[R] Sum the cell of a vector
Alaios
alaios at yahoo.com
Tue May 3 17:32:18 CEST 2011
Dear all,
I would like to know what is the most time efficient way to calculate the following in a huge vector.
Let's say that I have the vector
1,2,3,4,5,6
and I want to return a vector of the same length which every cell containing the sum of the previous cells like this
1, 1+2, 1+2+3, 1+2+3+4, 1+2+3+4+5, 1+2+3+4+5+6
What do you think is the most effective way to do that (not having to do the previous sum).
Of course I can do this with a for loop but I believe that might be a more efficient way in R.
I would like to thank you in advance for your help
Best Regards
Alex
More information about the R-help
mailing list