Skip to contents

Calculate the actual age between two dates

Usage

calc_age(birth_date, onset_date)

Arguments

birth_date

Birth date.

onset_date

Event date.

Value

Vector of ages.

Examples

sdate <- as.Date("1960-01-01")
edate <- as.Date("1980-12-31")
bdate <- sample(seq(sdate, edate, by = "1 day"), 100, replace = TRUE)
event <- sample(seq(as.Date("2020-01-01"),
                    as.Date("2023-07-08"),
                    by = "1 day"),
                100, replace = TRUE)
ages <- calc_age(bdate, event)
ages
#>   [1] 46 45 44 56 61 43 55 42 58 51 54 49 56 48 56 50 60 44 53 51 43 50 41 40 54
#>  [26] 54 48 50 54 43 54 58 41 51 46 47 53 45 50 57 54 42 57 58 39 44 60 45 50 53
#>  [51] 55 57 48 45 51 42 49 58 50 45 44 49 48 52 53 56 48 56 43 59 59 61 51 42 60
#>  [76] 58 43 58 55 43 54 56 46 54 50 55 59 45 45 42 54 46 56 44 52 50 56 44 54 55