-
-
Notifications
You must be signed in to change notification settings - Fork 71
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
ifelse fails with multi-column xts object #198
Comments
Thanks for the report! Interestingly, this also failed in 0.9-7 if the index was POSIXct, as created by R> set.seed(21)
R> xxts <- xts(matrix(rnorm(30) > 0, 5, 3), .POSIXct(1:5))
R> x.xts <- .xts(matrix(rnorm(30) > 0, 5, 3), 1:5)
R>
R> ifelse(xxts, -1, 1)
[,1] [,2] [,3]
1969-12-31 18:00:01 -1 -1 1
1969-12-31 18:00:02 -1 1 -1
1969-12-31 18:00:03 -1 1 1
1969-12-31 18:00:04 1 -1 -1
1969-12-31 18:00:05 -1 1 -1
R> ifelse(x.xts, -1, 1)
Error in `[.xts`(test, ok) : 'i' or 'j' out of range
R>
R> y <- xxts
R> index(y) <- seq(as.Date('2017-07-01'), by='day', length.out=5)
R> ifelse(y, -1, 1)
[,1] [,2] [,3]
2017-07-01 -1 -1 1
2017-07-02 -1 1 -1
2017-07-03 -1 1 1
2017-07-04 1 -1 -1
2017-07-05 -1 1 -1
R> packageVersion("xts")
[1] '0.9.7' But it's consistently broken in version 0.10-0. R> set.seed(21)
R> xxts <- xts(matrix(rnorm(30) > 0, 5, 3), .POSIXct(1:5))
R> x.xts <- .xts(matrix(rnorm(30) > 0, 5, 3), 1:5)
R>
R> ifelse(xxts, -1, 1)
Error in `[.xts`(test, ok) : 'i' or 'j' out of range
R> ifelse(x.xts, -1, 1)
Error in `[.xts`(test, ok) : 'i' or 'j' out of range
R>
R> y <- xxts
R> index(y) <- seq(as.Date('2017-07-01'), by='day', length.out=5)
R> ifelse(y, -1, 1)
Error in `[.xts`(test, ok) : 'i' or 'j' out of range
R> packageVersion("xts")
[1] '0.10.0' I'll continue to investigate. |
This is related to #163. The fix to that bug seems to be what's triggering the error now. This is because: R> storage.mode(.index(xxts))
[1] "double"
R> storage.mode(.index(x.xts))
[1] "integer" And that's what explains why |
Hi Joshua, Today, when I downloaded "quantsrat", it automatically updated xts to v0.10-0 and ever since I'm having the problem with ifelse() on xts objects. I'd be really thankful if you could point me towards a solution as this piece of code is paramount to my work... Many Thanks! |
xts v0.10-0 is the current version of xts. The error you show has nothing to do with ifelse, and in general ifelse should work as it always has on newer xts objects (with the exceptions noted in this thread about use of the xts constructor). Perhaps you could create a minimal reproducible example? |
The original error I'm getting, is: The code reads large xlsx files, converts them to xts objects, performs rollapply() to extract rolling regression coefficients and then uses ifelse() to generate rules.
This code is being applied to various sheets within a workbook via an lapply() function thx! |
Revert back to xts 0.9-7 on your latest R version. devtools::install_version("xts", version = "0.9-7") |
Hi, thanks for confirming.
|
Case solved ; |
Notes from an email discussion with the zoo team. My initial email contained the example code below: x <- xts(matrix(!c(0,0,0,1,0,0,1,1,0), 3, 3), .POSIXct(1:3, tz = "UTC"))
colnames(x) <- letters[1:ncol(x)]
z <- as.zoo(x)
s <- as.ts(z)
ifelse(s, 1, 0) # works
ifelse(z, 1, 0) # error
ifelse(x, 1, 0) # error Achim's initial thoughts:
Josh's proposal:
Gabor's thoughts:
Achim's reply to Gabor:
|
Removing the milestone, since I'm not sure when (or if) this will be implemented. |
ifelse()
was working fine with multi-column xts object in 0.9-7 version.Using v0.10-0 I get the following:
Similar (#36).
Session info
The text was updated successfully, but these errors were encountered: