本文介绍了在R(Rstudio)中读取诸如ÆØÅ之类的特殊字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试读取一个CSV文件,其中包含以挪威语编写的问卷数据。因此,此文件包含字母ÆØÅ,但是R似乎不能很好地处理这些字母,它们都显示为问号。

I am trying to read a CSV file containing questionnaire data written in Norwegian. So this file contains the letters Æ Ø Å, however R does not seem to handle these letters well, they all appear as question marks.

我用它来读取数据:

data <- read.csv2("Responser - Vasket - 20.06.2013.csv")

我应该使用任何选项让R知道我有特殊字符吗?

Is there any options I should use to let R know I have special characters?

,而我正在Windows 7上使用Rstudio。

and I am using Rstudio on Windows 7.

推荐答案

您需要指定 read.csv2 的fileEncoding 参数(以及(?) encoding )。

You need to specify the fileEncoding argument to read.csv2 ( as well as (?) the encoding).

在转到R之前,最好先检查一下编码的文件正在使用文本编辑器。例如,如果您在Notepad ++中打开文件,则可以使用编码菜单查看和更改字符编码。在TextPad中,您可以从另存为..对话框中更改编码。

Before you get to R, it is a good idea to check what the encoding of the file is using a text editor. For example, if you open a file in Notepad++, the Encoding menu lets you view and change the character encoding. In TextPad, you can change the encoding from the Save As.. dialog box. Most text editors will have such a feature.

这是您需要传递给 fileEncoding 的值。您不能仅仅将文件声明为UTF-16(如果尚未创建)。这就是为什么您要发出警告。

This is the value you need to pass to fileEncoding; you can't just declare a file to be UTF-16 if it isn't already. That's why you had a warning.

这篇关于在R(Rstudio)中读取诸如ÆØÅ之类的特殊字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 10:49
查看更多