Replace multiple letters with accents with gsub

ghz 1years ago ⋅ 538 views

Question

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

Use the character translation function

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