[Rd] hasNA() / anyNA()?

Henrik Bengtsson hb at stat.berkeley.edu
Mon Aug 13 19:45:38 CEST 2007


Hi,

is there a hasNA() / an anyNA() function in R?  Of course,

hasNA <- function(x) {
  any(is.na(x));
}

would do, but that would scan all elements in 'x' and then do the
test.  I'm looking for a more efficient implementation that returns
TRUE at the first NA, e.g.

hasNA <- function(x) {
  for (kk in seq(along=x)) {
    if (is.na(x[kk]))
      return(TRUE);
  }
  FALSE;
}

Cheers

Henrik



More information about the R-devel mailing list