stats::modal

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

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

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

Example 1

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])

Example 2

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)

Example 3

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?