I am using str_replace()
to rename thousands of mispelled city names. I'd like to align the replacement argument (i.e. the last argument) to a consistent total number of characters from the left. For example, I'd like to go from:
data %>%
mutate(
city_name = str_replace(city_name, "Torunto", "Toronto"),
city_name = str_replace(city_name, "Edmoonton", "Edmonton"),
city_name = str_replace(city_name, "Saskatchawan", "Saskatchewan")
)
To this:
data %>%
mutate(
city_name = str_replace(city_name, "Torunto", "Toronto"),
city_name = str_replace(city_name, "Edmoonton", "Edmonton"),
city_name = str_replace(city_name, "Saskatchawan", "Saskatchewan")
)
Is there any RStudio feature that allows me to do this easily? So far, I have experimented with a reprex search and replace and the 'find and add next' RStudio feature but to no avail.