list2df: Convert a list to a data frame

Description Usage Arguments Details Value Author(s) Examples

Description

Convert a list of vectors (or data frames) with same numbered lengths (or number of columns) into a data frame.

Usage

1
2
list2df(vList, col.names = NULL, row.names = NULL,
        convert.numeric = TRUE, strings.as.factors = FALSE)

Arguments

vList

List of vectors or data frames, each vector having the same length, n, or each data frame having the same number of columns, n.

col.names

Optional character vector of length n with column names that will be given to the output data frame. If col.names = NULL, column names are extracted if possible from the column names (or names) of the data frames (or vectors).

row.names

Optional character vector with length equivalent to the length of vList containing the row names of the output data frame. If row.names = NULL, row names from the data frames (or names of the vList elements) if possible.

convert.numeric

If vList is list of vectors, = TRUE attempts to convert each column to numeric if possible using as.numeric.silent

strings.as.factors

If vList is a list of vectors, = TRUE converts character variables into factors using factor2character.

Details

It is permissible for vList to contain NULL elements. list2df performs numerous consistency checks to ensure that contents of vList which are combined into the resulting data frame are conformable, labeled consistently, of the equivalent class when necessary, etc.

Value

If vList is list of data frames, a data frame resulting from efficiently row binding the data frames in vList is returned. If vList is a list of vectors, a data frame is returned where the first column contains the first elements of the list vectors, the second column contains the second elements of the list vectors, etc.

Author(s)

Landon Sego

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# For a list of data frames
z <- list(d1 = data.frame(a = 1:10, b = letters[1:10]),
          d2 = data.frame(a = 11:15, b = letters[11:15]))
list2df(z)

# For a list of vectors
x <- c("r1c1 1", "r2c1 2", "r3c1 3", "r4c4 4")
y <- strsplit(x, "\ ")
list2df(y)
list2df(y, col.names=LETTERS[1:2])

z <- list(NULL, a = c(top = 10, bottom = 12), NULL, b = c(top = 15, bottom = 17))
list2df(z)

PNNL-Comp-Mass-Spec/glmnetGLR documentation built on May 28, 2019, 2:23 p.m.