Skip to content

Dataframe from list of similar lists: not _a_ way, but _the best_ way

1 message · Brian Diggs

#
On 12/7/2010 1:03 AM, Nick Sabbe wrote:
Actually, this is not a list of lists, but rather a list of vectors with 
dimensions.  I didn't know such a thing existed, but obviously it does.
I don't know that this is best (in terms of fastest and/or least memory 
usage), but to me the following is "best" in that it hands off the 
problem to a package that is designed to handle such problems, so 
presumably does a better job than any one-off approach.

library("plyr")

DF <- ldply(1:10, function(nr){data.frame(org=nr, chr=as.character(nr))})

Note that the internal function returns a data.frame rather than a list, 
and the *dply functions automatically stitch the individual data.frames 
together.  Check out the documentation to the plyr package.