Re: [R] Running Total

2012-03-05 Thread Mark Lamias
ark Lamias From: Edward Patzelt To: jim holtman Cc: r-help@r-project.org Sent: Monday, March 5, 2012 1:59 PM Subject: Re: [R] Running Total Actually in looking at this I need it to only add if a 0 occurs instead of a 1. On Mon, Mar 5, 2012 at 12:57 PM, jim holt

Re: [R] Running Total

2012-03-05 Thread Mikhail Titov
Edward Patzelt writes: > Actually in looking at this I need it to only add if a 0 occurs instead of > a 1. cumsum(1-x) > > On Mon, Mar 5, 2012 at 12:57 PM, jim holtman wrote: > >> cumsum >> >> is probably what you want: >> >> > x <- c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L,

Re: [R] Running Total

2012-03-05 Thread R. Michael Weylandt
cumsum(1-x) cumsum(x==0) Michael On Mar 5, 2012, at 1:59 PM, Edward Patzelt wrote: > Actually in looking at this I need it to only add if a 0 occurs instead of > a 1. > > On Mon, Mar 5, 2012 at 12:57 PM, jim holtman wrote: > >> cumsum >> >> is probably what you want: >> >>> x <- c(1L, 1L,

Re: [R] Running Total

2012-03-05 Thread Edward Patzelt
Actually in looking at this I need it to only add if a 0 occurs instead of a 1. On Mon, Mar 5, 2012 at 12:57 PM, jim holtman wrote: > cumsum > > is probably what you want: > > > x <- c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, > + 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L,

Re: [R] Running Total

2012-03-05 Thread jim holtman
cumsum is probably what you want: > x <- c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, + 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, + 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, + 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L,

Re: [R] Running Total

2012-03-05 Thread Mikhail Titov
Edward Patzelt writes: > I'm am trying to create a vector that has a running total that adds each > time a 1 occurs. here's the code and data > > c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, > 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, > 0L, 1L, 1L, 1L, 1L,

[R] Running Total

2012-03-05 Thread Edward Patzelt
I'm am trying to create a vector that has a running total that adds each time a 1 occurs. here's the code and data c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 0L, 1L, 1L, 1L, 1L,