Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (5.3k points)

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 an easier way to do this all in one line, right? I don't find the gsub help to be very comprehensive on this.

1 Answer

0 votes
by

To replace multiple letters with accents you can use the character translation function i.e., chrtr() from the base package as follows:

mydata=c("á","é","ó")

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

> mydata

[1] "a" "e" "o"

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...