Type: | Package |
Title: | Natural Ordering |
Version: | 0.1.3 |
Suggests: | testthat |
Date: | 2016-08-30 |
Author: | Kosei Abe |
Maintainer: | Kosei Abe <mail@recyclebin.jp> |
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. |
License: | BSD_3_clause + file LICENSE |
BugReports: | https://github.com/kos59125/naturalsort/issues |
RoxygenNote: | 5.0.1 |
NeedsCompilation: | no |
Packaged: | 2016-08-30 05:50:59 UTC; abe |
Repository: | CRAN |
Date/Publication: | 2016-08-30 12:48:28 |
Natural Ordering Sort
Description
Provides functions related to natural ordering.
Natural Ordering Factor
Description
naturalfactor
creates a factor with levels in natural order.
Usage
naturalfactor(x, levels, ordered = TRUE, ...)
Arguments
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 Sort
Description
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.
Usage
naturalorder(text, decreasing = FALSE, na.last = TRUE)
naturalsort(text, decreasing = FALSE, na.last = NA)
Arguments
text |
a character vector to sort. |
decreasing |
logical. |
na.last |
logical. If |
Value
For naturalorder
, the results are indices of vector elements in natural order.
For naturalsort
, the results are sorted vectors.
Examples
text <- c("a-1.png", "a-2.png", "a-10.png")
print(sort(text))
print(naturalsort(text))