x <- c("apple", "car", "happy", "char")
str_sort(x)
str_order(x)
x[str_order(x)]
str_rank(x)
# In Czech, ch is a digraph that sorts after h
str_sort(x, locale = "cs")
# Use numeric = TRUE to sort numbers in strings
x <- c("100a10", "100a5", "2b", "2a")
str_sort(x)
str_sort(x, numeric = TRUE)
Run the code above in your browser using DataLab