Call mode_frequency() to get the number of times that a
vector's mode appears in the vector.
See mode_frequency_range() for bounds on an unknown frequency.
Arguments
- x
A vector to check for its modal frequency.
- na.rm
Logical. Should missing values in
xbe removed before computation proceeds? Default isFALSE.- max_unique
Numeric or string. If the maximum number of unique values in
xis known, setmax_uniqueto that number. This rules out thatNAs represent values beyond that number (see examples). Set it to"known"instead if no values beyond those already known can occur. Default isNULL, which assumes no maximum.
Details
By default (na.rm = FALSE), the function returns NA if any
values are missing. That is because missings make the frequency uncertain
even if the mode is known: any missing value may or may not be the mode,
and hence count towards the modal frequency.
See also
mode_first(), which the function wraps.
Examples
# The mode, `9`, appears three times:
mode_frequency(c(7, 8, 8, 9, 9, 9))
#> [1] 3
# With missing values, the frequency
# is unknown, even if the mode isn't:
mode_frequency(c(1, 1, NA))
#> [1] NA
# You can ignore this problem and
# determine the frequency among known values
# (there should be good reasons for this!):
mode_frequency(c(1, 1, NA), na.rm = TRUE)
#> [1] 2