Title: | Natural Ordering |
---|---|
Description: | Provides functions related to human natural ordering. It handles adjacent digits in a character sequence as a number so that natural sort function arranges a character vector by their numbers, not digit characters. It is typically seen when operating systems lists file names. For example, a sequence a-1.png, a-2.png, a-10.png looks naturally ordered because 1 < 2 < 10 and natural sort algorithm arranges so whereas general sort algorithms arrange it into a-1.png, a-10.png, a-2.png owing to their third and fourth characters. |
Authors: | Kosei Abe |
Maintainer: | Kosei Abe <[email protected]> |
License: | BSD_3_clause + file LICENSE |
Version: | 0.1.3 |
Built: | 2025-03-13 02:44:25 UTC |
Source: | https://github.com/kos59125/naturalsort |
naturalfactor
creates a factor with levels in natural order.
naturalfactor(x, levels, ordered = TRUE, ...)
naturalfactor(x, levels, ordered = TRUE, ...)
x |
a character vector. |
levels |
a character vector whose elements might be appeared in |
ordered |
logical flag that determines whether the factor is ordered. |
... |
arguments that are passed to |
Natural ordering is a kind of alphanumerical ordering.
naturalorder
returns the order of the argument character #' vector in human natural ascending or descending order.
naturalsort
returns the sorted vector.
naturalorder(text, decreasing = FALSE, na.last = TRUE) naturalsort(text, decreasing = FALSE, na.last = NA)
naturalorder(text, decreasing = FALSE, na.last = TRUE) naturalsort(text, decreasing = FALSE, na.last = NA)
text |
a character vector to sort. |
decreasing |
logical. |
na.last |
logical. If |
For naturalorder
, the results are indices of vector elements in natural order.
For naturalsort
, the results are sorted vectors.
text <- c("a-1.png", "a-2.png", "a-10.png") print(sort(text)) print(naturalsort(text))
text <- c("a-1.png", "a-2.png", "a-10.png") print(sort(text)) print(naturalsort(text))