Re: [R] sequential sum of a vector...

From: Shubha Vishwanath Karanth <shubhak_at_ambaresearch.com>
Date: Wed, 23 Jul 2008 21:01:44 +0530


Many Thanks Jorge... That was one more way...Is it possible if I can do this without using rep(1:10,each=8) or the grouping....because I feel the number 8 here is fixed... If there is some technique of tracking the position of first 8, then next 8... don't know whether I am clear in conveying...  

Thanks, shubha  


From: Jorge Ivan Velez [mailto:jorgeivanvelez_at_gmail.com] Sent: Wednesday, July 23, 2008 8:59 PM
To: Shubha Vishwanath Karanth
Cc: r-help_at_stat.math.ethz.ch
Subject: Re: [R] sequential sum of a vector...

Dear Shubha,

Try this:

x=1:80
tapply(x,rep(1:10,each=8),sum)
 1 2 3 4 5 6 7 8 9 10
 36 100 164 228 292 356 420 484 548 612

HTH, Jorge

On Wed, Jul 23, 2008 at 10:03 AM, Shubha Vishwanath Karanth <shubhak_at_ambaresearch.com> wrote:

Hi R,

Let,

x=1:80

I want to sum up first 8 elements of x, then again next 8 elements of x, then again another 8 elements..... So, my new vector should look like:

c(36,100,164,228,292,356,420,484,548,612)

I used:

aggregate(x,list(rep(1:10,each=8)),sum)[-1]

or

rowsum(x,group=rep(1:10,each=8))

But without grouping, can I achieve the required? Any other ways of doing this?

Thanks, Shubha

This e-mail may contain confidential and/or privileged i...{{dropped:13}}



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.

This e-mail may contain confidential and/or privileged i...{{dropped:13}}



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 Wed 23 Jul 2008 - 16:29:26 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 Wed 23 Jul 2008 - 17:32:25 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