Learn R Programming

emil (version 2.2.3)

mode: Get the most common value

Description

Get the most common value

Usage

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

Arguments

Value

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

Examples

Run this code
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