age_from_dob: Calculate age in years from dates of birth

Description Usage Arguments Value Examples

View source: R/age_from_dob.R

Description

Calculate age in years from dates of birth.

Usage

1
age_from_dob(dob, until = Sys.Date(), as_int = TRUE)

Arguments

dob

Vector of dates of birth. If not of class "Date", will attempt to convert using lubridate::as_date.

until

End-date used for age calculation. Defaults to current date (based on Sys.Date()). If not of class "Date", will attempt to convert using lubridate::as_date.

as_int

Logical indicating whether to return ages rounded down to the nearest integer (TRUE), or as numeric decimal values (FALSE). Defaults to TRUE.

Value

Vector of ages in units of years, either of class integer (if as_int = TRUE) or numeric (as_int = FALSE).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
dates_of_birth <- as.Date(
  c("2001-04-05", "1976-10-24", "1990-03-15", "1943-12-08")
)

# by default returns integer ages
age_from_dob(dates_of_birth)

# use as_int = FALSE to return decimal values
age_from_dob(dates_of_birth, as_int = FALSE)

# calculate with end-point other than current date
age_from_dob(dates_of_birth, until = "2019-01-01")

epicentre-msf/llutils documentation built on Nov. 9, 2020, 8:24 p.m.