I am having a question about sequencing dates in data.table by group.
I have this code that use to work in the past but now it is not working.
I have figured out that this issue is do to having a newer version of the data.table package.
The code just worked on an older version (1.8.x) and now it updated to 1.9.2 and the code isn't working.
Can anyone help me figure this out.
Here is some data:
test_data <- data.frame(group=c(1,2,3),
date=c("2011-01-01","2012-02-02","2013-03-03"),
date2=Sys.Date(),
stringsAsFactors=FALSE)
test_data[,"date"] <- as.Date(test_data[,"date"])
test_data[,"date2"] <- as.Date(test_data[,"date2"])
Here is my code"
library("data.table")
identifier <- "group"
results <- data.table(test_data)[,{s=seq(from=date,to=Sys.Date(),by="days")},
by=list(group,date)]
I am getting the following error:
Error in Ops.Date(del, by) : / not defined for "Date" objects
Thanks ahead of time!
you can try as.POSIXct intstead of as.Date. In my experience, data.table works well with POSIXct type rather than date type
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With