Learn R Programming

era (version 0.6.0)

yr_sort: Chronological ordering of year vectors

Description

Sorts a vector of years into earliest-to-latest or latest-to-earliest chronological order based on its era.

Usage

yr_sort(x, reverse = FALSE, ...)

Value

Sorted yr vector

Arguments

x

yr vector with era

reverse

Set FALSE (the default) for chronological order (earliest to latest) or TRUE for reverse chronological order (latest to earliest).

...

Other arguments passed to sort(); in particular use na.last to control NA handling.

Details

This is implemented as a prefixed function rather than an S3 sort() method for yrs to avoid surprises when numerical (i.e. not chronological) sorting is expected.

See Also

Other functions for chronological ordering and extremes: yr_difference(), yr_earlier_than(), yr_extremes

Examples

Run this code
# Forward-counting era:
x <- yr(c(200, 100, 300), "CE")
yr_sort(x)
yr_sort(x, reverse = TRUE)

# Backward-counting era:
y <- yr(c(200, 100, 300), "BCE")
yr_sort(y)
yr_sort(y, reverse = TRUE)

Run the code above in your browser using DataLab