0 votes
1 view
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 (25.3k points)

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"

Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...