[R] Sub-vector

Roger Bivand Roger.Bivand at nhh.no
Wed Mar 29 19:29:44 CEST 2006


On Thu, 30 Mar 2006, Wuming Gong wrote:

> Dear list,
> 
> Given a vector of logical values, say
> 
> >a <- c(TRUE,TRUE,TRUE,FALSE,FALSE,FALSE,FALSE,TRUE,TRUE,TRUE)
> 
> Are there any R functions that can tell whether there are two or more
> "TRUE" in a row in this vector?

?rle (a very useful function)

aa <- rle(a)
any(aa$values & aa$lengths > 1)


> 
> Thanks,
> 
> Wuming
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no




More information about the R-help mailing list