mode_all: All modes

View source: R/mode-proper.R

mode_allR Documentation

All modes

Description

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

Usage

mode_all(x, na.rm = FALSE)

Arguments

x

A vector to search for its modes.

na.rm

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

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

  • mode_first() for the first-appearing mode.

  • mode_single() for the only mode, or NA if there are more.

Examples

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

# Only `8` is:
mode_all(c(8, 8, 9))

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

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

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

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

moder documentation built on May 31, 2023, 7:23 p.m.