[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,

Re: [R] Running Total

2012-03-05 Thread Mikhail Titov
Edward Patzelt patze...@umn.edu 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,

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 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 jholt...@gmail.com 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,

Re: [R] Running Total

2012-03-05 Thread R. Michael Weylandt michael.weyla...@gmail.com
cumsum(1-x) cumsum(x==0) Michael On Mar 5, 2012, at 1:59 PM, Edward Patzelt patze...@umn.edu 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 jholt...@gmail.com wrote: cumsum is probably what you

Re: [R] Running Total

2012-03-05 Thread Mikhail Titov
Edward Patzelt patze...@umn.edu 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 jholt...@gmail.com wrote: cumsum is probably what you want: x - c(1L, 1L, 0L, 1L, 1L, 1L, 1L, 1L, 0L, 1L,

Re: [R] Running Total

2012-03-05 Thread Mark Lamias
Lamias From: Edward Patzelt patze...@umn.edu To: jim holtman jholt...@gmail.com 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