stat_mode | R Documentation |
Computes the statistical mode of a set of values. The mode is defined as the most frequent value, i.e. the value that is most likely to be sampled.
stat_mode(x, type = c("one", "all", "n"), rm_na = FALSE)
x |
An R object. |
type |
What the function should calculate.
|
rm_na |
Ignore missing values in |
If type = "n"
, the number of modes in x
(an integer). Otherwise, the mode(s) of x
or NA
if none exist(s) (same type as x
).
The package modeest for more powerful mode estimation functions.
Other statistical computing / numeric functions:
round_to()
,
safe_max()
,
safe_min()
,
safe_seq_len()
pal::stat_mode(c(rep(3L, times = 3), 1:9))
pal::stat_mode(c(1.5, 4, 9.9))
# if no mode exists, `NA` (of the same type as x) is returned
pal::stat_mode(letters)
pal::stat_mode(c(letters, "a"))
# if multiple modes exist, `NA` is returned by default
pal::stat_mode(c(letters, "a", "b"))
# set `type = "all"` to return all modes instead
pal::stat_mode(c(letters, "a", "b"),
type = "all")
# `NA` is treated as any other value by default
pal::stat_mode(c(letters, "a", NA_character_, NA_character_),
type = "all")
# set `rm_na = TRUE` to ignore `NA` values
pal::stat_mode(c(letters, "a", NA_character_, NA_character_),
type = "all",
rm_na = TRUE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.