mode_first {moder} | R Documentation |
The first-appearing mode
Description
mode_first()
returns the mode that appears first in a vector, i.e., before
any other modes.
Usage
mode_first(x, na.rm = FALSE, accept = FALSE)
Arguments
x |
A vector to search for its first mode. |
na.rm |
Boolean. Should missing values in |
accept |
Boolean. Should the first-appearing value known to be a mode be
accepted? If |
Value
The first mode (most frequent value) in x
. If it can't be
determined because of missing values, returns NA
instead.
See Also
-
mode_all()
for the full set of modes. -
mode_single()
for the only mode, orNA
if there are more.
Examples
# `2` is most frequent:
mode_first(c(1, 2, 2, 2, 3))
# Can't determine the first mode --
# it might be `1` or `2` depending
# on the true value behind `NA:
mode_first(c(1, 1, 2, 2, NA))
# Ignore `NA`s with `na.rm = TRUE`
# (there should be good reasons for this!):
mode_first(c(1, 1, 2, 2, NA), na.rm = TRUE)
# `1` is the most frequent value,
# no matter what `NA` stands for:
mode_first(c(1, 1, 1, 2, NA))
# By default, the function insists on
# the first mode, so it won't accept the
# first value *known* to be a mode if an
# earlier value might be a mode, too:
mode_first(c(1, 2, 2, NA))
# You may accept the first-known mode:
mode_first(c(1, 2, 2, NA), accept = TRUE)
[Package moder version 0.2.1 Index]