I use dplyrand gsubto remove special characters. I am trying to translate the code that I had with base R.
Here's a fake example similar to my data:
region = c("regi\xf3n de tarapac\xe1","regi\xf3n de tarapac\xe1")
provincia = c("cami\xf1a","iquique")
comuna = c("tamarugal","alto hospicio")
comunas = cbind(region,provincia,comuna)
This works for me:
comunas = comunas %>%
mutate(comuna = gsub("\xe1", "\u00e1", comuna),
comuna = gsub("<e1>", "\u00e1", comuna)
)
But now I want to apply the same thing to each column:
comunas = comunas %>%
mutate_all(funs(gsub("\xe1", "\u00e1", .),
gsub("<e1>", "\u00e1", .)
))
And I see that the last piece has no effect. The idea is to get:
region provincia comuna
[1,] "regi\xf3n de tarapacá" "cami\xf1a" "tamarugal"
[2,] "regi\xf3n de tarapacá" "iquique" "alto hospicio"
And any other necessary changes.
Any idea? thank you very much in advance!
source
share