At 7:33 PM +0530 7/23/08, Shubha Vishwanath Karanth 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


colSums(matrix(x,nrow=8))

Bill

--
William Revelle         http://personality-project.org/revelle.html
Professor                       http://personality-project.org/personality.html
Department of Psychology             http://www.wcas.northwestern.edu/psych/
Northwestern University http://www.northwestern.edu/
Attend  ISSID/ARP:2009               http://issid.org/issid.2009/

______________________________________________
R-help@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.

Reply via email to