[R] or of a logical vector

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Aug 5 21:03:26 CEST 2004


See ?any, which does this directly.

On Thu, 5 Aug 2004, Eric Lecoutre wrote:

> 
> Hi Ben,
> 
> Always do consider that boolean vectors TRUE/FALSE are equivalent to 
> integers 1/0.

Not really.  They are in almost all arithmetic expressions.

> 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
> 
> ______________________________________________
> 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
> 
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list