Order Table by Frequency in R (Example Code)

In this article you’ll learn how to order a table object by frequency in R programming.

Creation of Example Data

example_table <- table(c(1:5, 1:3, 2))                  # Example table in R
example_table                                           # Display example table in RStudio console
# 1 2 3 4 5 
# 2 3 2 1 1

Example: Sorting Table Object Using order() Function

example_table[order(example_table, decreasing = TRUE)]  # Sorting table
# 2 1 3 4 5 
# 3 2 2 1 1

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