lm2d {str2str} | R Documentation |
List of Matrices to Data-Frame
Description
lm2d
converts a list of matrices to a data.frame. The function is
primarily for rbinding a list of matrices (along
= 1). An option to
cbind the list of matrices is included (along
= 2), but is just a call to
data.frame(lapply(lm, m2d), stringsAsFactors = stringsAsFactors, check.names = check.names)
.
Usage
lm2d(
lm,
along = 1,
fill = FALSE,
rtn.listnames.nm = "list_names",
rtn.rownames.nm = "row_names",
stringsAsFactors = FALSE,
check.names = FALSE,
check = TRUE
)
Arguments
lm |
list of matrices. |
along |
numeric vector of length 1 specifying which dimension the matrices
from |
fill |
logical vector of length 1 specifying whether to fill in missing values
for any matrices from |
rtn.listnames.nm |
character of length 1 specifying what the name of the
column containing the names/positions of |
rtn.rownames.nm |
character of length 1 specifying what the name of the
column containing the names/positions of the rows within |
stringsAsFactors |
logical vector of length 1 specifying whether character columns
from |
check.names |
logical vector of length 1 specifying whether the colnames
of the returned data.frame should be checked for duplicates and made unique.
Only used if for cbinding with |
check |
logical vector of length 1 specifying whether to check the structure
of the input arguments. For example, check whether |
Details
Another way to convert a list of matrices to a data.frame is to convert the list
dimension, row dimension, and column dimension in the list of matrices all to
variable dimensions in the data.frame. If this is desired, call a2d(lm2a(lm))
instead of lm2d
.
Value
data.frame with the rows (if along
= 1) or columns (if along
= 2) of lm
binded together.
Examples
# list names and rownames
lm <- asplit(HairEyeColor, MARGIN = 3L)
lm2d(lm) # default
lm2d(lm, rtn.listnames.nm = "Sex", rtn.rownames.nm = "Hair")
# no list names
lm2 <- `names<-`(lm, value = NULL)
lm2d(lm2)
lm2d(lm2, rtn.listnames.nm = NULL)
# no rownames too
lm3 <- lapply(lm2, `rownames<-`, value = NULL)
lm2d(lm3)
lm2d(lm3, rtn.rownames.nm = NULL)
lm2d(lm3, rtn.listnames.nm = NULL, rtn.rownames.nm = NULL)
# cbinding as columns
lm2d(lm3, along = 2)
lm2d(lm3, along = 2, check.names = TRUE)