Skip to content

Instantly share code, notes, and snippets.

@Ironholds
Created October 7, 2014 20:28
Show Gist options
  • Select an option

  • Save Ironholds/ddbb1756a4457de705ee to your computer and use it in GitHub Desktop.

Select an option

Save Ironholds/ddbb1756a4457de705ee to your computer and use it in GitHub Desktop.
//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