Computes the statistical mode, i.e. the value that appears most often in a vector. Returns the first match, if TRUE for multiple values.
Arguments
- x
A vector of data values.
- ...
Further arguments, currently unused.
- na.rm
a logical evaluating to
TRUE
orFALSE
indicating whetherNA
values should be stripped before the computation proceeds.
Examples
vector_numeric <- sample(1:5, 15, TRUE)
vector_numeric
#> [1] 4 4 5 4 3 1 2 5 4 2 2 2 3 5 3
stat_mode(vector_numeric)
#> [1] 4
vector_character <- sample(LETTERS[1:5], 15, TRUE)
vector_character
#> [1] "D" "D" "D" "D" "E" "D" "D" "D" "D" "A" "E" "E" "C" "B" "A"
stat_mode(vector_character)
#> [1] "D"