age.Rd
Calculates age in years based on a reference date, which is the sytem date at default.
age(x, reference = Sys.Date(), exact = FALSE, na.rm = FALSE)
x | date(s), will be coerced with |
---|---|
reference | reference date(s) (defaults to today), will be coerced with |
exact | a logical to indicate whether age calculation should be exact, i.e. with decimals. It divides the number of days of year-to-date (YTD) of |
na.rm | a logical to indicate whether missing values should be removed |
An integer (no decimals) if exact = FALSE
, a double (with decimals) otherwise
The lifecycle of this function is stable. In a stable function, we are largely happy with the unlying code, and major changes are unlikely. This means that the unlying code will generally evolve by adding new arguments; we will avoid removing arguments or changing the meaning of existing arguments.
If the unlying code needs breaking changes, they will occur gradually. To begin with, the function or argument will be deprecated; it will continue to work but will emit an message informing you of the change. Next, typically after at least one newly released version on CRAN, the message will be transformed to an error.
On our website https://msberends.gitlab.io/AMR you can find a tutorial about how to conduct AMR analysis, the complete documentation of all functions (which reads a lot easier than here in R) and an example analysis using WHONET data.
To split ages into groups, use the age_groups()
function.
# 10 random birth dates df <- data.frame(birth_date = Sys.Date() - runif(10) * 25000) # add ages df$age <- age(df$birth_date) # add exact ages df$age_exact <- age(df$birth_date, exact = TRUE) df