[R] Merging data frames one of which is NULL

Dimitri Liakhovitski dimitri.liakhovitski at gmail.com
Tue Nov 9 17:42:20 CET 2010


Hello!

I am running a loop. The result of each run of the loop is a data
frame. I am merging all the data frames.
For exampe:

The dataframe from run 1:
x<-data.frame(a=1,b=2,c=3)

The dataframe from run 2:
y<-data.frame(a=10,b=20,d=30)

What I want to get is:
merge(x,y,all.x=T,all.y=T)

Then I want to merge it with the output of the 3rd run, etc.

Unfortunately, I can't create the placeholder for the overall resutls
BEFORE I run the loop because I don't even know how many columns I'll
end up with - after merging all the data frames.
I was thinking of creating an empty list:

first<-NULL

...and then updating it during each run by merging it with the data
frame that is the output of the run. However, when I try to merge the
empty list with any non-empty data frame - it ends up empty:
merge(first,a,,all.x=T,all.y=T)

Is there a way to make it merge while keeping everything?
Thanks a lot!
-- 
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com



More information about the R-help mailing list