Subset Zoo Object by Datetime

Subset Zoo Object by Datetime

I'm trying to subset the the ZOO object x below for SaleDateTime > "2013-01-01 00:00:00.00". I've tried the attempt below, which get close but not exactly what I want. For some reason it returns records starting in 2014. The data goes all the way back to 2011 and there's plenty of values with SaleDateTime in 2013. The data has the form SaleDateTime = '2012-02-01 23:00:00.000' and SaleCount=4. This doesn't seem like it should be that tricky. I would definitely appreciate advice.

x<-zoo(Value$SalesCount, order.by=Value$SaleDateTime)

Attempt 1

 vv<-subset(x, index(x)>=as.Date("2013-01-01 00:00:00.000"))

Warning message: In eval(expr, envir, enclos) : Incompatible methods ("Ops.factor", "Ops.Date") for ">="

1

1 Answer

Subsetting with [ using the index is one solution. Following the example:

vv <- x[index(x) >= as.Date("2013-01-01 00:00:00.000")]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Maya Lin-Takahashi
Author

Maya Lin-Takahashi

Maya is a hardware enthusiast who tests and reviews smart home devices, smartphones, wearables, and audio gear. She focuses on practical consumer value and build quality.