Sum the cell of a vector
?cumsum
On Tue, May 3, 2011 at 11:32 AM, Alaios <alaios at yahoo.com> wrote:
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
______________________________________________ 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.
=============================================== Jon Daily Technician =============================================== #!/usr/bin/env outside # It's great, trust me.