Re: [R] Merge data frames but prefer values in one

2009-09-11 Thread Henrique Dallazuanna
Maybe: do.call(rbind, lapply(with(xy <- rbind(x, y), split(xy, list(a, b), drop = TRUE)), tail, 1)) On Fri, Sep 11, 2009 at 3:45 AM, jo wrote: > Thanks for the post-processing ideas. But is there any way to do that > in one step? > > On Thu, Sep 10, 2009 at 7:20 PM, Henrique Dallazuanna > wrot

Re: [R] Merge data frames but prefer values in one

2009-09-10 Thread jo
Thanks for the post-processing ideas. But is there any way to do that in one step? On Thu, Sep 10, 2009 at 7:20 PM, Henrique Dallazuanna wrote: > > Try this: > > xy <- merge(x, y, by = c("a","b"),all = TRUE) > xy$c <- ifelse(rowSums(!is.na(.x <- xy[, c('c.x', 'c.y')])) > 1, .x[,1], > rowSums(.x,

Re: [R] Merge data frames but prefer values in one

2009-09-10 Thread Henrique Dallazuanna
Try this: xy <- merge(x, y, by = c("a","b"),all = TRUE) xy$c <- ifelse(rowSums(!is.na(.x <- xy[, c('c.x', 'c.y')])) > 1, .x[,1], rowSums(.x, na.rm = TRUE)) xy On Thu, Sep 10, 2009 at 12:21 PM, JiHO wrote: > Hello everyone, > > My problem is better explained with an example: > > > x=data.frame(a