I still have problems understanding the data.table format. Can someone explain why the following does not work?
I am trying to classify dates in groups using cut . The breaks used can be found in another data table and depend on the by argument of the external data data.table
data <- data.table(A = c(1, 1, 1, 2, 2, 2), DATE = as.POSIXct(c("01-01-2012", "30-05-2015", "01-01-2020", "30-06-2012", "30-06-2013", "01-01-1999"), format = "%d-%m-%Y")) breaks <- data.table(B = c(1, 1, 2, 2), BREAKPOINT = as.POSIXct(c("01-01-2015", "01-01-2016", "30-06-2012", "30-06-2013"), format = "%d-%m-%Y")) data[, bucket := cut(DATE, breaks[B == A, BREAKPOINT], ordered_result = T), by = A]
I can get the desired result by doing
Thanks Michael
source share