Compares strings by tokenising them, sorting the tokens alphabetically and then computing the lev_ratio() of the result. This means that the order of words is irrelevant which can be helpful in some circumstances.

lev_token_sort_ratio(a, b, pairwise = TRUE, useNames = TRUE, ...)



The input strings


The input strings


Boolean. If TRUE, only the pairwise distances between a and b will be computed, rather than the combinations of all elements.


Boolean. Use input vectors as row and column names?


Additional arguments to be passed to stringdist::stringdistmatrix() or stringdist::stringsimmatrix().


A numeric scalar, vector or matrix depending on the length of the inputs.

See also


x <- "Episode IV - Star Wars: A New Hope"
y <- "Star Wars Episode IV - New Hope"

# Because the order of words is different the simple approach gives a low match ratio.
lev_ratio(x, y)
#> [1] 0.3529412

# The sorted token approach ignores word order.
lev_token_sort_ratio(x, y)
#> [1] 0.9354839