kyotil (version 2016.11-9)

age_calc: Age Calculation

Description

Calculate age, by Jason P Becker, modified very slightly in how arguments are passed to the function.

Usage

age_calc(dob, enddate = Sys.Date(), units = c("days","months","years"), precise = TRUE)

Arguments

dob
POSIXlt or Date. Birthday
enddate
POSIXlt or Date. Date to compute age
units
string. Choose a unit.
precise
Boolean.

References

http://blog.jsonbecker.com/2013/12/calculating-age-with-precision-in-r.html

Examples

Run this code

age_calc (dob=strptime("29OCT2002", format="%d%b%Y"), 
    enddate=strptime("30OCT2003", format="%d%b%Y"), units='years', precise=TRUE)
age_calc (dob=strptime("29OCT2002", format="%d%b%Y"), 
    enddate=strptime("30DEC2003", format="%d%b%Y"), units='years', precise=FALSE)

Run the code above in your browser using DataLab