[R] Combine list element by column name to make a dataframe

Duncan Mackay dulcalma at bigpond.com
Tue Apr 7 05:33:51 CEST 2015


forgot to cc to list

have a look at https://stat.ethz.ch/pipermail/r-help/2012-January/300275.html

and other messages in the sequence

if you use Marc Schwartz's list2df you with have to transpose  it with t()

Duncan

Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mackay at northnet.com.au

-----Original Message-----
From: R-help [mailto:r-help-bounces at r-project.org] On Behalf Of Mohammad Tanvir Ahamed via R-help
Sent: Monday, 6 April 2015 16:06
To: r-help at r-project.org
Subject: [R] Combine list element by column name to make a dataframe

Hi ,�

I have a example list like follow�


############################################

lst<-list(setNames(c(1,10,50,60,70,80),c("id","id1","math","phy","che","bio")),setNames(c(2,20,45),c("id","id1","phy")),setNames(c(3,30,75),c("id","id1","bio")))


My expected outcome :�

---------------------------------------------------------------------

df<-rbind(c(1,10,50,60,70,80),c(2,20,NA,45,NA,NA),c(3,30,NA,NA,NA,75))

colnames(df)<-c("id","id1","math","phy","che","bio")

row.names(df) <- NULL

df

############################################


Any suggestion will be appreciated .�

Thanks in advance.

�

Best regards


...........................�

Tanvir Ahamed

G�teborg, Sweden




	[[alternative HTML version deleted]]



More information about the R-help mailing list