Thanks for introducing me to "with" and the smart use of R subscripting
Now I know I can do something like this.
test<-c(1,1,1,1,1,0,0,0,0,0,2,2,2,2,2,2,0,1,0,1,1,0,0,0,0,0,0,0)
> with(rle(test), max(lengths[values==2]))
[1] 6
> with(rle(test), max(lengths[values==1]))
[1] 5
> with(rle(test), max(
!!
On Sat, May 23, 2009 at 1:52 PM, tsunhin wong wrote:
> Thanks!
> I tested it using:
> test<-c(1,1,1,1,1,0,0,0,0,0,0,0,1,1,0,1,0,1,0,1,1)
> that has a longer 7 zeros and 5 ones.
>
> What part of the script does the selection of ones instead of zeros?
>
> - John
>
> On Sat, May 23, 2009 at 1:17
Thanks!
I tested it using:
test<-c(1,1,1,1,1,0,0,0,0,0,0,0,1,1,0,1,0,1,0,1,1)
that has a longer 7 zeros and 5 ones.
What part of the script does the selection of ones instead of zeros?
- John
On Sat, May 23, 2009 at 1:17 PM, Gabor Grothendieck
wrote:
> Try this:
>
> with(rle(test), max(lengths[
Try this:
with(rle(test), max(lengths[!!values]))
On Sat, May 23, 2009 at 1:09 PM, tsunhin wong wrote:
> Dear R Users,
>
> I am trying to write a script to count the longest consecutive
> occurring 1 in a sequence:
> test<-c(1,1,1,1,1,1,1,0,0,0,0,1,1,0,1,0,1,0,1,1)
>
> In the case of the object
Dear R Users,
I am trying to write a script to count the longest consecutive
occurring 1 in a sequence:
test<-c(1,1,1,1,1,1,1,0,0,0,0,1,1,0,1,0,1,0,1,1)
In the case of the object "test", 1 occurs 7 consecutive times which
is the longest consecutive within the sequence.
I know I can always do a th
5 matches
Mail list logo