I am trying to write a function in tidyverse/dplyr
that I want to eventually use with lapply
(or map
). (I had been working on it to answer
I'm not really a dplyr afficionado, but for what its worth here is how you could achieve this using library(data.table)
instead:
setDT(sample_data)
gen_report <- function(report_cat){
sample_data[ , .(num = .N, total = sum(AMOUNT), REPORT_CATEGORY = report_cat),
by = .(REPORT_VALUE = get(report_cat), YEAR)]
}
gen_report('REPORT_CODE')
lapply(cat.list, gen_report)