Calculates age in years based on a reference date, which is the sytem date at default.

age(x, reference = Sys.Date())

Arguments

x

date(s), will be coerced with as.POSIXlt

reference

reference date(s) (defaults to today), will be coerced with as.POSIXlt and cannot be lower than x

Value

Integer (no decimals)

Read more on our website!

On our website https://msberends.gitlab.io/AMR you can find a comprehensive 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.

See also

age_groups to split age into age groups

Examples

# NOT RUN {
df <- data.frame(birth_date = Sys.Date() - runif(100) * 25000)
df$age <- age(df$birth_date)
# }