Rcpp NumericMatrix - how to erase a row / column?

后端 未结 2 1861
名媛妹妹
名媛妹妹 2020-12-17 21:40

A novice question as I learn the Rcpp classes / data structures: Is there a member function to erase a row / column for an object of class Rcpp::NumericMatrix?

2条回答
  •  感情败类
    2020-12-17 22:10

    How about using RcppArmadillo? I think the intention of the code would be much clearer...

    #include 
    // [[Rcpp::depends(RcppArmadillo)]]
    
    using namespace arma;
    
    // [[Rcpp::export]]
    mat sub1( mat x, uword e) {
      x.shed_col(e-1);
      x.shed_row(e-1);
      return x;
    }
    
    /*** R
    sub1( matrix(1:9,3), 2 )
    */
    

    > sub1( matrix(1:9,3), 2 )
         [,1] [,2]
    [1,]    1    7
    [2,]    3    9
    

提交回复
热议问题