Skip to content

Instantly share code, notes, and snippets.

@hadley
Created November 15, 2012 16:55
Show Gist options
  • Select an option

  • Save hadley/4079744 to your computer and use it in GitHub Desktop.

Select an option

Save hadley/4079744 to your computer and use it in GitHub Desktop.
cppFunction('
#include <algorithm>
IntegerVector findInterval2(NumericVector x, NumericVector breaks) {
IntegerVector out(x.size());
NumericVector::iterator it, pos;
IntegerVector::iterator out_it;
for(it = x.begin(), out_it = out.begin(); it != x.end(); it++, out_it++) {
pos = std::upper_bound(breaks.begin(), breaks.end(), *it);
*out_it = std::distance(pos, breaks.begin());
}
return(out);
}
')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment