use 'rle';
> a <- rnorm(20)
> b <- a < .5
> b
[1] FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE TRUE
TRUE
[13] FALSE FALSE TRUE TRUE TRUE FALSE TRUE FALSE
> rle(b)
Run Length Encoding
lengths: int [1:9] 1 7 2 2 2 3 1 1 1
values : logi [1:9] FALSE TRUE FALSE TRUE FALSE TRUE FALSE TRUE FALSE
>
__________________________________________________________
James Holtman "What is the problem you are trying to solve?"
Executive Technical Consultant -- Office of Technology, Convergys
[EMAIL PROTECTED]
+1 (513) 723-2929
Sean Davis
<[EMAIL PROTECTED] To: r-help
<[email protected]>
> cc:
Sent by: Subject: [R] Finding "runs"
of TRUE in binary vector
[EMAIL PROTECTED]
ath.ethz.ch
01/27/2005 17:13
I have a binary vector and I want to find all "regions" of that vector
that are runs of TRUE (or FALSE).
> a <- rnorm(10)
> b <- a<0.5
> b
[1] TRUE TRUE TRUE FALSE TRUE FALSE TRUE TRUE TRUE TRUE
My function would return something like a list:
region[[1]] 1,3
region[[2]] 5,5
region[[3]] 7,10
Any ideas besides looping and setting start and ends directly?
Thanks,
Sean
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
- Re: [R] Finding "runs" of TRUE in bi... james . holtman
- Re: [R] Finding "runs" of TRUE ... Kjetil Brinchmann Halvorsen
