Skip to content
Prev 277237 / 398506 Next

Running totals

Hi Mark,

Take a look at ?cumsum and see if this is what you want:

## your data output via dput() (easy to copy and paste from email to R)
dat <- structure(list(ACC = c("hal", "opn", "pga", "prt", "rbs"),
BAL = c(-171245.33,
-50487.63, 213440.38, 0.18, 8292.54)), .Names = c("ACC", "BAL"
), class = "data.frame", row.names = c("1", "2", "3", "4", "5"
))

dat$RTotal <- cumsum(dat$BAL)

dat
ACC        BAL     RTotal
1 hal -171245.33 -171245.33
2 opn  -50487.63 -221732.96
3 pga  213440.38   -8292.58
4 prt       0.18   -8292.40
5 rbs    8292.54       0.14


Hope this helps,

Josh
On Sun, Nov 13, 2011 at 1:18 PM, Mark Carter <mcturra2000 at yahoo.co.uk> wrote: