Here is a more complete example. Note that I want to output text strings for debugging purposes as the code for treatAsVector = true is never executed.
Barth NumericVector getValidCount(Rcpp::NumericMatrix m, bool treatAsVector) { Rcpp::Rcout << "getValidCount BEGINS" << std::endl; int N = m.cols(); NumericVector u, vec; NumericVector count (N); if(!treatAsVector) { Rcpp::Rcout << "Treating as matrix" << std::endl; for(int i = 0; i < N; i++) { vec = m(_,i); vec = vec[!Rcpp::is_na(vec)]; u = Rcpp::unique(vec); count[i] = u.length(); } } else { Rcpp::Rcout << "treating as vector" << std::endl; vec = as<NumericVector>(m); vec = vec[!Rcpp::is_na(vec)]; u = Rcpp::unique(vec); count.fill(u.length()); } return count; }
_______________________________________________ Rcpp-devel mailing list Rcpp-devel@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel