On Thu, 5 Aug 2004 [EMAIL PROTECTED] wrote:
> But you can also do these with 'any' and 'all', e.g.
>
> any(v==TRUE)
>
or any( (v==TRUE)==TRUE), or any( ((v==TRUE)==TRUE)==TRUE)...
Or, perhaps, any(v).
Lewis Carroll wrote a nice piece on this theme.
-thomas
__
On Thu, 5 Aug 2004, Liaw, Andy wrote:
> Is there anything wrong with sum(v) > 0?
>
any(v) has the advantage of having the same NA handling as Ben's function,
so that any(v) is TRUE if there is at least one TRUE and any number of NAs
and is NA if there are NAs and no TRUEs.
-thomas
_
Yes, of course:
> x <- c(TRUE, NA)
> any(x)
[1] TRUE
> sum(x) > 0
[1] NA
Andy
> From: Peter Dalgaard
>
> "Liaw, Andy" <[EMAIL PROTECTED]> writes:
>
> > Is there anything wrong with sum(v) > 0?
>
> Yes, there is an any()-thing ;-)
>
> (And NA handling differs too.)
>
> --
>O__ --
"Liaw, Andy" <[EMAIL PROTECTED]> writes:
> Is there anything wrong with sum(v) > 0?
Yes, there is an any()-thing ;-)
(And NA handling differs too.)
--
O__ Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of C
On 05-Aug-04 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) >
I don't know how careful about coercing type you need to be.
Something like TRUE %in% outer(v,v,"|") may work for you but simpler
functions that do arithmetic and coerce the answer back to logical [e.g.,
as.logical(max(v))] might suffice.
> xt <- c(T,T,T)
> xf <- c(T,F,F)
> outer(xt, xf, "|")
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 vec
Is there anything wrong with sum(v) > 0?
Andy
> From: Ben Wittner
>
> 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 <- funct
Ben Wittner jimmy.harvard.edu> writes:
: Is there some fast (built-in?) way to get the OR of all the elements in a
: logical vector?
Here are two possibilities:
max(x) == 1
sum(x) > 0
These use the fact that logicals used in arithmetic operations
are converted such that TRUE becomes 1 and FALS
?any
hope this helps. spencer graves
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)
f
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
11 matches
Mail list logo