Learn R Programming

PAutilities (version 1.1.0)

get_age: Calculate age

Description

Takes two Date objects and calculates age based on difftime (in days) divided by 365.2425 days per year (for age in years) or 30.4375 days per month (for age in months).

Usage

get_age(birthdate, current_date, units = c("years", "months"))

Value

Numeric value giving age in the specified units.

Arguments

birthdate

Date object giving the date of birth

current_date

Date object giving the date from which age is to be calculated

units

The units in which age should be reported

Examples

Run this code
get_age(as.Date("2000-01-01"), Sys.Date(), "years")

Run the code above in your browser using DataLab