Re: [R] Multiple merge, better solution?

2009-02-19 Thread Gabor Grothendieck
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 = r

Re: [R] Multiple merge, better solution?

2009-02-19 Thread Lauri Nikkinen
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

Re: [R] Multiple merge, better solution?

2009-02-19 Thread Lauri Nikkinen
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 = rno

Re: [R] Multiple merge, better solution?

2009-02-19 Thread baptiste auguie
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 Feb

Re: [R] Multiple merge, better solution?

2009-02-19 Thread baptiste auguie
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) all

Re: [R] Multiple merge, better solution?

2009-02-19 Thread Lauri Nikkinen
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 e

Re: [R] Multiple merge, better solution?

2009-02-19 Thread baptiste auguie
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"

Re: [R] Multiple merge, better solution?

2009-02-19 Thread markleeds
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 the