Rcpp function check if missing value

前端 未结 3 958
鱼传尺愫
鱼传尺愫 2020-12-03 00:24

I\'m converting R based code into Rcpp based code. The head of my function is:

NumericMatrix createMatrixOfLinkRatiosC(NumericMatrix matr, double threshold4C         


        
3条回答
  •  青春惊慌失措
    2020-12-03 00:34

    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.

提交回复
热议问题