| 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 (possiblyNULL) 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 inx.commonColnames(x) <- value: Set the column names of the DataFrames inx.columnMetadata(x): Get theDataFrameof metadata along the columns, i.e., where each column inxis represented by a row in the metadata. The metadata is common across all elements ofx. Note that callingmcols(x)returns the metadata on theDataFrameelements ofx.columnMetadata(x) <- value: Set theDataFrameof 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,iselects either the list elements or the rows within the list elements as determined by the[method forSimpleList/CompressedList,jselects the columns, anddropis used when one column is selected and output can be coerced into anAtomicListorIntegerRangesListsubclass. x[i,j] <- value: If matrix subsetting is used,iselects either the list elements or the rows within the list elements as determined by the[<-method forSimpleList/CompressedList,jselects the columns andvalueis the replacement value for the selected region.
Constructor
DataFrameList(...): Concatenates theDataFrameobjects in...into a newDataFrameList.SplitDataFrameList(..., compress = TRUE, cbindArgs = FALSE): IfcbindArgsisFALSE, the...arguments are coerced toDataFrameobjects and concatenated to form the result. The arguments must have the same number and names of columns. IfcbindArgsisTRUE, 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 newDataFrameListcontaining the element-by-element row concatenation of the objects in.... -
cbind(...): Creates a newDataFrameListcontaining the element-by-element column concatenation of the objects in....
Transformation
transform(`_data`, ...): Transforms aSplitDataFramein a manner analogous to the basetransform, where the columns areListobjects adhering to the structure of_data.
Coercion
In the following code snippets, x is a DataFrameList.
as(from, "DataFrame"): Coerces aSplitDataFrameListto aDataFrame, which has a column for every column infrom, except each column is aListwith the same structure asfrom.as(from, "SplitDataFrameList"): By default, simply calls theSplitDataFrameListconstructor onfrom. Iffromis aList, each element offromis passed as an argument toSplitDataFrameList, like callingas.liston a vector. Iffromis aDataFrame, each row becomes an element in the list.stack(x, index.var = "name"): Unlistsxand adds a column namedindex.varto the result, indicating the element ofxfrom 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): Coercesxto adata.frame. See as.data.frame on theListman page for details (?List).
Author(s)
Michael Lawrence, with contributions from Aaron Lun
See Also
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']]