dear R-Community is there a function which sums data "stepwise" exp: 2 1 4 5 Desired result 2 = 2 2+1 = 3 2+1+4 = 7 2+1+4+5 = 12 Is there a built in function for this? Thx Dom -- View this message in context: http://r.789695.n4.nabble.com/stepwise-sum-tp3874606p3874606.html Sent from the R help mailing list archive at Nabble.com.
"stepwise" sum
3 messages · behave, Nordlund, Dan (DSHS/RDA), Sarah Goslee
-----Original Message----- From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- project.org] On Behalf Of behave Sent: Wednesday, October 05, 2011 7:07 AM To: r-help at r-project.org Subject: [R] "stepwise" sum dear R-Community is there a function which sums data "stepwise" exp: 2 1 4 5 Desired result 2 = 2 2+1 = 3 2+1+4 = 7 2+1+4+5 = 12 Is there a built in function for this? Thx Dom
?cumsum Hope this is helpful, Dan Daniel J. Nordlund Washington State Department of Social and Health Services Planning, Performance, and Accountability Research and Data Analysis Division Olympia, WA 98504-5204
cumsum(c(2,1,4,5))
[1] 2 3 7 12
On Wed, Oct 5, 2011 at 10:06 AM, behave <dethlef1 at hotmail.com> wrote:
dear R-Community is there a function which sums data "stepwise" exp: 2 1 4 5 Desired ?result 2 = 2 2+1 = 3 2+1+4 = 7 2+1+4+5 = 12 Is there a built in function for this? Thx Dom
Sarah Goslee http://www.functionaldiversity.org