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,
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,
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,
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,
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
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,
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
7 matches
Mail list logo