Mode in R (Example)

In this tutorial you’ll learn how to compute the mode of a numeric vector in the R programming language.

Example Data

In this example, we’ll compute the mode of the following numeric vector:

x <- c(6, 8, 4, 3, 9, 1, 3, 5, 2)    # Create example vector

Example: Calculate Mode in R

The basic installation of the R programming language does not provide a function for the computation of the mode. For that reason, we need to install and load the DescTools package first:

install.packages("DescTools")        # Install DescTools package
library("DescTools")                 # Load DescTools package

Now, we can use the Mode function of the DescTools package as follows:

Mode(x)                              # Compute mode
# 3

The mode of our example vector is 3.

Leave a Reply

Your email address will not be published.

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu
Top