Hello,
My problem is that I would like to merge multiple files with a common
column but merge accepts only two
data.frames to merge. In the real situation, I have 26 different
data.frames with a common column. I can of course use merge many times
(see below) but what would be more sophisticated
Hi: Below is a TOTAL HACK and I don't recommend it but it does seem to
do what you want. I think that I remember Gabor saying that you can
merge multiple data frames using zoo but I don't know the specifics. I'm
sure he'll respond with the correct way. Below uses a global variable
to access
Hi,
I think Reduce could help you.
DF1 - data.frame(var1 = letters[1:5], a = rnorm(5))
DF2 - data.frame(var1 = letters[3:7], b = rnorm(5))
DF3 - data.frame(var1 = letters[6:10], c = rnorm(5))
DF4 - data.frame(var1 = letters[8:12], d = rnorm(5))
g - merge(DF1, DF2, by.x=var1, by.y=var1, all=T)
Thanks, both solutions work fine. I tried these solutions to my real
data, and I got an error
Error in match.names(clabs, names(xi)) :
names do not match previous names
I refined this example data to look more like my real data, this also
produces the same error. Any ideas how to prevent this
Another option using Recall,
merge.rec - function(.list, ...){
if(length(.list)==1) return(.list[[1]])
Recall(c(list(merge(.list[[1]], .list[[2]], ...)), .list[-(1:2)]), ...)
}
my.list - list(DF1, DF2, DF3, DF4)
test2 - merge.rec(my.list, by.x=var1, by.y=var1, all=T)
If you don't mind I've added this example to the R wiki,
http://wiki.r-project.org/rwiki/doku.php?id=tips:data-frames:merge
It would be very nice if a R guru could check that the information I
put is not complete fantasy. Feel free to remove as appropriate.
Best wishes,
baptiste
On 19
That's perfectly fine. I figured out how to to this with my second example
DF1 - data.frame(var1 = letters[1:5], a = rnorm(5), b = rnorm(5), c = rnorm(5))
DF2 - data.frame(var1 = letters[3:7], a = rnorm(5), b = rnorm(5), c = rnorm(5))
DF3 - data.frame(var1 = letters[6:10], a = rnorm(5), b =
Yes, even better
DF1 - data.frame(var1 = letters[1:5], a = rnorm(5), b = rnorm(5), c = rnorm(5))
DF2 - data.frame(var1 = letters[3:7], a = rnorm(5), b = rnorm(5), c = rnorm(5))
DF3 - data.frame(var1 = letters[6:10], a = rnorm(5), b = rnorm(5), c
= rnorm(5))
DF4 - data.frame(var1 = letters[8:12],
The zoo package has a multi-way merge for zoo objects. Its
just do.call(merge, z) where z is a list of zoo objects.
In detail:
set.seed(1)
DF1 - data.frame(var1 = letters[1:5], a = rnorm(5), b = rnorm(5), c = rnorm(5))
DF2 - data.frame(var1 = letters[3:7], a = rnorm(5), b = rnorm(5), c =
9 matches
Mail list logo