ld2d {str2str} | R Documentation |
List of Data-Frames to Data-Frame
Description
ld2d
converts a list of data.frames to a data.frame. The function is
primarily for rbinding a list of data.frames (along
= 1). An option to
cbind the list of data.frames is included (along
= 2), but is just a call to
data.frame(ld, stringsAsFactors = stringsAsFactors, check.names = check.names)
.
Usage
ld2d(
ld,
along = 1,
fill = FALSE,
rtn.listnames.nm = "list_names",
rtn.rownames.nm = "row_names",
stringsAsFactors = FALSE,
check.names = FALSE,
check = TRUE
)
Arguments
ld |
list of data.frames. |
along |
integer vector of length 1 specifying which dimension the data.frames
from |
fill |
logical vector of length 1 specifying whether to fill in missing values
for any data.frames 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 rownames of |
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 |
Value
data.frame with the rows (if along
= 1) or columns (if along
= 2) of ld
binded together.
Examples
# without listnames and default rownames
ld <- list(BOD*1, BOD*2, BOD*3)
ld2d(ld)
# with listnames and default rownames
names(ld) <- LETTERS[1:3]
ld2d(ld)
# without listnames and custom rownames
ld <- lapply(unname(ld), FUN = `row.names<-`, letters[1:6])
ld2d(ld)
# with listnames and custom rownames
ld <- setNames(ld, LETTERS[1:3])
ld2d(ld)
# can handle same named columns in different positions
ld <- list(BOD*1, rev(BOD*2), rev(BOD*3))
ld2d(ld)
# can handle some columns being absent with fill = TRUE
ld[[2]]$"demand" <- NULL
try_expr(ld2d(ld, fill = FALSE)) # error
ld2d(ld, fill = TRUE) # NAs added
# along = 2 for cbinding
ld2d(ld, along = 2) # does not check/rename for double colnames
ld2d(ld, along = 2, check.names = TRUE) # makes unique colnames
ld2d(setNames(ld, nm = c("One","Two","Three")), along = 2,
check.names = TRUE) # does not add prefixes from list names