Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rollmean fails when there are missing values in multi-column xts and k = nrow(x) #367

Open
eguidotti opened this issue May 10, 2022 · 2 comments
Labels

Comments

@eguidotti
Copy link

Description

The function rollmean fails when there are missing values in multi-column xts object and k = nrow(x).

Expected behavior

I'd expect that rollmean works also with missing values as in the example below

Minimal, reproducible example

library(xts)

n <- 10
x <- xts(1:n, order.by = Sys.Date() + 1:n)
xx <- cbind(x, x)
rollmean(xx, k = n) # -> works fine

xx[n, 1] <- NA # -> add a missing value
rollmean(xx, k = n) # -> fails

Session Info

R version 4.2.0 (2022-04-22)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS Monterey 12.2.1

Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices datasets  utils     methods   base     

other attached packages:
[1] xts_0.12.1 zoo_1.8-10

loaded via a namespace (and not attached):
[1] compiler_4.2.0  tools_4.2.0     grid_4.2.0      renv_0.15.4     lattice_0.20-45
@joshuaulrich
Copy link
Owner

Thanks for the report!

I also noticed that rollmean() is using align = "center" instead of align = "right" like rollapply.xts() does by default. That's because there isn't a rollmean.xts() method for the rollmean() generic to dispatch, so it dispatches to rollmean.zoo(), and it uses align = "center" by default. So we probably also need xts methods for 'rollmean', 'rollsum', 'rollmedian', and 'rollmax'.

@eguidotti
Copy link
Author

That would be awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants