Identifies rows in a matrix or data frame that contain any (or all) NA values.

has_NA(x, any = TRUE)

Arguments

x

A matrix or data frame.

any

Logical; if TRUE check if any observation in the row is a NA value, else checks if all observations are NA.

Value

A logical vector with values of TRUE for rows with any NA

values (or rows where all values are NA

when any = FALSE).

Examples

x <- matrix(rnorm(9), 3, 3)
x[2, 3] <- NA
has_NA(x)
#> [1] FALSE  TRUE FALSE
x <- data.frame(A = c(1, 2, NA), B = 0)
has_NA(x)
#> [1] FALSE FALSE  TRUE

x <- matrix(rnorm(9), 3, 3)
x[2, ] <- NA
x[3, 1] <- NA
has_NA(x, any = FALSE)
#> [1] FALSE  TRUE FALSE