DataTable is an API only (i.e. virtual class with no slots) for accessing
objects with a rectangular shape like DataFrame or
RangedData objects. It mimics the API for standard
data.frame objects.
Accessors
In the following code snippets, x is a DataTable.
nrow(x), ncol(x):
Get the number of rows and columns, respectively.
NROW(x), NCOL(x):
Same as nrow(x) and ncol(x), respectively.
dim(x):
Length two integer vector defined as c(nrow(x), ncol(x)).
rownames(x), colnames(x):
Get the names of the rows and columns, respectively.
dimnames(x):
Length two list of character vectors defined as
list(rownames(x), colnames(x)).
Subsetting
In the code snippets below, x is a DataTable object.
x[i, j, drop=TRUE]:
Return a new DataTable object made of the selected rows and columns. For
single column selection, the drop argument specifies whether or not
to coerce the returned sequence to a standard vector.
head(x, n=6L):
If n is non-negative, returns the first n rows of the DataTable
object.
If n is negative, returns all but the last abs(n) rows of
the DataTable object.
tail(x, n=6L):
If n is non-negative, returns the last n rows of the DataTable
object.
If n is negative, returns all but the first abs(n) rows of
the DataTable object.
subset(x, subset, select, drop=FALSE):
Return a new DataTable object using:
subset
logical expression indicating rows to keep, where missing
values are taken as FALSE.
select
expression indicating columns to keep.
drop
passed on to [ indexing operator.
na.omit(object):
Returns a subset with incomplete cases removed.
na.exclude(object):
Returns a subset with incomplete cases removed (but to be
included with NAs in statistical results).
is.na(x):
Returns a logical matrix indicating which cells are missing.
complete.cases(x):
Returns a logical vector identifying which cases have no missing values.
Combining
In the code snippets below, x is a DataTable object.
cbind(...): Creates a new DataTable by combining the columns
of the DataTable objects in ....
rbind(...): Creates a new DataTable by combining the rows of
the DataTable objects in ....
merge(x, y, ...): Merges two DataTable
objects x and y, with arguments in ... being
the same as those allowed by the base merge. It is
allowed for either x or y to be a data.frame.
Looping
In the code snippets below, x is a DataTable object.
by(data, INDICES, FUN, ..., simplify = TRUE):
Apply FUN to each group of data, a DataTable,
formed by the factor (or list of factors) INDICES. Exactly
the same contract as as.data.frame.
Utilities
duplicated(x): Returns a logical vector indicating the rows
that are identical to a previous row.
unique(x): Returns a new DataTable after
removing the duplicated rows from x.
show(x):
By default the show method displays 5 head and 5 tail
lines. The number of lines can be altered by setting the global
options showHeadLines and showTailLines. If the
object length is less than the sum of the options, the full object
is displayed. These options affect GRanges, GAlignments,
Ranges, DataTable and XString objects.
Coercion
as.env(x, enclos = parent.frame()):
Creates an environment from x with a symbol for each
colnames(x). The values are not actually copied into the
environment. Rather, they are dynamically bound using
makeActiveBinding. This prevents unnecessary copying
of the data from the external vectors into R vectors. The values
are cached, so that the data is not copied every time the symbol
is accessed.
Statistical modeling with DataTable
A number of wrappers are implemented for performing statistical
procedures, such as model fitting, with DataTable objects.
Tabulation
xtabs(formula = ~., data, subset, na.action,
exclude = c(NA, NaN), drop.unused.levels = FALSE):
Like the original xtabs, except data is a
DataTable.
See Also
DataFrame for an implementation that mimics data.frame.
data.frame
Examples
showClass("DataTable") # shows (some of) the known subclasses
library(IRanges)
df <- DataFrame(as.data.frame(UCBAdmissions))
xtabs(Freq ~ Gender + Admit, df)
Results
R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.
R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.
Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.
> library(S4Vectors)
Loading required package: stats4
Loading required package: BiocGenerics
Loading required package: parallel
Attaching package: 'BiocGenerics'
The following objects are masked from 'package:parallel':
clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
clusterExport, clusterMap, parApply, parCapply, parLapply,
parLapplyLB, parRapply, parSapply, parSapplyLB
The following objects are masked from 'package:stats':
IQR, mad, xtabs
The following objects are masked from 'package:base':
Filter, Find, Map, Position, Reduce, anyDuplicated, append,
as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
rbind, rownames, sapply, setdiff, sort, table, tapply, union,
unique, unsplit
Attaching package: 'S4Vectors'
The following objects are masked from 'package:base':
colMeans, colSums, expand.grid, rowMeans, rowSums
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/S4Vectors/DataTable-class.Rd_%03d_medium.png", width=480, height=480)
> ### Name: DataTable-class
> ### Title: DataTable objects
> ### Aliases: class:DataTable DataTable-class DataTable
> ### NROW,DataTable-method NCOL,DataTable-method dim,DataTable-method
> ### ROWNAMES ROWNAMES,ANY-method ROWNAMES,DataTable-method
> ### dimnames,DataTable-method dimnames<-,DataTable-method head.DataTable
> ### tail.DataTable subset,DataTable-method na.omit,DataTable-method
> ### na.exclude,DataTable-method is.na,DataTable-method
> ### complete.cases,DataTable-method cbind,DataTable-method
> ### rbind,DataTable-method merge,DataTable,DataTable-method
> ### merge,data.frame,DataTable-method merge,DataTable,data.frame-method
> ### by,DataTable-method duplicated,DataTable-method duplicated.DataTable
> ### unique,DataTable-method unique.DataTable as.env as.env,NULL-method
> ### as.env,DataTable-method show,DataTable-method xtabs,DataTable-method
> ### Keywords: methods classes
>
> ### ** Examples
>
> showClass("DataTable") # shows (some of) the known subclasses
Virtual Class "DataTable" [package "S4Vectors"]
No Slots, prototype of class "S4"
Extends: "DataTableORNULL"
Known Subclasses: "DataFrame"
>
> library(IRanges)
> df <- DataFrame(as.data.frame(UCBAdmissions))
> xtabs(Freq ~ Gender + Admit, df)
Admit
Gender Admitted Rejected
Male 1198 1493
Female 557 1278
>
>
>
>
>
> dev.off()
null device
1
>