我想转换一个列表,例如:
[[1]]
[1] 3 4 99 1 222
[[2]]
[1] 1 2 3 4 5
到 Rcpp 中的矩阵 (2,5)。最快的方法是什么?
在这种情况下,函数 wrap() 不起作用。
首先,我尝试将列表转换为向量,然后再转换为矩阵。在函数中使用 wrap():
#include <Rcpp.h>
using namespace Rcpp ;
// [[Rcpp::export]]
NumericVector mat(List a){
NumericVector wynik;
wynik = Rcpp::wrap(a);
return wynik;
}
/***R
mat(list(c(3,4,99,1,222), c(1,2,3,4,5)))
*/
我收到一个错误:
> mat(list(c(3,4,99,1,222), c(1,2,3,4,5)))
Error in eval(substitute(expr), envir, enclos) :
not compatible with requested type