Created
October 7, 2014 20:28
-
-
Save Ironholds/ddbb1756a4457de705ee 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
| //Includes/namespaces | |
| #include <Rcpp.h> | |
| using namespace Rcpp; | |
| // Recursive session counting function | |
| // [[Rcpp::export]] | |
| int session_count(NumericVector x, int local_minimum) { | |
| //Create output object | |
| int count; | |
| //If there's only one value in x (perfectly possible - this is designed to be recursive) return as such | |
| if(x.size() == 1){ | |
| count = 1; | |
| return count; | |
| } | |
| //Otherwise, loop | |
| for(int i = 0; i < x.size(); ++i) { | |
| //If the value is greater than the local minimum | |
| if(x[i] > local_minimum){ | |
| //Increment the count | |
| count += 1; | |
| } | |
| } | |
| //Return | |
| return count; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment