# modec¶

## Purpose¶

Computes the mode of every column of a matrix.

## Format¶

m = modec(x)
Parameters: x (NxK matrix) – data m (Kx1 matrix) – contains the mode of every column of x.

## Examples¶

### Basic example¶

// Create a 5x1 column vector
x = { 3,
4,
4,
3,
3 };

// Compute the mode of this column
m = modec(x);


After the code above, m is equal to:

3


### Multi-column mode from credit dataset¶

This example will load the variables, Cards, Age and Education from the dataset credit.dat and find the mode of each variable.

// Create the file name with full path
fname = getGAUSSHome() \$+ "examples/credit.dat";

// Load three variables by name
X = loadd(fname, "Cards + Age + Education");

// Compute the mode of each of the
// three columns in 'X'
m = modec(X);


After the code above, m will equal:

 2
44
16


Which tells us that for our sample, the most common:

• number of credit cards owned is 2.
• age is 44 years old.
• number of years of education is 16.

## Remarks¶

• If two more more numbers are tied for the most appearances, then modec() will select the smallest of them.

• modec() will not count missing values. However, if a column contains only missing values, a missing value will be returned, indicating that no valid numbers were found.

• To find the mode of the entire matrix, use the vecr() command to turn the matrix into a column vector before calling modec.

m = modec(vecr(x));

• To find out how many times each value is present, use counts().

• To compute the mode for subgroups of a variable, use aggregate().