【发布时间】:2012-10-04 01:56:25
【问题描述】:
我在 R 中有一个列表 x
我不确定如何处理 Rcpp 中的列表。我收到一条错误消息,有人可以检查我的代码吗?
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)
【问题讨论】: