Mode | R Documentation |
There is no built-in function to find the mode of something. This function can find the mode of a numeric, character, or factor vector. By default it will return multiple values in a multi-modal dataset, but there are several methods of tie-breaking included.
Mode(x, break_ties = "no", na.rm = FALSE, ties = NULL, mean = NULL)
x |
(Char/Numeric/Factor) A vector. |
break_ties |
(Character) If more than one mode is found, how should the tie be broken?
|
na.rm |
(Logical) If |
ties |
Deprecated (2019-02-26). Use |
mean |
Deprecated (2019-02-26). Use |
If all values are unique, it will return all of the values unless you choose to break the tie.
A vector of the mode value(s).
Ken Williams (https://stackoverflow.com/users/169947/ken-williams)
jprockbelly (https://stackoverflow.com/users/1502898/jprockbelly)
Desi Quintans (http://www.desiquintans.com)
https://stackoverflow.com/a/8189441/5578429
vec <- c(1, 2, 3, 4, 4, 4, 3, 3, NA, NA, NA)
Mode(vec, break_ties = "no")
#> [1] 3 4 NA
Mode(vec, break_ties = "no", na.rm = TRUE)
#> [1] 3 4
Mode(vec, break_ties = "mean", na.rm = FALSE)
#> [1] NA
Mode(vec, break_ties = "mean", na.rm = TRUE)
#> [1] 3.5
Mode(vec, break_ties = "median", na.rm = TRUE)
#> [1] 3
Mode(letters[1:4], break_ties = "no")
#> [1] "a" "b" "c" "d"
Mode(letters[1:4], break_ties = "median l")
#> "b"
Mode(letters[1:4], break_ties = "median r")
#> "c"
Mode(letters[1:4], break_ties = "random")
#> [1] "a"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.