AlSub
AlSub

Reputation: 1155

Decoding character strings vectors in R

Suppose you have an atomic vector containing encoded character strings:

string_encoding <- c("São Paulo", "Paraná")

Is there any way to decode every element in the vector, returning a vector of the same length with ASCII, ISO-8859-1 or other class of encoding?

The output should be:

expected_encoding <- c("Sao Paulo", "Parana")

Upvotes: 2

Views: 645

Answers (2)

Duck
Duck

Reputation: 39595

Another option can be:

iconv(string_encoding, to='ASCII//TRANSLIT')

Output:

[1] "Sao Paulo" "Parana"

Upvotes: 1

tmfmnk
tmfmnk

Reputation: 39858

Using stringi, you can do:

stri_trans_general(string_encoding, "Latin-ASCII")

[1] "Sao Paulo" "Parana"

Upvotes: 2

Related Questions