Skip to contents

mode_frequency_range() determines the minimum and maximum number of times that a vector's mode appears in the vector. The minimum assumes that no NAs are the mode; the maximum assumes that all NAs are.

Usage

mode_frequency_range(x, max_unique = NULL)

Arguments

x

A vector to check for its modal frequency.

max_unique

Numeric or string. If the maximum number of unique values in x is known, set max_unique to that number. This rules out that NAs represent values beyond that number (see examples). Set it to "known" instead if no values beyond those already known can occur. Default is NULL, which assumes no maximum.

Value

Integer (length 2).

Details

If there are no NAs in x, the two return values are identical. If all x values are NA, the return values are 1 (no two x values are the same) and the total number of values (all x values are the same).

See also

mode_frequency(), for the precise frequency (or NA if it can't be determined).

Examples

# The mode is `7`. It appears four or
# five times because the `NA` might
# also be a `7`:
mode_frequency_range(c(7, 7, 7, 7, 8, 8, NA))
#> [1] 4 5

# All of `"c"`, `"d"`, and `"e"` are the modes,
# and each of them appears twice:
mode_frequency_range(c("a", "b", "c", "c", "d", "d", "e", "e"))
#> [1] 2 2