简体   繁体   English

将.csv导入U时出现UTF-8编码错误?

[英]Importing a .csv into R with UTF-8 encoding error?

I have a .csv file which is written in spanish so it has special characters like ñ, á, é, í, ó, ú. 我有一个用西班牙语编写的.csv文件,因此它具有ñ,á,é,í,ó,ú等特殊字符。 So if I open it in the notepad I can see all the characters properly written and I have already saved the file with UTF-8 encoding. 因此,如果在记事本中打开它,我可以看到所有正确书写的字符,并且我已经使用UTF-8编码保存了文件。 However, when I open RStudio and I import the data using: 但是,当我打开RStudio并使用以下命令导入数据时:

servutf <- read.csv("servutf.csv", sep=";")

I get all the dataset but incorrectly encoded ie: 我得到了所有数据集,但编码不正确,即:

Tengo 7 años de experiencia

It should be the following: 应该是以下内容:

Tengo 7 años de experiencia

I have tried everything, I don't know what else to do as I have already checked that R is using UTF-8 encoding and the file is encoded in the same way. 我已经尝试了所有方法,但我不知道该怎么办,因为我已经检查过R是否使用UTF-8编码,并且文件是以相同的方式编码的。

Any suggestion please? 有什么建议吗?

您需要指定编码

servutf <- read.csv("servutf.csv", sep=";", encoding = "UTF-8")

Try: 尝试:

library(readr)
servutf <- read_csv("servutf.csv")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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