There is a way to initialize Numeric vector with NA values like.
NumericVector x(10,NumericVector::get_na())
is there any similar way to initialize a matrix to NA values?
Here is a version that does not waste memory.
#include <Rcpp.h>
using namespace Rcpp ;
// [[Rcpp::export]]
NumericMatrix na_matrix(int n){
NumericMatrix m(n,n) ;
std::fill( m.begin(), m.end(), NumericVector::get_na() ) ;
return m ;
}
FWIW, in Rcpp11
, you can use some more expressive syntax:
NumericMatrix m(n,n, NA) ;
Thanks to this constructor
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With