From the Slack discussion in help-with-r, code suggestions were:
(contributions from @tomjemmett, https://github.com/sebastian-fox, @zx8754, @TimTaylor)
currently 5 styles of approach jump out:
dplyr::recode()
factor approaches (base or forcats)
Named vector.
Explicit joins (base merge, dplyr or data.table)
dplyr::case_when() / data.table::fcase()
list_of_csv[['Lancaster']] %>%
mutate(
# Create categories
age_group = dplyr::case_when(
age == '00_04' | age == '05_09' | age == '10_14' | age == '15_19' ~ '0-19'
),
# Convert to factor
age_group = factor(
age_group,
level = c('0-19')
)
)
From the Slack discussion in help-with-r, code suggestions were: (contributions from @tomjemmett, https://github.com/sebastian-fox, @zx8754, @TimTaylor)
currently 5 styles of approach jump out:
Doesn't work with character though:
Possibly opaque?