as.data.frame.list: Convert a List to a Data Frame

Description Usage Arguments Value Author(s) References Examples

View source: R/dplyr_tools.R

Description

Convert a List to a Data Frame

Usage

1
2
## S3 method for class 'list'
as.data.frame(x, row.names = NULL, optional = FALSE, ...)

Arguments

x

a list to convert to a data frame.

row.names

a vector equal to length(x) corresponding to the row names. If NULL, the row names will be set to names(x).

optional

not used.

...

other parameters passed to data.frame.

Value

a data frame.

Author(s)

Jason Bryer <<jason@bryer.org>>

References

http://stackoverflow.com/questions/4227223/r-list-to-data-frame

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
    test1 <- list( c(a='a',b='b',c='c'), c(a='d',b='e',c='f'))
    as.data.frame(test1)

    test2 <- list( c('a','b','c'), c(a='d',b='e',c='f'))
    as.data.frame(test2)

    test3 <- list('Row1'=c(a='a',b='b',c='c'), 'Row2'=c(var1='d',var2='e',var3='f'))
    as.data.frame(test3)

    test4 <- list('Row1'=letters[1:5], 'Row2'=letters[1:7], 'Row3'=letters[8:14])
    as.data.frame(test4)

    test5 <- list(letters[1:10], letters[11:20])
    as.data.frame(test5)

    test6 <- list(list(letters), letters)
    as.data.frame(test6)

burch-cm/kittius documentation built on March 11, 2021, 5:40 a.m.