I have a data frame like in the example bellow that contains names of cities, and I need to replace some names in order to remove spaces and special characters like ~ and ´.
df = data.frame( city = c('São Paulo', 'Belo Horizonte', 'Natal', 'Goiânia', 'Manaus'))
The problem is that I need to keep the names that do not need to be changed. I am using the mutate function bellow, but it replaces the names with no space or special characters by numbers.
df = df %>% mutate(city_correct = ifelse(city == 'São Paulo', 'Sao.Paulo', ifelse(city == 'Belo Horizonte', 'Belo.Horizonte', ifelse(city == 'Goiânia', 'Goiania', city ))))
Does anyone know how I can make the function above work?