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

subset inconsistent with zoo when 'i' contains NA #414

Open joshuaulrich opened 5 months ago

joshuaulrich commented 5 months ago

xts subset does not allow NA in 'i' like zoo does.

require(xts)
x <- .xts(matrix(1:20, 10, 2), 1:10)
z <- as.zoo(x)
i <- c(1, NA, 5)

z[i,]
##                          
## 1969-12-31 18:00:01  1 11
## 1969-12-31 18:00:05  5 15
## <NA>                NA NA

x[i,]
## Error in `[.xts`(x, i, ) : 
##   only zeros may be mixed with negative subscripts

Making this consistent will not be a breaking change since it is currently an error in xts.