Skip to contents

Calculate age at death based on date of birth and date of death

Usage

cod_calculate_age(dob, dod, date_format = "%Y-%m-%d", codedit = TRUE)

cod_calculate_ages(dob, dod, date_format = "%Y-%m-%d", codedit = TRUE)

Arguments

dob

Date of birth. This should ideally be in standard ISO extended date format of "YYYY-MM-DD" as specified in the default value for date_format.

dod

Date of death. This should ideally be in standard ISO extended date format of YYYY-MM_DD" as specified in the default value for date_format.

date_format

Format for date values provided. Date formatting is handled using strptime() hence this needs to be specified based on what strptime() requires for its format argument. By default, this is set to the standard ISO extended date format expressed as "%Y-%m-%d" which corresponds to "YYYY-MM-DD".

codedit

Logical. Should output be based on the CoDEdit version 2 coding rules. Default to TRUE.

Value

Values for age in days, months and years. IF codedit is TRUE, a tibble with age value and age type as required by CoDEdit.

Examples

cod_calculate_age("1977-11-05", Sys.Date())
#> # A tibble: 1 × 2
#>   age_value age_type
#>       <int> <chr>   
#> 1        47 Y       
cod_calculate_age("1965-05-20", "2023-10-03")
#> # A tibble: 1 × 2
#>   age_value age_type
#>       <int> <chr>   
#> 1        58 Y