【发布时间】:2020-11-25 03:13:36
【问题描述】:
我有一个矩阵的索引存储在一个列表中,我想访问 Rcpp 中的这些列。
library(Rcpp)
library(RcppArmadillo)
cppFunction('arma::mat tmp(arma::mat mat1, List list1) {
arma::mat mat2=mat1.row(1);
return mat2.cols(as<arma::uvec>(list1[1]));
}',depends = "RcppArmadillo")
但是,上述函数会导致致命错误(“R sessions Aborted”)。例如,
tmp(matrix(1:4,2),list(list(c(0))))
纯 rcpp 中的类似函数会返回此错误。
note: in instantiation of function template specialization 'Rcpp::Vector<19, PreserveStorage>::create<Rcpp::traits::named_object<arma::subview_row<double> >, Rcpp::traits::named_object<arma::subview_elem2<double, arma::Mat<unsigned int>, arma::Mat<unsigned int> > >, Rcpp::traits::named_object<Rcpp::internal::generic_proxy<19, PreserveStorage> > >' requested here
通过documentation,我应该可以通过arma:uvec 访问这些列。
X.cols( vector_of_column_indices )
我不知道为什么它仍然要求我使用这种格式X.cols( first_col, last_col )。
非常感谢任何帮助!
【问题讨论】: