[R] collapsing list to data.frame
Erik Iverson
iverson at biostat.wisc.edu
Wed Mar 5 21:28:08 CET 2008
Perhaps
data.frame(do.call(rbind, l))
?
- Erik Iverson
a9804814 at unet.univie.ac.at wrote:
> Hello,
>
>
> Given a list with all elements having identical layout, e.g.:
>
>
> l = NULL
> l[[1]] = list(4, "hello")
> l[[2]] = list(7, "world")
> l[[3]] = list(9, " !!!! ")
>
>
> is there an easy way to collapse this list into a data.frame with each
> row being the elements of the list ?
> I.e. in this case I want to convert the list into a data.frame with 3
> rows and 2 columns, where column 1 holds the integer values, and column
> 2 the character values.
>
> I can get it done by looping over all elements and rbind them together
> to the final result, but that is quite slow (for large sets) and ugly,
> so I was wondering if there's an easy syntax.
>
> thanks a lot in advance,
> Thomas
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list