1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <Rcpp.h> using namespace Rcpp; // [[Rcpp::export]] IntegerVector which_are_num(NumericVector x, double a) { int nx = x.size(); std::vector<int> y; y.reserve(nx); for(int i = 0; i < nx; i++) { if (x[i] == a) y.push_back(i+1); } return wrap(y); } // [[Rcpp::export]] IntegerVector which_are_char(CharacterVector x, String a) { int nx = x.size(); std::vector<int> y; y.reserve(nx); for(int i = 0; i < nx; i++) { if (x[i] == a) y.push_back(i+1); } return wrap(y); } |