I'm trying to implement (in R is too slow) a for loop in C++ (Rcpp
) and I need to filer a dataframe
according to the id
column and get the whole row(s) for later processing by I keep getting this error:
use of overloaded operator '[]' is ambiguous (with operand types 'NameProxy' (aka 'generic-name_proxy<19>') and 'int')
The problem is I've not been able to find any example on how to do it. What I saw is that people break the dataframe down to vectors but in my case the number of columns can vary. Below my code: (the r loop can be seen in this question 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);
}