Skip to contents

mode_all() returns the set of all modes in a vector.

Usage

mode_all(x, na.rm = FALSE, na.rm.amount = 0)

Arguments

x

A vector to search for its modes.

na.rm

Logical. Should missing values in x be removed before computation proceeds? Default is FALSE.

na.rm.amount

Numeric. Alternative to na.rm that only removes a specified number of missing values. Default is 0.

Value

A vector with all modes (values tied for most frequent) in x. If the modes can't be determined because of missing values, returns NA instead.

See also

Examples

# Both `3` and `4` are the modes:
mode_all(c(1, 2, 3, 3, 4, 4))
#> [1] 3 4

# Only `8` is:
mode_all(c(8, 8, 9))
#> [1] 8

# Can't determine the modes here --
# `9` might be another mode:
mode_all(c(8, 8, 9, NA))
#> [1] NA

# Either `1` or `2` could be a
# single mode, depending on `NA`:
mode_all(c(1, 1, 2, 2, NA))
#> [1] NA

# `1` is the most frequent value,
# no matter what `NA` stands for:
mode_all(c(1, 1, 1, 2, NA))
#> [1] 1

# Ignore `NA`s with `na.rm = TRUE`
# (there should be good reasons for this!):
mode_all(c(8, 8, 9, NA), na.rm = TRUE)
#> [1] 8
mode_all(c(1, 1, 2, 2, NA), na.rm = TRUE)
#> [1] 1 2