Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

age_from_dates

age from birth and reference dates


Description

Calculate age at time of reference date, based on birth date, rounded to the given unit. These are designed for physiologic estimations, not for accuracy. The dates can be given as anything which can be coerced into a Date.

Usage

age_from_dates(birth_date, ref_date = Sys.Date(), unit = c("year",
  "month", "day"))

Arguments

birth_date

Date of birth, either as a Date or something which will be converted to a Date

ref_date

Date at which to calculate age, defaults to current date, either as a Date or something which will be converted to a Date

unit

character of length, one of "year" or "day".

Value

integer vector

References

https://stackoverflow.com/questions/31126726

Examples

age_from_dates("2014-11-08", "2014-12-31", unit = "day")
age_from_dates("2014-11-08", "2014-12-31", unit = "day")
age_from_dates("1981-07-09", "2014-06-29", unit = "year")
# age must be zero or positive, may be in future, or error is thrown
## Not run: 
age_from_dates("2120-10-10", "2119-01-01")

## End(Not run)
# leap days work: we are just using internal R date manipulation
age_from_dates("2000-02-28", "2000-03-01", unit = "day")
age_from_dates("2004-02-28", "2004-03-01", unit = "day")
age_from_dates("1900-02-28", "1900-03-01", unit = "day")
age_from_dates("1901-02-28", "1901-03-01", unit = "day")

physiology

Calculate physiologic characteristics of awake and anesthetized adults, children and infants

v1.2.1
GPL-3
Authors
Jack O. Wasey [aut, cre, cph] (<https://orcid.org/0000-0003-3738-4637>), Bill Denney [ctb] (<https://orcid.org/0000-0002-5759-428X>)
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.