> Perhaps I'm missing something, but isn't the maximum of the cumulative
> sum simply the last value, ie. sum(x)?
As many have mentioned, I was forgetting the negative numbers. Thanks
to those who pointed that out.
Hadley
__
[EMAIL PROTECTED] mailing
sum*, which is something
totally different.
Best,
Philippe Grosjean
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of
> Philippe Grosjean
> Sent: Friday, November 19, 2004 9:11 PM
> To: [EMAIL PROTECTED]; 'Sean Davis'
>
On Fri, 2004-11-19 at 18:00 -0600, Douglas Bates wrote:
> I have forgotten the details of the original question but it seems to me
> that if the elements of x could be both positive and negative then the
> maximum of the cumulative sum doesn't have to be the last sum.
On Fri, 2004-11-19 at 20:0
Marc Schwartz wrote:
On Fri, 2004-11-19 at 16:44 -0600, hadley wickham wrote:
Perhaps I'm missing something, but isn't the maximum of the cumulative
sum simply the last value, ie. sum(x)?
Hadley
Indeed!
And...going back to Sean's original post he did write:
"I just need max(Y)."
Thus, a whole grou
Marc Schwartz wrote:
On Fri, 2004-11-19 at 16:44 -0600, hadley wickham wrote:
Perhaps I'm missing something, but isn't the maximum of the cumulative
sum simply the last value, ie. sum(x)?
Hadley
Indeed!
And...going back to Sean's original post he did write:
"I just need max(Y)."
Thus, a wh
On Fri, 2004-11-19 at 16:44 -0600, hadley wickham wrote:
> Perhaps I'm missing something, but isn't the maximum of the cumulative
> sum simply the last value, ie. sum(x)?
>
> Hadley
Indeed!
And...going back to Sean's original post he did write:
"I just need max(Y)."
Thus, a whole group of us
Perhaps I'm missing something, but isn't the maximum of the cumulative
sum simply the last value, ie. sum(x)?
Hadley
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.or
On Fri, 2004-11-19 at 21:10 +0100, Philippe Grosjean wrote:
> ?cumsum is not exactly the answer (as I understand it), but a part of it.
> I propose:
>
> runSum2 <- function(x)
> cumsum(x)[-1] - c(0, cumsum(x[1:(length(x) - 2)]))
>
> # Example
> a <- round(runif(10, 0, 10))
> a
> runSum2(a)
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]
--Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] On Behalf Of Marc Schwartz
> Sent: Friday, November 19, 2004 7:57 PM
> To: Sean Davis
> Cc: R-Help
> Subject: Re: [R] Running sum
>
> On Fri, 2004-11-19 at 13:08 -0500, Sean Davis wrote:
> > I
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
Have you considered "cumsum"?
> cumsum(c(1, 2, 3, -9, 2))
[1] 1 3 6 -3 -1
hope this helps. spencer graves
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 <- v
?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 th
On Fri, 2004-11-19 at 13:08 -0500, 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]
Thanks all.
cumsum does the job
Sean
__
[EMAIL PROTECTED] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
see ?cumsum
x <- 1:10
cumsum(x)
max(cumsum(x))
HTH, Andy
> -Original Message-
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] Behalf Of Sean Davis
> Sent: Friday, November 19, 2004 1:09 PM
> To: r-help
> Subject: [R] Running sum
>
>
> I have vector X of length N that I want to ha
See cumsum:
> x <- rnorm(10)
> cs <- function(X) {
+ N <- length(X)
+ Y <- vector(length=N)
+ Y[1] <- X[1]
+ for (i in 2:N) {
+Y[i] <- Y[i-1]+X[i]
+ }
+ return(max(Y))
+ }
> cs(x)
[1] 3.228554
> max(cumsum(x))
[1] 3.228554
Andy
> From: Sean Davis
>
> I hav
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
18 matches
Mail list logo