Finds the most frequent value in an atomic vector. Ties can be handled by returning the first mode, last mode, a random mode, or all modes.
Arguments
- x
Atomic vector, such as numeric, character, logical, or factor.
- na.rm
Logical. If
TRUE, remove missing values before calculation. Defaults toTRUE.- multi
Character string controlling ties. Options are:
"first"Return the first mode in sorted table order.
"last"Return the last mode in sorted table order.
"sample"Return one randomly selected mode.
"all"Return all tied modes.
Value
A value or vector with the same general type as x. Returns NA
for empty inputs or inputs containing only missing values after NA
removal.
Details
For factors, returned mode values preserve the original levels. When
na.rm = FALSE, missing values are included in the frequency table.
See also
table() for frequency tables.