Help with tidying messy data from MS Excel

Wow! read_excel() %>% janitor::clean_names() is a gift from the R gods.

I had another question which you answered in a different response to the post Elegant Code with Case_when

My question was how to clean up the area names after the pivot. This was my solution to that question:

brfss_2014 <- brfss_2014 %>%
  mutate(area = case_when(
    str_detect(brfss_2014$area, "^uacc") ~ "uacc",
    str_detect(brfss_2014$area, "^pima") ~ "pima",
    str_detect(brfss_2014$area, "^pinal") ~ "pinal",
    str_detect(brfss_2014$area, "^santa") ~ "santa_cruz",
    str_detect(brfss_2014$area, "^yuma") ~ "yuma",
  ))

Now I need to repeat everything for each of the three sheets on that Excel workbook. Thanks for your help. I could have done it the long way in the time it took to solve but now I have a much better idea how to do this more efficiently in the future.

1 Like