Dear R community, I have the following two zoo objects: MONTHLY CPI> plot(z) > par("usr")[1] 1977.76333 2011.15333 70.39856 227.03744> z=zooreg(cpius$Value,as.yearmon("1979-11"),frequency=12) > str(z)?zooreg? series from Nov 1979 to Oct 2010 Data: num [1:372] 76.2 77 77.8 78.5 79.5 80.3 81.1 82 82 82.6 ... Index: Class 'yearmon' num [1:372] 1980 1980 1980 1980 1980 ... Frequency: 12 AND A DAILY SERIES IN THE SAME RANGE> plot(y) > par("usr")[1] 3233.80000 15362.20000 70.42363 226.38559> str(y)?zoo? series from 1980-02-01 to 2010-10-31 Data: num [1:11231] 76.2 76.2 76.3 76.3 76.3 ... Index: Class 'Date' num [1:11231] 3683 3684 3685 3686 3687 ... Now, due to a different index (and a different "usr" parameter for the graphic) I am not able to plot the two series together. How shall I do? Thanks -- View this message in context: http://r.789695.n4.nabble.com/Plot-two-zoo-object-with-different-indexes-tp3055890p3055890.html Sent from the R help mailing list archive at Nabble.com.
On Tue, Nov 23, 2010 at 12:53 PM, Manta <mantino84 at libero.it> wrote:> > Dear R community, I have the following two zoo objects: > > MONTHLY CPI > >> plot(z) >> par("usr") > [1] 1977.76333 2011.15333 ? 70.39856 ?227.03744 >> z=zooreg(cpius$Value,as.yearmon("1979-11"),frequency=12) >> str(z) > ?zooreg? series from Nov 1979 to Oct 2010 > ?Data: num [1:372] 76.2 77 77.8 78.5 79.5 80.3 81.1 82 82 82.6 ... > ?Index: Class 'yearmon' ?num [1:372] 1980 1980 1980 1980 1980 ... > ?Frequency: 12 > > AND A DAILY SERIES IN THE SAME RANGE > >> plot(y) >> par("usr") > [1] ?3233.80000 15362.20000 ? ?70.42363 ? 226.38559 >> str(y) > ?zoo? series from 1980-02-01 to 2010-10-31 > ?Data: num [1:11231] 76.2 76.2 76.3 76.3 76.3 ... > ?Index: Class 'Date' ?num [1:11231] 3683 3684 3685 3686 3687 ... > > Now, due to a different index (and a different "usr" parameter for the > graphic) I am not able to plot the two series together. How shall I do? >Try this: library(zoo) z1 <- zooreg(1:20, start = as.yearmon("2000-01"), freq = 12) z2 <- zoo(1:600, as.Date("2000-01-01") + 0:599) m <- merge(day = aggregate(z1, as.Date, identity), month = z2) plot(na.approx(m)) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com
On Tue, Nov 23, 2010 at 5:03 PM, Manta <mantino84 at libero.it> wrote:> > > Gabor Grothendieck wrote: >> >> How to convert a monthly series to a daily series has already been >> illustrated in multiple ways in this thread. >> > > Fair enough. However, my last question was different. I simply want to know > if there is a simple neat way to import a monthly series as a zoo object > indexed by date without applying other function after the import (as in the > example, using aggregate) > > Thanks >If by import you mean reading it in from a file you can use the read.zoo FUN= argument to manipulate the time index as you read it in (and if you want to aggregate or split it at the same time there are aggregate= and split= arguments as well). See ?read.zoo -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com