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

R

R Problem Overview


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.

R Solutions


Solution 1 - R

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionDimitar SlavchevView Question on Stackoverflow
Solution 1 - RJosh O'BrienView Answer on Stackoverflow