Checks if a Value is NA, NaN, or Finite

ISNA(x)

Source

Declaration: src/include/R_ext/Arith.h via src/include/R.h

Implementation: Functions R_IsNA(double x), R_IsNaN(double x), and R_finite(double x) are implemented in src/main/arithmetic.c

Arguments

x

(double) An scalar double.

Value

(integer) 0 ("false") or 1 ("true").

Overview

NaNNA
C API:
ISNAN()truetrue
ISNA()falsetrue
R_IsNaN()truefalse
R_IsNA()falsetrue
R API:
is.na()TRUETRUE
is.nan()TRUEFALSE

C API

 #include <R.h>
 
 int R_IsNA(double);
 int R_IsNaN(double);
 int R_finite(double);
 
 #define ISNA(x)           R_IsNA(x)
 
 #ifdef __cplusplus
   int R_isnancpp(double); /* in arithmetic.c */
 #  define ISNAN(x)     R_isnancpp(x)
 #else
 #  define ISNAN(x)     (isnan(x)!=0)
 #endif
 
 #ifdef HAVE_WORKING_ISFINITE
 /* isfinite is defined in <math.h> according to C99 */
 # define R_FINITE(x)    isfinite(x)
 #else
 # define R_FINITE(x)    R_finite(x)
 #endif

R API

library(base)

x <- c(NA_real_, NaN, 3.14, -Inf, +Inf)
is.na(x)        # c( TRUE,  TRUE, FALSE, FALSE, FALSE)
is.nan(x)       # c(FALSE,  TRUE, FALSE, FALSE, FALSE)
is.finite(x)    # c( TRUE,  TRUE,  TRUE, FALSE, FALSE)
is.infinite(x)  # c(FALSE, FALSE, FALSE,  TRUE,  TRUE)