[R] rolling sum (like in Rmetrics package)

From: joshv <josh.verdone_at_yahoo.com>
Date: Wed, 13 Feb 2008 08:25:57 -0800 (PST)

Hello, I'm new to R and would like to know how to create a vector of "rolling sums". (I have seen the Rmetrics package and the rollMean function and I would like to do the same thing except Sum instead of Mean.) I imagine someone has done this, I just can't find it anywhere.

x <- somevector #where x is 'n' entries long

#what I would like to do is:

x1 <- x[1:20]
output1 <- sum(x1)

x2 <- x[2:21]
output2 <- sum(x2)

x3 <- ...

ouput <- c(output1, output2, ...)


View this message in context: http://www.nabble.com/rolling-sum-%28like-in-Rmetrics-package%29-tp15459848p15459848.html
Sent from the R help mailing list archive at Nabble.com.

R-help_at_r-project.org mailing list
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 13 Feb 2008 - 16:29:54 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 13 Feb 2008 - 17:30:13 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