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 ld should be binded along: 1 is for rows and 2 is for columns.

fill

logical vector of length 1 specifying whether to fill in missing values for any data.frames from ld that do not have all the columns. At this time, fill is only available for rbinding and only used if along = 1.

rtn.listnames.nm

character of length 1 specifying what the name of the column containing the names/positions of ld should be in the returned data.frame. If NULL, then no column is created for the names/positions of ld in the returned data.frame.

rtn.rownames.nm

character of length 1 specifying what the name of the column containing the rownames of ld's data.frames should be in the returned data.frame. If NULL, then no column is created for the rownames of ld's data.frames in the returned data.frame.

stringsAsFactors

logical vector of length 1 specifying whether character columns from ld should be converted to factors. Only available and used if fill = FALSE.

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 along = 2.

check

logical vector of length 1 specifying whether to check the structure of the input arguments. For example, check whether ld is a list of data.frames. This argument is available to allow flexibility in whether the user values informative error messages (TRUE) vs. computational efficiency (FALSE).

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

[Package str2str version 1.0.0 Index]