(This article was first published on

**R – Statistical Odds & Ends**, and kindly contributed to R-bloggers)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.

Function | Typical number | NA | NaN | Inf | -Inf |
---|---|---|---|---|---|

is.double | TRUE | FALSE | TRUE | TRUE | TRUE |

is.finite | TRUE | FALSE | FALSE | FALSE | FALSE |

is.infinite | FALSE | FALSE | FALSE | TRUE | TRUE |

is.integer | *1 | FALSE | FALSE | FALSE | FALSE |

is.na | FALSE | TRUE | TRUE | FALSE | FALSE |

is.nan | FALSE | FALSE | TRUE | FALSE | FALSE |

is.null | FALSE | FALSE | FALSE | FALSE | FALSE |

is.numeric | TRUE | *2 | TRUE | TRUE | TRUE |

***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`

.

To

**leave a comment**for the author, please follow the link and comment on their blog:**R – Statistical Odds & Ends**.R-bloggers.com offers

**daily e-mail updates**about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...