How can I aggregate the dates column per month and date?
library(data.table)
df <- data.table(dates = c('2017-01-01', '2017-01-05'))
chosen_col <- 'dates'
Tried the following which does not work:
df[, .(n = .N), by = str_sub(chosen_col, 1, 7)]
df[, .(n = .N), by = eval(str_sub(chosen_col, 1, 7))]
EDIT:
So the question is how do I pass a character vector to a function inside the by argument. Fully aware of workarounds for the date problem.