[R] Plot two zoo object with different indexes
Gabor Grothendieck
ggrothendieck at gmail.com
Tue Nov 23 22:19:26 CET 2010
On Tue, Nov 23, 2010 at 3:58 PM, Manta <mantino84 at libero.it> wrote:
>
> Ok this helps definitely! But I still would like to know
>
> 1. How to change from one index to another within a 'zoo' object
Using
z <- zooreg(1:10, start = as.yearmon("2000-01"), freq = 12)
Try
aggregate(z, as.Date, identity)
or
time(z) <- as.Date(time(z))
Note that an example of the first approach was already shown in the
earlier answer.
> 2. How to import using as index 'Date' a monthly series (code below). The
> series in the US CPI from November 1979 to October 2010.
>
> z <- zoo(cpius$Value, as.Date("1979-11-30")+0:372)
Assuming the question is how to turn this daily series into a monthly series:
aggregate(z, as.yearmon, function(x) tail(x, 1))
Suggest you carefully review ?aggregate.zoo
--
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com
More information about the R-help
mailing list