Joschi Joschi - 5 months ago 64
R Question

Replace multiple arguments with gsub

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)