Home > other >  Left joining ICDcm2016 to data set
Left joining ICDcm2016 to data set

Time:01-26

I'm running into a problem, I downloaded the icd package and I'm trying to left join the ICD code from the ICDcm2016 to my own code that also has icd codes. When I try to left join for some reason all of the icd codes except for one "R99" come back as NAs. I cant figure out why the other codes are not joining. Here is an example of my code

new_data <- new_data %>% left_join(icdcm2016, by = c("code" = "code"))

Any ideas on how to make this work?

CodePudding user response:

In case this is the problem you encountered, I get a descriptive error which explains that my code column holds a different format of data than does the code column I'm trying to join to.

new_data <- data.frame(code = c("A00", "A000"),
                       my_data = c("hello", "world"))


# Doesn't work because icd10cm2016$code is a special data type, not plain character data.
new_data %>% 
  left_join(icd.data::icd10cm2016, 
            by = c("code" = "code"))
#Error: Can't join on `x$code` x `y$code` because of incompatible types.
#ℹ `x$code` is of type <character>>.
#ℹ `y$code` is of type <icd10cm>>.
#Run `rlang::last_error()` to see where the error occurred.



# Works if we coerce the icd10cm2016$code to plain text
new_data %>% 
  left_join(icd.data::icd10cm2016 %>% 
              mutate(code = as.character(code)), 
            by = c("code" = "code"))

  code my_data billable                                         short_desc                                          long_desc three_digit   major                    sub_chapter                                   chapter
1  A00   hello    FALSE                                            Cholera                                            Cholera         A00 Cholera Intestinal Infectious Diseases Certain infectious and parasitic diseases
2 A000   world     TRUE Cholera due to Vibrio cholerae 01, biovar cholerae Cholera due to Vibrio cholerae 01, biovar cholerae         A00 Cholera Intestinal Infectious Diseases Certain infectious and parasitic diseases
  •  Tags:  
  • Related