[R] list of lists to a data.frame

Rajarshi Guha rguha at indiana.edu
Fri Aug 18 22:44:41 CEST 2006


Hi, I have a situation where I have a list of lists. Each list can
contain elements of different types (but each one will be a scalar) say
of double, integer or character.

However the elements of each list are always in the same order:

x <- list('a', 1, 2)
y <- list('b', 3, 4)
z <- list('c', 5, 6)

a <- list(x,y,z)

What I'd like to do is to convert a to a data.frame.

Currently I am doing:

b <- do.call(rbind, a)

However, when I do b[,1] I get a list returned rather than a vector of
characters and similarly for b[,2] and so on.

I am clearly missing something, but how do I convert the list of lists
to a data.frame where a column is represented as a vector rather than a
list?

Thanks,

-------------------------------------------------------------------
Rajarshi Guha <rguha at indiana.edu>
GPG Fingerprint: 0CCA 8EE2 2EEB 25E2 AB04 06F7 1BB9 E634 9B87 56EE
-------------------------------------------------------------------
All life evolves by the differential survival of replicating entities.
-- Dawkins



More information about the R-help mailing list