R – How to check if entire vector has no values other than NA (or NAN) in R

r

How to check if entire vector has no values other than NA (or NAN) in R ?

If I use is.na it returns a vector of TRUE / FALSE.

I need to check if there is single not NA element or not.

Best Solution

The function all(), when passed a Boolean vector, will tell you whether all of the values in it are TRUE:

> all(is.na(c(NA, NaN)))
[1] TRUE
> all(is.na(c(NA, NaN, 1)))
[1] FALSE
Related Question