I have a data.table dt as follows.
data.table
dt
df <- data.frame(t1 = rep(0,5), t3 = c(12, 5, 8,9, 5), t7= c(25, 48, 7, 9, 14)) dt <- setD
Another option use Reduce with accumulate=TRUE:
Reduce
accumulate=TRUE
dt[, names(dt) := Reduce(`+`, dt, accumulate = TRUE)] dt # t1 t3 t7 #1: 0 12 37 #2: 0 5 53 #3: 0 8 15 #4: 0 9 18 #5: 0 5 19