Skip to content
Prev 257031 / 398506 Next

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

On Fri, Apr 15, 2011 at 6:10 PM, zhenjiang xu <zhenjiang.xu at gmail.com> wrote:
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":

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

The last line gives:
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)
a+b

The last line gives:
a b c
7 2 4