I have a data table with this schema:
date, key_a, key_b, key_c, key_d, value
I'd like to make a list of lists that has this structure:
[1]
date, key_a, value
[2]
date, key_b, value
[3]
date, key_c, value
I'd like to aggregate my dt
into a list where each of the entries is aggregating the dt
across a separate one of the keys.
This is my code
setDT(dt)
list_of_dts[1] <-
dt[, .(value = sum(value)), .(date, key_a)]
list_of_dts[2] <-
dt[, .(value = sum(value)), .(date, key_b)]
(So on)
Is there a more efficient way of solving this?