I have a data.table as follows
set.seed(5) x <- data.table(x=sample(1:20,15)) > x x 1: 5 2: 14 3: 17 4: 20 5: 2 6: 11 7: 8 8: 15 9: 12 10
A base R solution:
i = 1 v = i sum = 0 while (i <= nrow(x)) { v = c(v, i) sum = sum + x$x[i] i = sum }