使用Rcpp我试图在传递给 C++(类)NA
的向量中进行测试。似乎该功能适用于, ... 但不适用于.POSIXct
DatetimeVector
Rcpp::is_na(.)
NumericVector
CharcterVector
DatetimeVector
这是C++
测试但如果添加则无法编译NA
的代码NumericVector
CharacterVector
DatetimeVector
#include <Rcpp.h>
using namespace std;
using namespace Rcpp;
//[[Rcpp::export]]
List testNA(DataFrame df){
const int N = df.nrows();
//Test for NA in an IntegerVector
IntegerVector intV = df["intV"];
LogicalVector resInt = is_na(intV);
//Test for NA in an CharacterVector
CharacterVector strV = df["strV"];
LogicalVector resStr = is_na(strV);
//Test for NA in an DatetimeVector
DatetimeVector dtV = df["dtV"];
LogicalVector resDT;
//resDT = is_na(dtV); UNCOMMENT => DOES NOT COMPILE
return(List::create(_["df"]=df,
_["resInt"]=resInt,
_["resStr"]=resStr,
_["resDT"]=resDT));
}
/*** R
cat("testing for NA\n")
intV <- c(1,NA,2)
df <- data.frame(intV=intV, strV=as.character(intV), dtV=as.POSIXct(intV,origin='1970-01-01'))
str(df)
testNA(df)
*/
在 R 中
library("Rcpp")
sourceCpp("theCodeAbove.cpp")