How to sort a data frame by a column in R

· 1 min read · Updated March 13, 2026 · beginner
r sorting dplyr data.table

Sorting a data frame by column is a common task. Here are three ways to do it.

With dplyr

The tidyverse approach uses arrange():

library(dplyr)

sorted <- df %>%
  arrange(desc(salary))

To sort by multiple columns, pass them in order:

df %>%
  arrange(department, desc(salary))

With base R

Base R uses order():

sorted <- df[order(df$salary), ]
sorted_desc <- df[order(-df$salary), ]

For multiple columns, add more expressions to order().

See Also