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

From: Gabor Grothendieck <>
Date: Fri, 15 Apr 2011 19:10:52 -0400

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 rows while the other have some more.

If you represent them as zoo series then you can do it using + (although the definition of + is different than in your post). Here "a", "b" and "c" are the "times":

a <- zoo(1:3, letters[1:3])
b <- zoo(c(6, 1), c("a", "c"))

The last line gives:

> a+b

a c
7 4

To use the definition in your post one could do this (which has the effect of modifying b so that a+b works as in your post):

merge(a, b, fill = 0, retclass = NULL)

The last line gives:

> a+b

a b c
7 2 4

Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at

______________________________________________ mailing list
PLEASE do read the posting guide
and provide commented, minimal, self-contained, reproducible code.
Received on Fri 15 Apr 2011 - 23:14:34 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 16 Apr 2011 - 06:00:30 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.

list of date sections of archive