Converting accents to ASCII in R

不羁岁月 提交于 2019-12-11 08:04:33

问题


I'm trying to convert special characters to ASCII in R. I tried using Hadley's advice in this question:

stringi::stri_trans_general('Jos\xe9', 'latin-ascii')

But I get "Jos�". I'm using stringi v1.1.1.

I'm running a Mac. My friends who are running Windows machines seem to get the desired result of "Jose".

Any idea what is going on?


回答1:


The default encoding on Windows is different from the typical default encoding on other operating systems (UTF-8). x ='Jos\xe9' means something in Latin1, but not in UTF-8. So, on Linux or OS X you need to tell R what the encoding is:

x ='Jos\xe9'
Encoding(x) <- 'latin1'
stri_trans_general(x, 'Latin-ASCII')


来源:https://stackoverflow.com/questions/37930717/converting-accents-to-ascii-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!