From hex to ascci?

Hi, sorry for the subject to be in spanish, but i want to translate the hex to ascii, i have this example.

[1] "S\xe1banas de hospital"
[2] "\xc1cido valproico"
[3] "Servicios hospitalarios de emergencia o quir\xfargico"

1 "Sábanas de hospital"
2 "Ácido valproico"
3 "Servicios hospitalarios de emergencia o quirúrgico"

How do i make a function to do it?

What is the input and the output? If it's to go from the first to the second, you just need to tell R that the encoding is "latin1":

xx <- c("S\xe1banas de hospital",
"\xc1cido valproico",
"Servicios hospitalarios de emergencia o quir\xfargico")

# displayed incorrectly
xx
#> [1] "S\xe1banas de hospital"                               
#> [2] "\xc1cido valproico"                                   
#> [3] "Servicios hospitalarios de emergencia o quir\xfargico"

# because R doesn't know what encoding was used (was it Spanish? Japanese? Hebrew?)
Encoding(xx)
#> [1] "unknown" "unknown" "unknown"


# tell R which encoding you used
Encoding(xx) <- "latin1"
Encoding(xx)
#> [1] "latin1" "latin1" "latin1"

# now R knows how to display it
xx
#> [1] "Sábanas de hospital"                               
#> [2] "Ácido valproico"                                   
#> [3] "Servicios hospitalarios de emergencia o quirúrgico"

Created on 2022-07-19 by the reprex package (v2.0.1)

2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.