I would like to use the zoo function rollapply to apply a function (for example mean) on a time series but only using the last N known points. For example:
x = zoo(c(1,2,3,4), order.by=c(10,11,12,13))
rollmean(x,2)
Produces:
10 11 12
1.5 2.5 3.5
I would like to produce a series that would have date entries of 11, 12, 13 and values of 1.5, 2.5, 3.5. The values seem correct but the dates that rollmean outputs don't seem to correspond to what I would like. I'm a bit worried about just assigning the dates I want to the zoo object using time(x)<-
because I'm not sure that rollapply is actually doing the right thing. Help is appreciated as always.