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