RE: [R] or of a logical vector

2004-08-05 Thread Thomas Lumley
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 __

RE: [R] or of a logical vector

2004-08-05 Thread Thomas Lumley
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 _

RE: [R] or of a logical vector

2004-08-05 Thread Liaw, Andy
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__ --

Re: [R] or of a logical vector

2004-08-05 Thread 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__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of C

RE: [R] or of a logical vector

2004-08-05 Thread Ted Harding
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) >

RE: [R] or of a logical vector

2004-08-05 Thread Baskin, Robert
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, "|")

Re: [R] or of a logical vector

2004-08-05 Thread Prof Brian Ripley
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

RE: [R] or of a logical vector

2004-08-05 Thread Liaw, Andy
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

Re: [R] or of a logical vector

2004-08-05 Thread Gabor Grothendieck
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

Re: [R] or of a logical vector

2004-08-05 Thread Spencer Graves
?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

Re: [R] or of a logical vector

2004-08-05 Thread Eric Lecoutre
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