df <- data.frame(ID = c(1, 2, 3),
icd_1 = c("410.x", "428.0", "496"),
icd_2 = c("428.33", "401.9", "493.90"))
# Using pre-existing mapping (e.g., charlson9 or quan_elixhauser9)
mapping <- "charlson9"
icd9_to_comorbid(df, "ID", c("icd_1", "icd_2"), mapping)
# Using custom mapping
custom_mapping <- list("Myocardial Infarction" = c("410.x", "412.x"),
"Congestive Heart Failure" = c("398.91", "402.01",
"402.11", "402.91", "404.01", "404.03",
"404.11", "404.13", "404.91", "404.93", "425.4",
"425.5", "425.6", "425.7", "425.8", "425.9", "428.x"))
icd9_to_comorbid(df, "ID", c("icd_1", "icd_2"), custom_mapping, batch_size = 2)
Run the code above in your browser using DataLab