Jak obsługiwać listę w R na Rcpp
Mam listę w R, która x <-list (c (1,2,3), c (4,5), c (5,5), c (6)). Chcę wprowadzić listę do Rcpp i zwrócić je jako średni wektor, c (2, 4.5, 5, 6).
Nie wiem, jak poradzić sobie z listą w Rcpp. Mam komunikat o błędzie, więc czy ktoś może sprawdzić mój kod?
library(inline)
fx = cxxfunction(signature(x='List'), body =
'
Rcpp::List xlist(x);
int n = xlist.size();
double res[n];
for(int i=0; i<n; i++) {
Rcpp NumericVector y(xlist[i]);
int m=y.size();
res[i]=0;
for(int j=0; j<m; j++){
res[i]=res[i]+y[j]
}
}
return(wrap(res));
'
, plugin='Rcpp')
x<-list(c(1,2,3), c(4,5), c(5,5), c(6))
fx(x)