Replace multiple letters with accents with gsub

Joschi picture Joschi · Mar 6, 2013 · Viewed 50.5k times · Source

of course I could replace specific arguments like this:

    mydata=c("á","é","ó")
    mydata=gsub("á","a",mydata)
    mydata=gsub("é","e",mydata)
    mydata=gsub("ó","o",mydata)
    mydata

but surely there is a easier way to do this all in onle line, right? I dont find the gsub help to be very comprehensive on this.

Answer

kith picture kith · Mar 6, 2013

Use the character translation function

chartr("áéó", "aeo", mydata)