rip_year() extracts the year from a date or datetime object.

rip_year(x)

Arguments

x

<Date / POSIXct / POSIXlt>

The vector to extract the year from.

Value

An integer vector the same size as x containing the years.

Examples

x <- as.Date("2019-01-01") rip_year(x)
#> [1] 2019
# Identical dates, but in different years a <- as.POSIXct("1969-12-31 19:00:00", tz = "America/New_York") b <- as.POSIXct("1970-01-01 00:00:00", tz = "UTC") identical(as.numeric(a), as.numeric(b))
#> [1] TRUE
rip_year(a)
#> [1] 1969
rip_year(b)
#> [1] 1970