Running sum
Prof Brian Ripley wrote:
?cumsum On Fri, 19 Nov 2004, Sean Davis wrote:
I have vector X of length N that I want to have a running sum for
(called Y). I just need max(Y). I do this with a "for" loop like so:
Y <- vector(length=N)
Y[1] <- X[1]
for (i in 2:N) {
Y[i] <- Y[i-1]+X[i]
}
return(max(Y))
Is there a faster way to do this?
My apologies, I am not being entirely serious, but... Please do read the posting guide! (particularly the third point in the "Responding to other posts" section). Bob
Bob O'Hara Department of Mathematics and Statistics P.O. Box 68 (Gustaf H??llstr??min katu 2b) FIN-00014 University of Helsinki Finland Telephone: +358-9-191 51479 Mobile: +358 50 599 0540 Fax: +358-9-191 51400 WWW: http://www.RNI.Helsinki.FI/~boh/ Journal of Negative Results - EEB: www.jnr-eeb.org