Skip to content
Prev 299866 / 398503 Next

help with merging 2 data frames

Hello,

About many columns like 'e1' and 'e2' I don't know but with the provided 
example the following does NOT depend on them, only on 'a', 'b' and 'a2' 
and 'a3'.


z <- lapply(c("a2", "a3"), function(cc) merge(x, y, by.x=c("a", "b"), 
by.y=c(cc, "b")))
z <- lapply(seq_along(z), function(i)
         z[[i]][ -which(names(z[[i]]) %in% c("a2", "a3")) ])
z <- do.call(rbind, z)
z <- z[order(z$a, z$b), ]
rownames(z) <- seq_len(nrow(z))
all.equal(desired, z)


Hope this helps,

Rui Barradas

Em 11-07-2012 23:28, Dimitri Liakhovitski escreveu: