[R] Running totals
Joshua Wiley
jwiley.psych at gmail.com
Mon Nov 14 00:20:07 CET 2011
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
> 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:
> I have a table which looks like this:
>
> ACC BAL
> 1 hal -171245.33
> 2 opn -50487.63
> 3 pga 213440.38
> 4 prt 0.18
> 5 rbs 8292.54
>
> How do I create a column which shows the running totals of the BAL columns?
>
> [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
--
Joshua Wiley
Ph.D. Student, Health Psychology
Programmer Analyst II, ATS Statistical Consulting Group
University of California, Los Angeles
https://joshuawiley.com/
More information about the R-help
mailing list