[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

HTH,

Eric



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
>below?
>
>Thanks.
>
>-Ben
>
>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
>https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>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
Belgium

tel: (+32)(0)10473050
lecoutre at stat.ucl.ac.be
http://www.stat.ucl.ac.be/ISpersonnel/lecoutre

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




More information about the R-help mailing list