在Rcpp中过滤(子集化)数据帧

时间:2018-04-03 09:49:25

标签: c++ r rcpp

我正在尝试在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);
}

0 个答案:

没有答案
相关问题