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:10 PM, Dennis Murphy <[email protected]> wrote: > 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 > > HTH, > Dennis > > On Fri, Apr 15, 2011 at 1:31 PM, zhenjiang xu <[email protected]> > wrote: > > 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]] > > > > ______________________________________________ > > [email protected] mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > -- Best, Zhenjiang [[alternative HTML version deleted]] ______________________________________________ [email protected] mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.

