Re: [R] how to add two data.frame with the same column but different row numbers

2011-04-15 Thread zhenjiang xu
Thanks, Gabor. It's a nice workaround. I'll look more at zoo library. On Fri, Apr 15, 2011 at 7:10 PM, Gabor Grothendieck wrote: > On Fri, Apr 15, 2011 at 6:10 PM, zhenjiang xu > wrote: > > Thanks, Dennis! I'll go with it. It's surprising there is no ready way to > do > > that. I imagine it sho

Re: [R] how to add two data.frame with the same column but different row numbers

2011-04-15 Thread Gabor Grothendieck
On Fri, Apr 15, 2011 at 6:10 PM, zhenjiang xu wrote: > Thanks, Dennis! I'll go with it. It's surprising there is no ready way to do > that. I imagine it should be a common data manipulation to add two > data.frame from two different sources. It could happen that one data.frame > is missing some ro

Re: [R] how to add two data.frame with the same column but different row numbers

2011-04-15 Thread zhenjiang xu
Thanks, Dennis! I'll go with it. It's surprising there is no ready way to do that. I imagine it should be a common data manipulation to add two data.frame from two different sources. It could happen that one data.frame is missing some rows while the other have some more. On Fri, Apr 15, 2011 at 5:

Re: [R] how to add two data.frame with the same column but different row numbers

2011-04-15 Thread Dennis Murphy
Hi: Here's one approach: > df1 <- data.frame(x = letters[1:3], y = 1:3) > df2 <- data.frame(x = c('a', 'c'), z = c(6, 1)) > dfm <- merge(df1, df2, all.x = TRUE) > dfm x y z 1 a 1 6 2 b 2 NA 3 c 3 1 sumdf <- data.frame(x = dfm$x, y = rowSums(dfm[, -1], na.rm = TRUE)) x y 1 a 7 2 b 2 3 c 4

[R] how to add two data.frame with the same column but different row numbers

2011-04-15 Thread zhenjiang xu
Hi all, Suppose I have 2 data.frame , a and b, how can I add them together to get c? Thanks > a A a 1 b 2 c 3 > b A a 6 c 1 > c A a 7 b 2 c 4 -- Best, Zhenjiang [[alternative HTML version deleted]] __ R-help@r-project.org mailing lis