I have a list of matrix and some of them are NA, like the following:
listToCheck <- list(NA, matrix(0,nrow = 2, ncol = 2))
and I would like to write a code in Rcpp to check if any element of the list is NA or not.
I tried the two following,
// [[Rcpp::depends(RcppArmadillo)]]
#include <RcppArmadillo.h>
using namespace Rcpp;
// [[Rcpp::export]]
bool checkNa(int i, List elemInCluster){
arma::mat matrix = elemInCluster[i];
if(R_IsNA(matrix(0,0))){
return true;
}
return false;
}
but it doesn't work as when I try checkNa(0, listToCheck)
it gives Error in checkNa(0, listToCheck) : Not a matrix.
as I try to access the first element even when the matrix is NA.
As R_IsNA works on double, is there any way to check that the matrix is NA without having to access one of its elements?