Skip to content

Instantly share code, notes, and snippets.

@chrisgilmerproj
Created December 5, 2011 22:40
Show Gist options
  • Save chrisgilmerproj/1435738 to your computer and use it in GitHub Desktop.
Save chrisgilmerproj/1435738 to your computer and use it in GitHub Desktop.
Simple mode code
float mode(float *data_array){
int c_new, c_old = 0, 0;
float mode_new, mode_old = 0.0, 0.0;
int i;
for(i = 0; i < len(data_array); i++){
float num = data_array[i]
if (num != mode_new) {
if (c_new > c_old) {
c_old = c_new;
mode_old = mode_new;
c_new = 0;
}
mode_new = num;
}
c_new++;
}
return mode_old;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment