To sort a string vector in dictionary order in R, you can use the sort
function.
In this example,
vec
with some string values.sort
function to sort the elements of the vector in ascending order. By default, the sort
function sorts elements in dictionary order.sorted_vec
.vec <- c("banana", "apple", "orange", "grape")
sorted_vec <- sort(vec)
print(sorted_vec)
[1] "apple" "banana" "grape" "orange"
In this tutorial, we learned How to Sort a String Vector in Dictionary Order in R language with well detailed examples.