mode2: Statistical Mode of a Numeric Vector

Description Usage Arguments Value See Also Examples

View source: R/quest_functions.R

Description

mode2 calculates the statistical mode - a measure of central tendancy - of a numeric vector. This is in contrast to mode in base R, which returns the storage mode of an object. In the case multiple modes exist, the multiple argument allows the user to specify if they want the multiple modes returned or just one.

Usage

1
mode2(x, na.rm = FALSE, multiple = FALSE)

Arguments

x

atomic vector

na.rm

logical vector of length 1 specifying if missing values should be removed from x before calculating its frequencies.

multiple

logical vector of length 1 specifying if multiple modes should be returned in the case they exist. If multiple modes exist and multiple = TRUE, the multiple modes will be returned in alphanumeric order. If multiple modes exist and multiple = TRUE, the first mode in alphanumeric order will be returned. Note, NA is always last in the alphanumeric order. If only one mode exists, then the multiple argument is not used.

Value

atomic vector of the same storage mode as x providing the statistical mode(s).

See Also

freq table

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
# ONE MODE
vec <- c(7,8,9,7,8,9,9)
mode2(vec)
mode2(vec, multiple = TRUE)

# TWO MODES
vec <- c(7,8,9,7,8,9,8,9)
mode2(vec)
mode2(vec, multiple = TRUE)

# WITH NA
vec <- c(7,8,9,7,8,9,NA,9)
mode2(vec)
mode2(vec, na.rm = TRUE)
vec <- c(7,8,9,7,8,9,NA,9,NA,NA)
mode2(vec)
mode2(vec, multiple = TRUE)

quest documentation built on Sept. 10, 2021, 5:07 p.m.

Related to mode2 in quest...