Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

stats::modal

Modal (most frequent) value(s) in a data sample

MuPAD® notebooks are not recommended. Use MATLAB® live scripts instead.

MATLAB live scripts support most MuPAD functionality, though there are some differences. For more information, see Convert MuPAD Notebooks to MATLAB Live Scripts.

Syntax

stats::modal(x1, x2, …)
stats::modal([x1, x2, …])
stats::modal(s, <c>)

Description

stats::modal(x1, x2, …) returns the most frequent value(s) of the data xi.

The column index c is optional, if the data are given by a stats::sample object containing only one non-string column. Cf. Example 3.

External statistical data stored in an ASCII file can be imported into a MuPAD® session via import::readdata. In particular, see Example 1 of the corresponding help page.

Examples

We calculate the modal value of a data sequence:

stats::modal(2, a, b, c, b, 10, 12, 2, b)

Alternatively, data may be passed as a list:

stats::modal([a, a, a, b, c, b, 10, 12, 2, b])

We create a sample containing "age" and "gender":

stats::sample([[32, "f"], [25, "m"], [40, "f"], [23, "f"]])
32  "f"
25  "m"
40  "f"
23  "f"

The modal value of the second column (the most frequent "gender") is calculated:

stats::modal(%, 2)

We create a sample consisting of only one column:

stats::sample([4, 6, 2, 6, 8, 3, 2, 1, 7, 9, 3, 6, 5, 1, 6, 8]):

The modal value of these data is calculated. In this case, the column does not have to be specified, since there is only one column:

stats::modal(%)

Parameters

x1, x2, …

The statistical data: arithmetical expressions.

s

A sample of domain type stats::sample.

c

An integer representing a column index of the sample s. This column provides the data x1, x2 etc.

Return Values

Sequence consisting of a list and an integer. The list contains the most frequent element(s) in the data, the integer specifies the number of occurrences. E.g., the result [x5, x10], 21 means that x5 and x10 are the most frequent data items, each occurring 21 times.

Was this topic helpful?