I have a question about lists in R. I have a list within 16 list containing a list with variables like this:
x
[[1]]
A 1 3
B 4 2
[[2]]
C 23 4
D 9 22
E 4 54
The A,B,C and D are rownames in the lists. Now I want to create a file that paste only the rownames in a dataframe. Each row in the dataframe contains 1 list in the total list.
A B
C D E
Can anyone help me with this? I thought maybe someting like do.call(rbind, rownames(x))
EDIT! 05-08-2011
Is there a way to save the rownames list by list? So in the end there are no NA’s in the data and the data is unequal?
Thank you all!
Making an assumption about the nature of
x, if we use:which gives:
Then
seems the only plausible answer. Unless we pad the
("A","B")vector with something, we can’t use a matrix or a data frame because the component lengths do not match. Hence one of the reasons thedo.call()idea fails:To pad the result with
NAand get a data frame, we could do:The last line gives:
If you want that nicely printed, then
is an option inside R.