Recoding in R

Recoding in R refers to the process of transforming or modifying the values of a variable. This can involve changing the values to different categories, recategorizing them, or assigning new values based on specific conditions.

#mutate province names
dd= dd1 %>%
  mutate(geo = case_when(
    grepl("Newfoundland and Labrador", geo) ~ "Newfoundland and Labrador",
    grepl("Nova Scotia", geo) ~ "Nova Scotia",
    grepl("Prince Edward Island", geo) ~ "Prince Edward Island",
    grepl("New Brunswick", geo) ~ "New Brunswick",
    grepl("Quebec", geo) ~ "Quebec",
    grepl("Onta", geo) ~ "Ontario",
    grepl("Manitoba", geo) ~ "Manitoba",
    grepl("Saskatchewan", geo) ~ "Saskatchewan",
    grepl("Alberta", geo) ~ "Alberta",
    grepl("British Columbia", geo) ~ "British Columbia",
    grepl("Canada", geo) ~ "Canada",
    TRUE ~ "Other"
  )) %>%
  group_by(across(c(1:4))) %>%
  summarise(value = sum(value))