I have a long numeric vector v (length N) and I want create a shorter vector of length N/k consisting of sums of k-subsequences of v:
v <- c(1,2,3,4,5,6,7,8,9,10) N=10, k=3 ===> [6,15,24,10] I can, of course, iterate: > w <- vector(mode="numeric",length=ceiling(N/k)) > for (i in 1:length(w)) w[i] <- sum(v(i*k:(i+1)*k)) (modulo boundary conditions) but I wonder if there is a better way. thanks! -- Sam Steingold (http://sds.podval.org/) on Ubuntu 12.04 (precise) X 11.0.11103000 http://www.childpsy.net/ http://think-israel.org http://thereligionofpeace.com http://dhimmi.com http://truepeace.org http://www.PetitionOnline.com/tap12009/ Type louder, please. ______________________________________________ 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.