| mfv {statip} | R Documentation |
The function mfv returns the most frequent value(s) (or mode(s))
found in a vector.
The function mfv1 returns the first of these values, so that
mfv1(x) is identical to mfv(x)[[1L]].
mfv(x, na.rm = FALSE, ...) mfv1(x, na.rm = FALSE, ...)
x |
Vector of observations (of type numeric, integer, character, factor, or
logical).
|
na.rm |
logical. If |
... |
Additional arguments (not used). |
See David Smith' blog post
here
to understand the philosophy followed in the code of mfv for missing
values treatment.
The function mfv returns a vector of the same type as x.
One should be aware that this vector can be of length > 1, in case of
multiple modes.
mfv1 always returns a vector of length 1
(the first of the modes found).
mfv calls the function tabulate.
Dutta S. and Goswami A. (2010). Mode estimation for discrete distributions. Mathematical Methods of Statistics, 19(4):374–384.
# Basic examples:
mfv(c(3, 3, 3, 2, 4)) # 3
mfv(c(TRUE, FALSE, TRUE)) # TRUE
mfv(c("a", "a", "b", "a", "d")) # "a"
mfv(c("a", "a", "b", "b", "d")) # c("a", "b")
mfv1(c("a", "a", "b", "b", "d")) # "a"
# With missing values:
mfv(c(3, 3, 3, 2, NA)) # 3
mfv(c(3, 3, 2, NA)) # NA
mfv(c(3, 3, 2, NA), na.rm = TRUE)# 3
# With only missing values:
mfv(c(NA, NA)) # NA
mfv(c(NA, NA), na.rm = TRUE) # NaN