[R] Convert some columns of List to dataframe R

Zilefac Elvis zilefacelvis at yahoo.com
Mon Aug 4 00:12:06 CEST 2014


Dear All,
I have a List in R and would like to convert it to data.frame.
Below is a reproducible example. I can do something like: 

x1<-do.call(cbind.data.frame, lst3) #OR 
x1<-as.data.frame(lst3).

However, my output looks like this:

Year Site  x   Year Site  x 
2001 G101 33.1 2001 G102 34

I would like to have as my output:

Year  G101   G102 
2001  33.1   34


Thanks
Atem.
----------------------------------------------------------------------------------


 list(structure(list(Year = 2001L, Site = structure(1L, .Label = "G101", class = "factor"), 
    x = 33.1), .Names = c("Year", "Site", "x"), row.names = c(NA, 
-1L), class = "data.frame"), structure(list(Year = 2001L, Site = structure(1L, .Label = "G102", class = "factor"), 
    x = 34), .Names = c("Year", "Site", "x"), row.names = c(NA, 
-1L), class = "data.frame"))



More information about the R-help mailing list