anyNA
Quickly check for missing (NA) values

Description

Discovers if an object contains a missing NA value more quickly than any(is.na()).

Usage

anyNA(x, recursive = FALSE)

Arguments

x An object.
recursive A logical value. If TRUE, checks inside of lists, except those with a class attribute. If FALSE (the default), just checks atomic vectors or the columns of a data.frame for missing values. anyNA never checks the attributes of x.

Details

anyNA is an S3 generic function and methods can be written for it. The default method does not look at any attributes of an object nor more than one level into a recursive object.
For commonly-used classes of objects, this function is equivalent to any(is.na(x)), but it is more efficient because the search is done in compiled C++ code, and it stops looking after finding the first missing value.
Value
returns TRUE if x contains any NA or NaN values; otherwise, it returns FALSE.
See Also
is.na, any.
Examples
anyNA(1:10) # FALSE 
anyNA(c(-3, NA, 16)) # TRUE 
anyNA(data.frame(X=1:5, Y=factor(letters[c(1:3,NA,5)]))) # TRUE
anyNA(data.frame(X=1:5, Y=factor(letters[c(1:3,NA,5)], exclude=NULL))) # FALSE
Package base version 6.0.0-69
Package Index