Why can’t I use the & operator in xts objects when querying dates?
For example, these will work:
myts[myts$Symbol == "AAPL" & myts$Size > 100, c("Symbol", "Size")]
myts['2011-09-21', c("Symbol", "Size")]
But this AND condition on a date/time query will not work:
myts[myts$Symbol == "AAPL" & '2011-09-21', c("Symbol", "Size")]
Error in `&.default`("2011-09-21", myts$Symbol == "AAPL") :
operations are possible only for numeric, logical or complex types
"2011-09-21"is not a logical vector and cannot be coerced to a logical vector. See?"&"for details.xts’ ISO-8601 style subsetting is nice, but there’s nothing we can do to change the behavior of
.Primitive("&"). You can do something like this though: