compute_age | R Documentation |
Calculate the time difference between two dates in specified units (years, months, or days). Uses lubridate intervals for accurate calculations across calendar irregularities.
compute_age(date_start, date_end, unit = c("years", "months", "days"))
date_start |
Starting date. Must be a date or datetime object compatible with lubridate. |
date_end |
Ending date. Must be a date or datetime object compatible with lubridate. |
unit |
Character string specifying the unit for the result. Must be one of "years", "months", or "days". Defaults to "years". |
A numeric value representing the time difference in the specified unit.
# Calculate age in years
compute_age(as.Date("1990-01-01"), as.Date("2024-01-01"))
# Calculate age in months
compute_age(as.Date("2023-01-01"), as.Date("2024-01-01"), unit = "months")
# Calculate age in days
compute_age(as.Date("2023-12-01"), as.Date("2024-01-01"), unit = "days")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.