Returns the chronologically earliest and/or latest value in a vector of
years, i.e. era-aware version min(), max(), and range().
Arguments
- x
A yr vector with era
- na.rm
a logical indicating whether missing values should be removed
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.
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.
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)
#> # CE years <yr[1]>:
#> [1] 100
#> # Era: Common Era (CE): Gregorian years (365.2425 days), counted forwards from 0
yr_latest(x)
#> # CE years <yr[1]>:
#> [1] 300
#> # Era: Common Era (CE): Gregorian years (365.2425 days), counted forwards from 0
yr_range(x)
#> # CE years <yr[2]>:
#> [1] 100 300
#> # Era: Common Era (CE): Gregorian years (365.2425 days), counted forwards from 0
# Backward-counting era:
y <- yr(c(200, 100, 300), "BCE")
yr_earliest(y)
#> # BCE years <yr[1]>:
#> [1] 300
#> # Era: Before Common Era (BCE): Gregorian years (365.2425 days), counted backwards from 1
yr_latest(y)
#> # BCE years <yr[1]>:
#> [1] 100
#> # Era: Before Common Era (BCE): Gregorian years (365.2425 days), counted backwards from 1
yr_range(x)
#> # CE years <yr[2]>:
#> [1] 100 300
#> # Era: Common Era (CE): Gregorian years (365.2425 days), counted forwards from 0