Fastest way to detect if vector has at least 1 NA?

r na
SFun28 picture SFun28 · Jul 1, 2011 · Viewed 79.6k times · Source

What is the fastest way to detect if a vector has at least 1 NA in R? I've been using:

sum( is.na( data ) ) > 0

But that requires examining each element, coercion, and the sum function.

Answer

Sacha Epskamp picture Sacha Epskamp · Jul 1, 2011

I'm thinking:

any(is.na(data))

should be slightly faster.