Skip to contents

Structure cause-of-death data into CoDEdit tool input data

Usage

cod_structure_input(df, sex, sex_code = c(1, 2), dob, dod, code, id = NULL)

Arguments

df

A data.frame of raw cause-of-death data with the following required variables that contains values for sex, date of birth, date of death, and cause-of-death code.

sex

A character value for the variable name in df containing the values for sex.

sex_code

A character or integer vector of 2 values that indicate which values are to be considered pertaining to males (first value in the vector) or to females (second value in the vector).

dob

A character value for the variable name in df containing the values for date of birth.

dod

A character value for the variable name in df containing the values for date of death.

code

A character value for the variable name in df containing the values for cause-of-death code.

id

A character value for the variable name in df containing unique record identifiers. Default to NULL. If NULL, unique record identifiers will be generated.

Value

A tibble with 6 columns and number of rows equal to df with names "FreeId", "Sex", "Age Value", "Age Type", "Code", and "Death Date".

Examples

df <- data.frame(
  id = 1:3,
  sex = c(1, 1, 2),
  dob = c("1977-11-05", "1971-04-04", "2012-08-13"),
  dod = c("2024-06-28", "2023-10-11", "2023-09-25"),
  code = c("P219", "O230", "Q913")
)

cod_structure_input(df, sex = "sex", dob = "dob", dod = "dod", code = "code")
#> # A tibble: 3 × 6
#>   FreeId   Sex `Age Value` `Age Type` Code  `Death Date`
#>    <int> <int>       <int> <chr>      <chr> <chr>       
#> 1      1     1         110 Y          P219  2024        
#> 2      2     1         110 Y          O230  2023        
#> 3      3     2         110 Y          Q913  2023