Re: [R] sequentially summing up a elements of a vector

2012-01-21 Thread Jorge I Velez
Try cumsum(x) HTH, Jorge.- On Sat, Jan 21, 2012 at 6:59 PM, Martin Batholdy <> wrote: > Hi, > > > I have a somewhat abstract and tricky problem (at least for me). > > > Perhaps someone here can help me: > > > I would like to convert: > > x <- c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0

Re: [R] sequentially summing up a elements of a vector

2012-01-21 Thread R. Michael Weylandt
Perhaps I misunderstand you, but ?cumsum. x <- c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0) y <- c(0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4) identical(cumsum(x), y) Michael On Sat, Jan 21, 2012 at 6:59 PM, Martin Batholdy wrote: > Hi, > > > I have

[R] sequentially summing up a elements of a vector

2012-01-21 Thread Martin Batholdy
Hi, I have a somewhat abstract and tricky problem (at least for me). Perhaps someone here can help me: I would like to convert: x <- c(0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0) into x <- c(0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4) every 1 i