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.
x1, x2, …) stats::modal(
[x1, x2, …]) stats::modal(
…) returns the most frequent value(s)
of the data xi.
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:
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:
The statistical data: arithmetical expressions.
A sample of domain type
An integer representing a column index of the sample
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
x10 are the most
frequent data items, each occurring 21 times.