B Seven
B Seven

Reputation: 45943

How to combine two zoo objects in R

I have 2 zoo objects of the same length, one with dates.

> a
           Number
2007-01-01      5
...

> b
1 10
...

How to add b as a column in a?

            Number   b
2007-01-01       5  10

Or create a combined object with both as above?

Upvotes: 1

Views: 589

Answers (1)

G. Grothendieck
G. Grothendieck

Reputation: 269501

In the future please provide your data in reproducible form. We have assumed the data a and b shown below.

library(zoo)

# inputs
a <- zoo(cbind(Number = 5), as.Date("2007-01-01"))
b <- zoo(cbind(10))

ab <- cbind(a, coredata(b))
names(ab) <- c(names(a), "b")

giving:

> ab
           Number  b
2007-01-01      5 10

Upvotes: 1

Related Questions