Learn R Programming

dttr2 (version 0.4.0)

dtt_years: Get and Set Year Values

Description

Gets and sets year values for date/time vectors.

Usage

dtt_years(x, ...)

dtt_years(x) <- value

dtt_set_year(x, value)

dtt_year(x, ...)

dtt_year(x) <- value

# S3 method for Date dtt_year(x, ...)

# S3 method for POSIXct dtt_year(x, ...)

# S3 method for Date dtt_year(x) <- value

# S3 method for POSIXct dtt_year(x) <- value

Value

An integer vector (or the modified date/time vector).

Arguments

x

A date/time vector.

...

Unused.

value

A integer vector of the year value(s).

Methods (by class)

  • Date: Get integer vector of year values for a Date vector

  • POSIXct: Get integer vector of year values for a POSIXct vector

  • Date: Set year values for a Date vector

  • POSIXct: Set year values for a POSIXct vector

See Also

dtt_year_decimal()

Other set date: dtt_day(), dtt_months()

Examples

Run this code
x <- as.Date("1990-01-02")
dtt_year(x)
dtt_year(x) <- 11L
x

x <- as.POSIXct("1990-01-02 23:40:51")
dtt_year(x)
dtt_year(x) <- 2022L
x

Run the code above in your browser using DataLab