Re: [R] running sum of a vector

2007-11-07 Thread Benilton Carvalho
x <- 1:10 cumsum(x) b On Nov 7, 2007, at 5:59 PM, Alexy Khrabrov wrote: > I need a vector with sums of vectors up to each position in the > original. The imperative version is simple: > > # running sum: the traditional imperative way > sumr.1 <- function(x) { > s <- c() > ss <- 0 > for (i

Re: [R] running sum of a vector

2007-11-07 Thread Chuck Cleland
Alexy Khrabrov wrote: > I need a vector with sums of vectors up to each position in the > original. The imperative version is simple: > > # running sum: the traditional imperative way > sumr.1 <- function(x) { >s <- c() >ss <- 0 >for (i in 1:length(x)) { > ss <- ss + x[i] >