as.Date.yrs: Coerce Fractional Year Values to Date Values

View source: R/fractional_years.R

as.Date.yrsR Documentation

Coerce Fractional Year Values to Date Values

Description

Coerces an yrs object to a Date object. Some loss of information comes if year.length = "approx" was set when using get.yrs, so the transformation back to Date will not be perfect there. With year.length = "actual" the original values are perfectly retrieved.

Usage

## S3 method for class 'yrs'
as.Date(x, ...)

Arguments

x

an yrs object created by get.yrs

...

unused, included for compatibility with other as.Date methods

Value

A vector of 'Date' values based on the input fractional years.

Author(s)

Joonas Miettinen

See Also

get.yrs

Examples

data("sire", package = "popEpi")

## approximate year lengths: here 20 % have an extra day added
sire$dg_yrs <- get.yrs(sire$dg_date)
summary(sire$dg_yrs)
dg_date2 <- as.Date(sire$dg_yrs)
summary(as.numeric(dg_date2 - as.Date(sire$dg_date)))

## using actual year lengths
sire$dg_yrs <- get.yrs(sire$dg_date, year.length = "actual")
summary(sire$dg_yrs)
dg_date2 <- as.Date(sire$dg_yrs)
summary(as.numeric(dg_date2 - as.Date(sire$dg_date)))

popEpi documentation built on Aug. 23, 2023, 5:08 p.m.