stringi (version 1.8.3)

stri_rank: Ranking

Description

This function ranks each string in a character vector according to a locale-dependent lexicographic order. It is a portable replacement for the base xtfrm function.

Usage

stri_rank(str, ..., opts_collator = NULL)

Value

The result is a vector of ranks corresponding to each string in str.

Arguments

str

a character vector

...

additional settings for opts_collator

opts_collator

a named list with ICU Collator's options, see stri_opts_collator, NULL for default collation options

Author

Marek Gagolewski and other contributors

Details

Missing values result in missing ranks and tied observations receive the same ranks (based on min).

For more information on ICU's Collator and how to tune it up in stringi, refer to stri_opts_collator.

References

Collation -- ICU User Guide, https://unicode-org.github.io/icu/userguide/collation/

See Also

The official online manual of stringi at https://stringi.gagolewski.com/

Gagolewski M., stringi: Fast and portable character string processing in R, Journal of Statistical Software 103(2), 2022, 1-59, tools:::Rd_expr_doi("10.18637/jss.v103.i02")

Other locale_sensitive: %s<%(), about_locale, about_search_boundaries, about_search_coll, stri_compare(), stri_count_boundaries(), stri_duplicated(), stri_enc_detect2(), stri_extract_all_boundaries(), stri_locate_all_boundaries(), stri_opts_collator(), stri_order(), stri_sort_key(), stri_sort(), stri_split_boundaries(), stri_trans_tolower(), stri_unique(), stri_wrap()

Examples

Run this code
stri_rank(c('hladny', 'chladny'), locale='pl_PL')
stri_rank(c('hladny', 'chladny'), locale='sk_SK')

stri_rank("a" %s+% c(1, 100, 2, 101, 11, 10))  # lexicographic order
stri_rank("a" %s+% c(1, 100, 2, 101, 11, 10), numeric=TRUE)  # OK
stri_rank("a" %s+% c(0.25, 0.5, 1, -1, -2, -3), numeric=TRUE)  # incorrect

# Ordering a data frame with respect to two criteria:
X <- data.frame(a=c("b", NA, "b", "b", NA, "a", "a", "c"), b=runif(8))
X[order(stri_rank(X$a), X$b), ]

Run the code above in your browser using DataLab