DataFrameList-class {IRanges} | R Documentation |
List of DataFrames
Description
Represents a list of DataFrame
objects.
The SplitDataFrameList
class contains the additional restriction
that all the columns be of the same name and type. Internally it is stored
as a list of DataFrame
objects and extends
List
.
Accessors
In the following code snippets, x
is a DataFrameList
.
dims(x)
:Get the two-column matrix indicating the number of rows and columns over the entire dataset.
dimnames(x)
:Get the list of two CharacterLists, the first holding the rownames (possibly
NULL
) and the second the column names.
In the following code snippets, x
is a SplitDataFrameList
.
commonColnames(x)
:Get the character vector of column names present in the individual DataFrames in
x
.commonColnames(x) <- value
:Set the column names of the DataFrames in
x
.columnMetadata(x)
:Get the
DataFrame
of metadata along the columns, i.e., where each column inx
is represented by a row in the metadata. The metadata is common across all elements ofx
. Note that callingmcols(x)
returns the metadata on theDataFrame
elements ofx
.columnMetadata(x) <- value
:Set the
DataFrame
of metadata for the columns.
Subsetting
In the following code snippets, x
is a SplitDataFrameList
. In
general x
follows the conventions of
SimpleList
/CompressedList
with the following addition:
x[i,j,drop]
:If matrix subsetting is used,
i
selects either the list elements or the rows within the list elements as determined by the[
method forSimpleList
/CompressedList
,j
selects the columns, anddrop
is used when one column is selected and output can be coerced into anAtomicList
orIntegerRangesList
subclass.x[i,j] <- value
:If matrix subsetting is used,
i
selects either the list elements or the rows within the list elements as determined by the[<-
method forSimpleList
/CompressedList
,j
selects the columns andvalue
is the replacement value for the selected region.
Constructor
DataFrameList(...)
:Concatenates the
DataFrame
objects in...
into a newDataFrameList
.SplitDataFrameList(..., compress = TRUE, cbindArgs = FALSE)
:If
cbindArgs
isFALSE
, the...
arguments are coerced toDataFrame
objects and concatenated to form the result. The arguments must have the same number and names of columns. IfcbindArgs
isTRUE
, the arguments are combined as columns. The arguments must then be the same length, with each element of an argument mapping to an element in the result. Ifcompress = TRUE
, returns aCompressedSplitDataFrameList
; else returns aSimpleSplitDataFrameList
.
Combining
In the following code snippets, objects in ...
are of class
DataFrameList
.
rbind(...)
:Creates a new
DataFrameList
containing the element-by-element row concatenation of the objects in...
.cbind(...)
:Creates a new
DataFrameList
containing the element-by-element column concatenation of the objects in...
.
Transformation
transform(`_data`, ...)
:Transforms a
SplitDataFrame
in a manner analogous to the basetransform
, where the columns areList
objects adhering to the structure of_data
.
Coercion
In the following code snippets, x
is a DataFrameList
.
as(from, "DataFrame")
:Coerces a
SplitDataFrameList
to aDataFrame
, which has a column for every column infrom
, except each column is aList
with the same structure asfrom
.as(from, "SplitDataFrameList")
:By default, simply calls the
SplitDataFrameList
constructor onfrom
. Iffrom
is aList
, each element offrom
is passed as an argument toSplitDataFrameList
, like callingas.list
on a vector. Iffrom
is aDataFrame
, each row becomes an element in the list.stack(x, index.var = "name")
:Unlists
x
and adds a column namedindex.var
to the result, indicating the element ofx
from which each row was obtained.as.data.frame(x, row.names = NULL, optional = FALSE, ..., value.name = "value", use.outer.mcols = FALSE, group_name.as.factor = FALSE)
:-
Coerces
x
to adata.frame
. See as.data.frame on theList
man page for details (?List
).
Author(s)
Michael Lawrence, with contributions from Aaron Lun
See Also
DataFrame
Examples
# Making a DataFrameList, which has different columns.
out <- DataFrameList(DataFrame(X=1, Y=2), DataFrame(A=1:2, B=3:4))
out[[1]]
# A more interesting SplitDataFrameList, which is guaranteed
# to have the same columns.
out <- SplitDataFrameList(DataFrame(X=1, Y=2), DataFrame(X=1:2, Y=3:4))
out[[1]]
out[,"X"]
out[,"Y"]
commonColnames(out)
commonColnames(out) <- c("x", "y")
out[[1]]
# We can also create these split objects using various split() functions:
out <- splitAsList(DataFrame(X=runif(100), Y=rpois(100, 5)),
sample(letters, 100, replace=TRUE))
out[['a']]