mode: Get the most common value

Description Usage Arguments Value Author(s) Examples

View source: R/helpers.r

Description

Get the most common value

Usage

1
mode(x, na.rm = FALSE, allow_multiple = TRUE)

Arguments

x

Vector.

na.rm

Whether to ignore missing values when calculating the mode. Note that modes may be identified even if x contains missing values as long as they are too few to affect the result.

allow_multiple

Controls what is returned if x contains more than one mode. If TRUE all modes are returned, if FALSE NA is returned.

Value

The most common values or values in x or NA if could not be determined.

Author(s)

Christofer Bäcklin

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
mode(mtcars$cyl)
mode(chickwts$feed)
mode(unlist(strsplit("Hello Dolly!", "")))

# Multiple modes
mode(iris$Species)

# Missing values
x <- rep(1:4, 4)
x[2:4] <- NA
mode(x)
mode(x, na.rm=TRUE)

x <- c(rep(1:3, c(4,2,1)), NA)
mode(x, na.rm=FALSE)

emil documentation built on Aug. 1, 2018, 1:03 a.m.

Related to mode in emil...