Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

kos59125/naturalsort

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

naturalsort package

The package provides functions related to human natural ordering.

Installation

install.packages("naturalsort")

For devtools users, run:

install_github("kos59125/naturalsort", subdir="naturalsort")

Usage

library(naturalsort)

## Simple example.
text <- c("a1.png", "a2.png", "a10.png")
print(naturalsort(text))
print(sort(text))  # general sort

## Reordering factors in natural order.
## After read.table with stringsAsFactors=TRUE, levels of column of factor is sorted in character order.
## If you prefer natural ordered factor, call read.table with stringsAsFactors=FALSE and creates factor column manually.
data <- read.table(file, header=TRUE, stringsAsFactors=FALSE)
data$SomeFactor <- factor(data$SomeFactor, levels=naturalsort(unique(data$SomeFactor)))

About

Natural ordering in R

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages