在R中将重音转换为ASCII [英] Converting accents to ASCII in R
本文介绍了在R中将重音转换为ASCII的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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')
但是我得到了乔斯".我正在使用stringi v1.1.1.
But I get "Jos�". I'm using stringi v1.1.1.
我正在运行Mac.我的运行Windows计算机的朋友似乎获得了"Jose"的期望结果.
I'm running a Mac. My friends who are running Windows machines seem to get the desired result of "Jose".
知道发生了什么吗?
推荐答案
Windows上的默认编码与其他操作系统(UTF-8)上的典型默认编码不同. x ='Jos\xe9'
表示
Latin1,但不是UTF-8.因此,在Linux或OS X上,您需要告诉R编码是什么:
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')
这篇关于在R中将重音转换为ASCII的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文