year: Convert a 'Date' vector to a numeric vector

View source: R/biostat3-internal.R

yearR Documentation

Convert a Date vector to a numeric vector

Description

Convert a Date vector to a numeric vector (either continuous or truncated).

Usage

year(date, trunc = FALSE, year.length = 365.24)

Arguments

date

Date vector

trunc

logical for whether to truncate the date to a whole year or consider the date as a double (default).

year.length

assumed length of a year

Details

For the double calculation, we use (truncated year of Date) + (date - 1 Jan of Year)/year.length.

Value

numeric vector

Examples

  c(year(as.Date("2001-07-01")),year(as.Date("2001-01-01"),trunc=TRUE))

biostat3 documentation built on Nov. 2, 2023, 6:04 p.m.