R has both NaN
and NA
(which is really a special kind of NaN
) for representing missing values. This is important to know because there are many functions that check if a value is NaN
-y (NA
or NaN
):
Some truth tables for functions from the R/C API (note the frustrating lack of consistency)
+---------------------+
| Function | NaN | NA |
+---------------------+
| ISNAN | t | t |
| R_IsNaN | t | f |
| ISNA | f | t |
| R_IsNA | f | t |
+---------------------+
and Rcpp:
+-------------------------+
| Function | NaN | NA |
+-------------------------+
| Rcpp::is_na | t | t |
| Rcpp::is_nan | t | f |
+-------------------------+
and from the R interpreter (note: Rcpp tries to match this, rather than the R/C API):
+---------------------+
| Function | NaN | NA |
+---------------------+
| is.na | t | t |
| is.nan | t | f |
+---------------------+
Unfortunately it's a confusing landscape, but this should empower you a bit.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…