I am learning Rcpp from Hadley Wickham's Advance R: http://adv-r.had.co.nz/Rcpp.html.
There is one exercise to implement R function unique() in Rcpp using an unordered_set (challenge: do it in one line!). The solution finds the unique numbers in a numeric vector. I am trying to find the unique characters in a character vector using the second code chunk, which produces an error. Any idea on how to achieve this simple function manually ? Thanks!
// [[Rcpp::export]]
std::unordered_set<double> uniqueCC(NumericVector x) {
return std::unordered_set<double>(x.begin(), x.end());
}
// [[Rcpp::export]]
std::unordered_set<String> uniqueCC(CharacterVector x) {
return std::unordered_set<String>(x.begin(), x.end());
}