[This article was first published on R – Statistical Odds & Ends, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

In R, a numeric variable is either a number (like 0, 42, or -3.14), or one of 4 special values: `NA`, `NaN`, `Inf` or `-Inf`. It can be hard to remember how the `is.x` functions treat each of the special values, especially `NA` and `NaN`! The table below summarizes how each of these values is treated by different base R functions. Functions are listed in alphabetical order.

FunctionTypical numberNANaNInf-Inf
is.doubleTRUEFALSETRUETRUETRUE
is.finiteTRUEFALSEFALSEFALSEFALSE
is.infiniteFALSEFALSEFALSETRUETRUE
is.integer*1FALSEFALSEFALSEFALSE
is.naFALSETRUETRUEFALSEFALSE
is.nanFALSEFALSETRUEFALSEFALSE
is.nullFALSEFALSEFALSEFALSEFALSE
is.numericTRUE*2TRUETRUETRUE

*1: `is.integer` can return `TRUE` or `FALSE`, depending on whether the number is an integer or not.

*2: R actually has different types of `NA`s (see here for more details). `is.numeric(NA)` returns `FALSE`, but `is.numeric(NA_integer_)` and `is.numeric(NA_real_)` return `TRUE`. Interestingly, `is.numeric(NA_complex_)` returns `FALSE`.