Re: [R] Sum the cell of a vector

From: Jonathan Daily <biomathjdaily_at_gmail.com>
Date: Tue, 03 May 2011 11:39:38 -0400

?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.

______________________________________________
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.
Received on Thu 05 May 2011 - 06:25:11 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 05 May 2011 - 07:00:06 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive