Skip to content
Prev 309425 / 398506 Next

"NA-friendly" operator

Instead of ignore-NA versions of ">", "<", "==", etc., I prefer to factor out
the ignore-NA part of things:

   is.true <- function(x) !is.na(x) & x
   is.false <- function(x) !is.na(x) & !x
used as
  >  is.false(c(1,2,NA,4) > 3)
  [1]  TRUE  TRUE FALSE FALSE
  >    is.true(c(1,2,NA,4) > 3)
  [1] FALSE FALSE FALSE  TRUE
or with any other expression that evaluates to a logical.

subset() must have a similar thing buried in it and people use it for that but
then get caught up in its nonstandard evaluation semantics.  which() must
also have it but you don't always want to convert to integer indexes.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com