yr_extremes: Chronological minima and maxima

yr_extremesR Documentation

Chronological minima and maxima

Description

Returns the chronologically earliest and/or latest value in a vector of years, i.e. era-aware version min(), max(), and range().

Usage

yr_earliest(x, na.rm = FALSE)

yr_latest(x, na.rm = FALSE)

yr_range(x, na.rm = FALSE)

Arguments

x

A yr vector with era

na.rm

a logical indicating whether missing values should be removed

Details

These are implemented as prefixed functions rather than S3 min(), max(), and range() methods for yrs to avoid surprises when numerical (i.e. not chronological) extremes are expected.

Value

For yr_earliest() and yr_leatest(), a yr vector of length 1 with the earliest or latest value.

For yr_range(), a yr vector of length 2 with the earliest and latest value (in that order).

If x contains NA values and na.rm = FALSE (the default), only NAs will be returned.

See Also

Other functions for chronological ordering and extremes: yr_sort()

Examples

# Forward-counting era:
x <- yr(c(200, 100, 300), "CE")
yr_earliest(x)
yr_latest(x)
yr_range(x)

# Backward-counting era:
y <- yr(c(200, 100, 300), "BCE")
yr_earliest(y)
yr_latest(y)
yr_range(x)


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