简体   繁体   中英

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")

Using stringi , you can do:

stri_trans_general(string_encoding, "Latin-ASCII")

[1] "Sao Paulo" "Parana"

Another option can be:

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

Output:

[1] "Sao Paulo" "Parana"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM