yr_sort: Chronological ordering of year vectors

View source: R/yr_sort_range.R

yr_sortR Documentation

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, ...)

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.

Value

Sorted yr vector

See Also

Other functions for chronological ordering and extremes: yr_extremes

Examples

# 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)

era documentation built on April 4, 2025, 2:09 a.m.