DataTable objects
Description
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 asnrow(x)
andncol(x)
, respectively. 
dim(x)
: Length two integer vector defined asc(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 aslist(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, thedrop
argument specifies whether or not to coerce the returned sequence to a standard vector. 
head(x, n=6L)
: Ifn
is nonnegative, returns the first n rows of the DataTable object. Ifn
is negative, returns all but the lastabs(n)
rows of the DataTable object. 
tail(x, n=6L)
: Ifn
is nonnegative, returns the last n rows of the DataTable object. Ifn
is negative, returns all but the firstabs(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 newDataTable
by combining the columns of theDataTable
objects in...
. 
rbind(...)
: Creates a newDataTable
by combining the rows of theDataTable
objects in...
. 
merge(x, y, ...)
: Merges twoDataTable
objectsx
andy
, with arguments in...
being the same as those allowed by the basemerge
. It is allowed for eitherx
ory
to be adata.frame
.
Looping
In the code snippets below, x
is a DataTable object.

by(data, INDICES, FUN, ..., simplify = TRUE)
: ApplyFUN
to each group ofdata
, aDataTable
, formed by the factor (or list of factors)INDICES
. Exactly the same contract asas.data.frame
.
Utilities
duplicated(x)
: Returns a logical vector indicating the rows that are identical to a previous row.unique(x)
: Returns a newDataTable
after removing the duplicated rows fromx
.
show(x)
: By default theshow
method displays 5 head and 5 tail lines. The number of lines can be altered by setting the global optionsshowHeadLines
andshowTailLines
. 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 fromx
with a symbol for eachcolnames(x)
. The values are not actually copied into the environment. Rather, they are dynamically bound usingmakeActiveBinding
. 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 originalxtabs
, exceptdata
is aDataTable
.
See Also

DataFrame for an implementation that mimics
data.frame
. 
data.frame
Examples
1 2 3 4 5  showClass("DataTable") # shows (some of) the known subclasses
library(IRanges)
df < DataFrame(as.data.frame(UCBAdmissions))
xtabs(Freq ~ Gender + Admit, df)
