Re: [R] Merging data frames of different length

2008-12-20 Thread Dimitri Liakhovitski
Thanks a lot, Gabor - it's perfect! Dimitri On Fri, Dec 19, 2008 at 6:24 PM, Gabor Grothendieck wrote: > Try this: > >> L <- list(data.frame(A=2, B=3, C=4), > + data.frame(A=2, B=1, C=3, D=2, E=4, F=5), > + data.frame(A=1, B=2, C=4, D=3, E=2, F=4, G=5, H=4, I=2)) > >> library(plyr) >> do.call(rbi

Re: [R] Merging data frames of different length

2008-12-19 Thread Gabor Grothendieck
Try this: > L <- list(data.frame(A=2, B=3, C=4), + data.frame(A=2, B=1, C=3, D=2, E=4, F=5), + data.frame(A=1, B=2, C=4, D=3, E=2, F=4, G=5, H=4, I=2)) > library(plyr) > do.call(rbind.fill, L) A B C D E F G H I 1 2 3 4 NA NA NA NA NA NA 2 2 1 3 2 4 5 NA NA NA 3 1 2 4 3 2 4 5 4 2

Re: [R] Merging data frames of different length

2008-12-19 Thread Adam D. I. Kramer
Hi Dimitri, Not exceptionally elegant, but this should do it: alldata <- as.data.frame(matrix(as.numeric(NA),nrow=99,ncol=9)) colnames(alldata) <- colnames(L[[?]]) ( where ? is a 9-column data frame with the correct names ) foreach (i in 1:99) { alldata[i,colnames(L[[i]])] <- L[[i]] }

[R] Merging data frames of different length

2008-12-19 Thread Dimitri Liakhovitski
Hello, everyone! I have list L that contains 99 data frames. All data frames have only one row, but a different number of columns. Some data frames have 3 columns, some - 6 columns, and some - 9 columns. The names of the first 3 columns are identical in all 99 data frames (e.g., A, B, and C). The