I want to convert a list e.g like this:
[[1]]
[1] 3 4 99 1 222
[[2]]
[1] 1 2 3 4 5
to a matrix (2,5) in Rcpp. What is the fastest way to do this?
Function wrap() is not working in this case.
First of of I have tried to convert a list to a vector and later to a matrix.Using wrap() in a function:
#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)))
*/
I receive a bug:
> 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