Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save knapply/39b35d6e6efd574816395a57d7cecaa8 to your computer and use it in GitHub Desktop.
Save knapply/39b35d6e6efd574816395a57d7cecaa8 to your computer and use it in GitHub Desktop.
Length from scratch (ish)
#include <Rcpp.h>
using namespace Rcpp;
// [[Rcpp::export]]
int cpp_length(NumericVector x) {
int out = 0;
for (NumericVector::iterator iter = x.begin(); iter != x.end(); iter++) {
out++;
}
return out;
}
/*** R
cpp_length(1:20)
#> [1] 20
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment