I have a range of string values in a factor which I'd like to re-code. Within the levels, there's a long range of factor levels ("601", "602",...,"689") that I want to re-code to a single numeric value 5001.
I tried dplyr using mutate in combination with case_when as illustrated. These codes work for single values, but I don't know how to include a re-code for a range of string values without resorting by line.
basecensusdata <- basecensusdata %>%
mutate(educval, case_when(
basecensusdata$P12 == "000" ~ 0,
basecensusdata$P12 == "010" ~ 100))
I'd like to re-code the range ("601" to "689") into a singular numeric value under a new variable (say new_var). How can this be done?