Finds the most common value in an array.

View versions (1)

Interface

#include <codecogs/statistics/moments/mode.h>

using namespace Statistics::Moments;

This function calculates the most common value in an array of data. Like Median, mode is a location measure.

Example:

#include<iostream>
#include <codecogs/statistics/moments/mode.h>
int main()
{
  double x[11]={4, 4, 5, 5, 5, 8, 8, 8, 8, 9, 9},
  res=Stats::Moments::mode(11, x);
  std::cout<<"The mode of the x array is:"<<res<<std::endl;
  return 0;
}

Output:

The mode of the x array is: 8

Parameters

n
the size of the array
data
the actual array of data

Returns

the most common value in the given array of data
GPL Licence — free for non commercial use. See Licence details.