I am trying to create a variable that indicates what quarter of the fiscal year a transaction was completed. Thus, this I need to customize the start and end dates of the quarter variable.
dt <- data.table(
date = c("2016-09-26", "2016-10-14", "2017-01-09"),
value = c(42, 87, 102),
location = c("a","b","c"))
dt$date <- as.Date(dt$date, "%m/%d/%Y")
I have tried using this code but it returns "invalid specification in breaks"...
dt$quarter <- cut(dt$date,
breaks=c(-Inf, "2016-07-26", "2016-12-31", Inf),
labels=c("Q3-2016","Q4-2016","Q1-2017""))
Any suggestions on how can I re-code this?