stri_order: Ordering Permutation and Sorting

Description Usage Arguments Details Value See Also Examples

Description

stri_order determines a permutation which rearranges strings into ascending or descending order. stri_sort sorts the vector according to a lexicographic order.

Usage

1
2
3
stri_order(str, decreasing = FALSE, opts_collator = list())

stri_sort(str, decreasing = FALSE, opts_collator = list())

Arguments

str

character vector

decreasing

single logical value; should the sort order be nondecreasing (FALSE, default) or nonincreasing (TRUE)?

opts_collator

a named list as generated with stri_opts_collator with Collator's options, or NA for dummy Unicode code point comparison

Details

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

Uses a stable sort algorithm (STL's stable_sort); performs up to N*log^2(N) element comparisons, where N is the length of str.

Interestingly, stri_order is most often faster that R's order.

Missing values are always put at the end of a character vector.

stri_sort is a 'black sheep' in stringi: it does not always return UTF-8-encoded strings. Moreover, it preserves many input object's attributes. This is because it is defined as str[stri_order(str, decreasing, opts_collator)].

Value

For stri_order, an integer vector that gives the sort order is returned.

For stri_order, you get a sorted version of str, i.e. a character vector.

See Also

Other locale_sensitive: stri_cmp, stri_compare; stri_count_fixed; stri_detect_fixed; stri_enc_detect2; stri_locate_all_fixed, stri_locate_all_fixed,, stri_locate_first_fixed, stri_locate_first_fixed,, stri_locate_last_fixed, stri_locate_last_fixed; stri_opts_collator; stri_replace_all_fixed, stri_replace_all_fixed, stri_replace_first_fixed, stri_replace_first_fixed, stri_replace_last_fixed, stri_replace_last_fixed; stri_split_fixed, stri_split_fixed; stri_trans_tolower, stri_trans_totitle, stri_trans_toupper; stringi-locale; stringi-search-fixed

Examples

1
2
3
4
5
## Not run: 
stri_sort(c("hladny", "chladny"), opts_collator=stri_opts_collator(locale="pl_PL"))
stri_sort(c("hladny", "chladny"), opts_collator=stri_opts_collator(locale="sk_SK"))

## End(Not run)

Example output

[1] "chladny" "hladny" 
[1] "hladny"  "chladny"

stringi documentation built on May 2, 2019, 4:54 p.m.