Learn R Programming

emil (version 2.2.10)

mode: Get the most common value

Description

Get the most common value

Usage

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.

Examples

Run this code
# NOT RUN {
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)
# }

Run the code above in your browser using DataLab