I would like to get a reducing rolling product within my group(s) using data.table. That is, the first row in the data set tst below would be the product of all 4 value-observations within group A and orderVal(1:4). The second would be orderVal 2:4, the third 3:4 and the last just 4:4 and so on for all k-groups. I could do it with a for-loop but I know this probably could be done a lot cleaner and more efficently using just data.table.
Reproducible code below:
require(data.table)
tst <- data.table(grp = c(rep("A", 4), rep("B",4)),
orderVal = c(rep(seq(1,4),2)),
val = c(rep(1.4, 4), rep(1.5, 4)))