1

I wish to execute a function FUN over a rolling window of 1 year. My xts has not the same number of points per year. How can I do that in an efficient way?

P.S. usually to execute a FUN over a fixed number of datapoints (for instance 100) I use:

as.xts(rollapply(data = zoo(indicator), FUN = FUN, width = 100, align = "right"))

but obviously this doesn't work if there are not always the same number of points per year.

4

2 に答える 2

0

ライブラリのapply.yearly(x, FUN, ...)関数を使用できます。xts

dat <- xts(rnorm(1000), order.by = as.Date(1:1000))
plot(dat)
apply.yearly(dat, mean)
于 2021-05-10T05:23:49.723 に答える