rollapply with “growing” window

后端 未结 2 986
抹茶落季
抹茶落季 2021-01-02 09:31

Guys, normally when you do something like:

tmp = zoo(rnorm(100), 1:100)
rollapply(tmp, 10, function(x) quantile(x, 0.05), align=\"right\")

2条回答
  •  失恋的感觉
    2021-01-02 10:08

    Why not just pad the series with 9 NAs at the beginning? Definitely better than "ugly for loops":

    tmp = zoo(c(rep(NA,9), rnorm(100)), 1:109)
    zoo(rollapply(tmp, 10, function(x) quantile(x, 0.05, na.rm = TRUE), 
                  align="right"), 1:100)
    

提交回复
热议问题