Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

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)

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

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.

Value

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

References

Collation - ICU User Guide, http://userguide.icu-project.org/collation

See Also

Examples

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)

# 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), ]

stringi

Character String Processing Facilities

v1.6.1
file LICENSE
Authors
Marek Gagolewski [aut, cre, cph] (<https://orcid.org/0000-0003-0637-6028>), Bartek Tartanus [ctb], and others (stringi source code); IBM, Unicode, Inc. and others (ICU4C source code, Unicode Character Database)
Initial release
2021-05-05

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.