使用Rcpp删除矩阵行时获取错误

Xia*_*ong 0 r armadillo rcpp

#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
// [[Rcpp::export]]
arma::mat fed(arma::mat x){
arma::mat zz=x.shed_rows(0,2);
return(zz);
}
Run Code Online (Sandbox Code Playgroud)

只想从矩阵中删除一些行,得到如下错误.从'void'转换为非标量类型'arma :: Mat}''

Ral*_*ner 5

两点:

  • 请不要将错误消息发布为图像.请改用文字.
  • 如错误所示,该shed_rows()方法不返回任何内容.相反,它改变了它所作用的矩阵,参见文档.

以下作品:

#include <RcppArmadillo.h>
// [[Rcpp::depends(RcppArmadillo)]]
using namespace Rcpp;
// [[Rcpp::export]]
arma::mat fed(arma::mat x){
    x.shed_rows(0,2);
    return(x);
}

/*** R
fed(matrix(1:16, 4 ,4))
*/
Run Code Online (Sandbox Code Playgroud)