[R] or of a logical vector

Eric Lecoutre lecoutre at stat.ucl.ac.be
Thu Aug 5 20:19:05 CEST 2004

Hi Ben,

Always do consider that boolean vectors TRUE/FALSE are equivalent to 
integers 1/0.
What you want is to know wether one element of a vector is TRUE, which is:

 > sum(vec)>0



At 18:38 5/08/2004, Ben Wittner wrote:
>Is there some fast (built-in?) way to get the OR of all the elements in a
>logical vector?
>In other words, is there some fast (built-in) version of the function vor
>vor <- function(v) {
>   ans <- v[1]
>   if (length(v) > 1)
>     for (i in 2:length(v))
>       ans <- ans | v[i]
>   ans
>R-help at stat.math.ethz.ch mailing list
>PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html

Eric Lecoutre
UCL /  Institut de Statistique
Voie du Roman Pays, 20
1348 Louvain-la-Neuve

tel: (+32)(0)10473050
lecoutre at stat.ucl.ac.be

If the statistics are boring, then you've got the wrong numbers. -Edward 

More information about the R-help mailing list