R Select Most Frequent Values from Vector or Column (Example Code)

In this article, I’ll illustrate how to select the most frequent elements of a vector or data frame variable in R programming.

Example Data

x <- c(1, 4, 3, 5, 7, 6, 1, 1, 4, 3, 4)    # Example data
x                                          # Show data in RStudio console
# [1] 1 4 3 5 7 6 1 1 4 3 4

Example: Select Most Common Data Points from Vector Object

sort(table(x), decreasing = TRUE)[1:3]     # Show most common values
# x
# 1 4 3 
# 3 3 2

Related Tutorials

You may find some related R programming tutorials in the list below.

Leave a Reply

Your email address will not be published. Required fields are marked *

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