sort

sort allows you to arrange (or partially arrange) a vector into ascending or descending order.

Examples

Given a vector, arrange it in a ascending order.

Click to see solution
x <- c(1,3,2,10,4)
sort(x)
[1]  1  2  3  4 10

Given a vector, arrange it in a descending order.

Click to see solution
x <- c(1,3,2,10,4)
sort(x, decreasing = TRUE)
[1] 10  4  3  2  1

Given a character vector, arrange it in ascending order.

Click to see solution
sort(c("waffle", "pancake", "eggs", "bacon"))
[1] "bacon"   "eggs"    "pancake" "waffle"