R中的字符编码 [英] Character encoding in R

查看:370
本文介绍了R中的字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图读取由Sql Server Management Studio生成的 csv 文件,并编码为 UTF-8 保存时选择该选项)到 R 版本3.0.1(x64)到 read.csv2()

I am trying to read a csv file generated by Sql Server Management Studio and encoded as UTF-8 (I chose that option when saving it) into R version 3.0.1 (x64) through read.csv2(). I can't R to display special characters correctly.

如果我设置 fileEncoding =UTF-8-BOM导入停止在我有一个ÿ的行。但是,当在 Notepad ++ 中打开文件时,ÿ会正确显示 UTF-8 我尝试没有设置 fileEncoding ,但是特殊字符不能正确显示(当然)。

If I set fileEncoding="UTF-8-BOM" the import stops at the line where I have a ÿ. However, when opening the file in Notepad++ the ÿ is displayed correctly with UTF-8 encoding. I have tried without setting fileEncoding, but then the special characters aren't displayed correctly (of course).

csv flie位于:
https://www.dropbox.com/ s / 7y47i826ikq8ahi / Data.csv

The csv flie is available here: https://www.dropbox.com/s/7y47i826ikq8ahi/Data.csv

如何读取csv文件并以正确的编码显示文本?

How do I read the csv file and display the text in the right encoding?

谢谢!!

推荐答案

我发现答案是我的。问题是从UTF-8到系统语言环境(R中的默认编码)通过 fileEncoding 的转换。因为我使用 RStudio ,我只是改变默认编码为UTF-8并删除 fileEncoding =UTF-8-BOM read.csv 。然后,读取整个csv文件,RStudio正确显示所有字符。

I found the answer my self. The problem was with the transformantion from UTF-8 to the system locale (the default encoding in R) through fileEncoding. As I use RStudio, I just changed the default encoding to UTF-8 and removed the fileEncoding="UTF-8-BOM" from read.csv. Then, the entire csv file was read and RStudio displays all characters correctly.

这篇关于R中的字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆