From hb at stat.berkeley.edu  Mon Aug 13 19:45:38 2007
From: hb at stat.berkeley.edu (Henrik Bengtsson)
Date: Mon, 13 Aug 2007 10:45:38 -0700
Subject: [Rd] hasNA() / anyNA()?
Message-ID: <59d7961d0708131045x7feeeab5i4edf107350fbefdb@mail.gmail.com>

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



[Rd] hasNA() / anyNA()?
Henrik Bengtsson