Open BibeFiu opened 2 years ago
Thanks for the report! I haven't taken a close look yet, but an (intentional) difference between xts and zoo is that the width
argument is positive for xts and negative for zoo when you want to look back in time.
Thanks for the quick feedback. I checked the list(3:5) in both zoo and xts. In xts I got the same error. In zoo it does as expected looks into future.
@BibeFiu can you please try the patch on the 356-rollapply-width
branch? Basically, it calls rollapply.zoo()
any time width
is a list. I hope that works...
@BibeFiu It would be great if you could try my proposed patch and let me know if it works as expected. You can install the version on the branch from R using the function:
remotes::install_github("joshuaulrich/xts@356-rollapply-width")
remotes::install_github("joshuaulrich/xts@365-rollapply-width")
@joshuaulrich thanks a lot. I tried to install the update with the code you provided I got a cannot open URL 'https://api.github.com/repos/joshuaulrich/xts/tarball/356-rollapply-width' error
@BibeFiu: sorry, I made a typo (356 instead of 365 like it should be). Use this command: remotes::install_github("joshuaulrich/xts@365-rollapply-width")
@BibeFiu Did this for you? I'm preparing an xts release and noticed this branch wasn't merged. I'd like to include it in this upcoming release.
Description
rollapply does not work for xts when the width parameter is a list.
The following example should compute the mean of 3 to 5 elements before, my_xts <- .xts(1:6,1:6) rollapplyr(my_xts, width = list(-3:-5), FUN = mean)
but instead reports am error: Error in rollapply.xts(..., align = align) : 'list' object cannot be coerced to type 'integer'
Expected behavior
But it works if my_xts is converted to zoo: rollapplyr(as.zoo(my_xts), width = list(-3:-5), FUN = mean)
Minimal, reproducible example