Partial sum of a vector
?filter
x
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
filter(x, rep(1,4))
Time Series: Start = 1 End = 20 Frequency = 1 [1] NA 10 14 18 22 26 30 34 38 42 46 50 54 58 62 66 70 74 NA NA
On Sun, Mar 1, 2009 at 9:29 PM, Mohammad Sabr <mohammad_sabr at yahoo.com> wrote:
I am trying to run a loop where I can sum parts of a matrix. For example, I want at each step in the loop to sum the?the next?4-values of a vector. I tried to do the following but the result were wrong:
for (i in 4:T) {
data_q[i-3,]=sum(data_m[i-3,]:data_m[i,])
}
can anyone please direct me on what should I do to run this loop properly
Thanks in advance
? ? ? ?[[alternative HTML version deleted]]
______________________________________________ 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.
Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?