[R] [SPAM?] binding two lists of lists of dataframes together

Jim Lemon drjimlemon at gmail.com
Tue May 12 02:14:08 CEST 2015


Hi Vin,
If I read your "Output (Wanted)" section correctly, you want a new
list in which each element is the concatenation of the corresponding
elements of the original two. If so, maybe this shorter example will
help:

list1<-list(id=as.data.frame(matrix(rep(c(563,623,581),3),nrow=3,byrow=TRUE)),
 wgtband=as.data.frame(matrix(0,nrow=3,ncol=3,byrow=TRUE)))
list2<-list(id=as.data.frame(matrix(c(217,120,372,125,334,86,130,349,576),nrow=3,byrow=TRUE)),
 wgtband=as.data.frame(matrix(rep(1:3,each=3),nrow=3)))
list3<-list()
for(i in 1:length(list1)) list3[[i]]<-cbind(list1[[i]],list2[[i]])
names(list3)<-names(list1)
list3

Jim



More information about the R-help mailing list