Chapter 40 10. Work with ICD-10 cause-of-death codes

Cause-of-death codes that start with C represent malignant neoplasms. Codes beginning with D include in situ, benign, or unknown-status neoplasms and are not counted as cancer deaths in this exercise.

40.1 10.1 Separate ICD-10 letters and numbers

rates <- rates %>%
  extract(
    Cause_of_death,
    into = c("letter", "number"),
    regex = "([A-Z]+)([0-9]+)",
    remove = FALSE
  ) %>%
  mutate(number = as.numeric(number))

rates %>% count(letter)
## # A tibble: 2 x 2
##   letter     n
##   <chr>  <int>
## 1 C      58916
## 2 D       1176

40.2 10.2 Keep cancer deaths only

rates <- rates %>%
  filter(letter == "C")