Message-ID: <419E43DE.8000308@jhsph.edu>
Date: 2004-11-19T19:05:02Z
From: Roger D. Peng
Subject: Running sum
In-Reply-To: <09151670-3A56-11D9-AD50-000A95D7BA10@mail.nih.gov>
You could try using embed(), but I doubt it's faster.
-roger
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?
>
> Thanks,
> Sean
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
--
Roger D. Peng
http://www.biostat.jhsph.edu/~rpeng/