Created
November 15, 2012 16:55
-
-
Save hadley/4079744 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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