简体   繁体   中英

rollapply and xts does not work in the new version of xts

If I run this simple code:

my_xts <- .xts(1:10*1,1:10)
rollapply(my_xts, list(seq(-2, 0)), sum, partial = 1)

In the new version of xts (0.9-3), I get:

Error in rollapply.xts(my_xts, list(seq(-2, 0)), sum, partial = 1) : 
(list) object cannot be coerced to type 'integer'
In addition: Warning message:
In rollapply.xts(my_xts, list(seq(-2, 0)), sum, partial = 1) :
partial argument is not currently supported

While in the old xts (0.8-6) runs smoothly.

Seems it is related with the option width. As in the vignette of rollapply , "width can be a list regarded as offsets compared to the current time". In the new version this cannot be possible.

Any workaround? Is there a possibility to call rollapply in a different way, in order to achieve the old behaviour?

rollapply.xts wasn't registered as an S3 method until version 0.8-9. That's why this worked for you previously. Since there wasn't an xts S3 method, rollapply.zoo would have been dispatched, which would have returned a zoo object (not an xts object).

rollapply.xts currently does not support width=list(...) , but you can get the same results you did previously by converting your xts object to a zoo object before calling rollapply .

rollapply(as.zoo(my_xts), list(seq(-2, 0)), sum, partial = 1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM