[R] From daily series to monthly and viceversa

Gabor Grothendieck ggrothendieck at gmail.com
Sat Apr 18 05:00:18 CEST 2009


Here is a partial solution:

library(zoo)
# z is CPI.  Just use 1, 2, 3, ... for example.
z <- zooreg(1:12, as.yearmon("2008-01"), freq = 12)
days.in.month <- as.numeric(as.Date(time(z), frac = 1) - as.Date(time(z)) + 1)
z2 <- cbind(z, z1 = lag(z, -1), z2 = lag(z, -2), z3 = lag(z, -3), days.in.month)
time(z2) <- as.Date(time(zz))
z3 <- na.locf(
		cbind(zz,
			zoo(, dd),
			day.of.month = as.numeric(format(time(zz), "%d"))
))
z3$day.of.month <- as.numeric(format(time(zz2), "%d"))
# now each row of z3 has all the data you need so apply(z3, 1, your.function)


On Fri, Apr 17, 2009 at 2:13 PM, manta <mantino84 at libero.it> wrote:
>
> any update anybody? I'm really stucked!
> --
> View this message in context: http://www.nabble.com/From-daily-series-to-monthly-and-viceversa-tp23064454p23103052.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.
>




More information about the R-help mailing list