dob2age: Calculate age from DOB

Description Usage Arguments Value Examples

View source: R/utils.R

Description

Calculate age from DOB

Usage

1
dob2age(dob, age_on = lubridate::today(), fun = NULL, units = "years", ...)

Arguments

dob

The date or vector of dates representing date(s) of birth.

age_on

(Date) The date on which age is to be calculated. Defaults to today.

fun

(function) The function to be applied to the age, e.g. floor. Defaults to NULL.

units

(character) The units to measure age in, e.g. "years". Only used if fun is specified. Defaults to "years".

...

Further optional arguments that will be passed to fun

Value

(duration) The age as a duration.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
dob2age(lubridate::as_date("1990-01-01"))
dob2age(
  dob = c(
    lubridate::as_date("1990-01-01"),
    lubridate::as_date("1994-01-01"),
    lubridate::as_date("1998-01-01")
  ),
  age_on = lubridate::as_date("2002-12-31"),
  fun = floor
)

epocakir documentation built on June 9, 2021, 9:07 a.m.