左加入ICDcm2016到数据集

Left joining ICDcm2016 to data set

我 运行 遇到了问题,我下载了 icd 包,我试图将 ICDcm2016 中的 ICD 代码加入到我自己的代码中,该代码也有 icd 代码。当我出于某种原因尝试离开加入时,除了一个“R99”之外的所有 icd 代码都作为 NA 返回。我不明白为什么其他代码没有加入。这是我的代码示例

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

关于如何使这项工作有任何想法吗?

万一这是您遇到的问题,我会收到一个描述性错误,说明我的 code 列包含的数据格式与我尝试加入的 code 列不同到.

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