I would like to use the rollupply function for zoo to apply a function (e.g. average value) to a time series, but only using the last N known points. For instance:
x = zoo(c(1,2,3,4), order.by=c(10,11,12,13))
rollmean(x,2)
It produces:
10 11 12
1.5 2.5 3.5
I would like to create a series in which there would be records of the dates 11, 12, 13 and the values 1.5, 2.5, 3.5. The values seem to be correct, but the dates when the rollmean output does not seem to match what I would like. I'm a little worried about just setting the dates I want for the zoo object using time(x)<-
, because I'm not sure rollapply really does the right thing. Help is appreciated, as always.
source share