我正在尝试在C ++(Rcpp
)中实现(在R中太慢)for循环,我需要根据dataframe
列提交id
并获取由以后处理的整行(我)一直收到此错误:
use of overloaded operator '[]' is ambiguous (with operand types 'NameProxy' (aka 'generic-name_proxy<19>') and 'int')
问题是我找不到任何关于如何做的例子。我看到的是人们将数据帧分解为向量,但在我的情况下,列数可能会有所不同。在我的代码下面:( r循环可以在这个问题中看到R - Replace nested for - Nested lists)
dt = data.table(id = c(1,2,3), A = c('A', 'B', 'C'), B = c('Yesterday', 'Today', 'Tomorrow'))
// [[Rcpp::export]]
Rcpp::List buildFacts(DataFrame dt) {
int rows = dt.nrow();
NumericVector dpid = dt["id"];
for (int idx = 0; idx < rows; idx++) {
int pos = dpid[idx];
//DataFrame time = dt[id == pos]$B // this is where the error comes
DataFrame position = dt["id"][pos]$B;
}
return Rcpp::List::create(Named("result") = 1);
}