Last active
November 5, 2018 23:25
-
-
Save knapply/39b35d6e6efd574816395a57d7cecaa8 to your computer and use it in GitHub Desktop.
Length from scratch (ish)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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