I have the following daily exchange rate series (from january 1st 1996 to december 31st 2008) and I want to obtain them monthly series from it. I've read about the 'zoo' library but I'm not getting it how to do it. These are the data (left column day-month-year, right column the index) 31/12/1993 1,12509 03/01/1994 1,12509 04/01/1994 1,12558 05/01/1994 1,1258 06/01/1994 1,12596 07/01/1994 1,12753 10/01/1994 1,1273 11/01/1994 1,12416 12/01/1994 1,1275 Also, I have monthly CPI data and I want to interpolate using the reference CPI formula in order to obtain the daily series. The time window is the same (January 1996, December 2008). Thanks in advance for your help. -- View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23064454.html Sent from the R help mailing list archive at Nabble.com.
Try this:> Lines <- "31/12/1993 1,12509+ 03/01/1994 1,12509 + 04/01/1994 1,12558 + 05/01/1994 1,1258 + 06/01/1994 1,12596 + 07/01/1994 1,12753 + 10/01/1994 1,1273 + 11/01/1994 1,12416 + 12/01/1994 1,1275"> library(zoo) > z <- read.zoo(textConnection(Lines), format = "%d/%m/%Y", dec = ",") > zm <- aggregate(z, as.yearmon, tail, 1); zmWarning message: closing unused connection 3 (Lines) Dec 1993 Jan 1994 1.12509 1.12750 and read ?read.zoo, ?aggregate.zoo and the three zoo vignettes vignette(package = "zoo") # lists their names vignette("zoo") # displays first one On Wed, Apr 15, 2009 at 2:26 PM, manta <mantino84 at libero.it> wrote:> > I have the following daily exchange rate series ?(from january 1st 1996 to > december 31st 2008) and I want to obtain them monthly series from it. I've > read about the 'zoo' library but I'm not getting it how to do it. These are > the data (left column day-month-year, right column the index) > > 31/12/1993 ? ? ?1,12509 > 03/01/1994 ? ? ?1,12509 > 04/01/1994 ? ? ?1,12558 > 05/01/1994 ? ? ?1,1258 > 06/01/1994 ? ? ?1,12596 > 07/01/1994 ? ? ?1,12753 > 10/01/1994 ? ? ?1,1273 > 11/01/1994 ? ? ?1,12416 > 12/01/1994 ? ? ?1,1275 > > Also, I have monthly CPI data and I want to interpolate using the reference > CPI formula in order to obtain the daily series. The time window is the same > (January 1996, December 2008). > Thanks in advance for your help. > > -- > View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23064454.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >
You can remove missing values with: zm <- aggregate(cambio, as.yearmon, mean, na.rm = TRUE) Its not clear what your second question is asking. If you want the series to have a Date class rather than yearmon class with the 1st of the month then: zd <- zm time(zd) <- as.Date(time(zm)) or zd <- aggregate(zm, as.Date, force) On Wed, Apr 15, 2009 at 5:28 PM, manta <mantino84 at libero.it> wrote:> > Ok, using > > mcambio <- aggregate(cambio, as.yearmon, mean) > > works perfectly!! Should I worry about the missing values or not anyway? And > then I go to the following question. From monthly data to daily using a > specific formula? > -- > View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23067500.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >