joshuaulrich / xts

Extensible time series class that provides uniform handling of many R time series classes by extending zoo.
http://joshuaulrich.github.io/xts/
GNU General Public License v2.0
219 stars 70 forks source link

rollapply #399

Open ggrothendieck opened 1 year ago

ggrothendieck commented 1 year ago

This fails if as.zoo is removed.

# https://stackoverflow.com/questions/75954700/75978704#75978704
library(quantmod)
getSymbols("SPY")
SPY.Close <- Ad(SPY)

SPY.Close$dn3 <- +rollapplyr(diff(as.zoo(SPY.Close)) < 0, 3, identical, 
  c(TRUE, TRUE, TRUE), fill = NA)
joshuaulrich commented 1 year ago

It fails for me even with the as.zoo().

SPY.Close$dn3 <- +rollapplyr(diff(as.zoo(SPY.Close)) < 0, 3, identical, 
    c(TRUE, TRUE, TRUE), fill = NA)
## Error in NextMethod(.Generic) : 
##   number of items to replace is not a multiple of replacement length

What's your sessionInfo()?

R$ sessionInfo()
R version 4.2.2 Patched (2022-11-10 r83330)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.10.0
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C               LC_TIME=en_US.UTF-8       
 [4] LC_COLLATE=en_US.UTF-8     LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                  LC_ADDRESS=C              
[10] LC_TELEPHONE=C             LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

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

other attached packages:
[1] quantmod_0.4.22 TTR_0.24.3      xts_0.13.0      zoo_1.8-11      colorout_1.2-2 

loaded via a namespace (and not attached):
[1] compiler_4.2.2  tools_4.2.2     curl_5.0.0      grid_4.2.2      jsonlite_1.8.4 
[6] lattice_0.20-45