I have a dataframe of ICD10 codes that I need to convert to their respective subchapters. The subchapters of these codes are identified using the first 3 characters of each code i.e. the subchapter for M1711 is M17.
Is there an efficient way to map from these codes to their subchapters?
Here's an example dataset of codes that I'm using:
df <- data.frame(codes = c("Z23","M1711","E0500","Z00129","G4452"))
I understand that Jack O. Wasey has a great package ICD
that can convert to comorbidities and also has the subchapter dataset:
install.packages("devtools")
devtools::install_github("jackwasey/icd")
sub_chap <- icd::icd10_sub_chapters
But as you can see below, the data is in a range of values and is not in the right format for 'joining' to.
When I unlist the subchapters I am missing values in between the values in the original dataframe
sub_chap_df = as.data.frame(unlist(sub_chap))
Is there an efficient way that I can convert my ICD10 codes to their respective subchapter?