问题
#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);
}
Just want remove some rows from matrix, get error as follows. conversion from 'void' to non-scalar type 'arma::Mat} requested'
回答1:
Two points:
- Please don't post error messages as image. Use Text instead.
- As the error indicates, the
shed_rows()
method does not return anything. Instead it alters the matrix it acts on, c.f. the documentation.
The following works:
#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))
*/
来源:https://stackoverflow.com/questions/52325480/get-error-when-use-rcpp-remove-rows-of-matrix