R/RStudio 从 csv 读取时更改列名

R/RStudio changes name of column when read from csv

我正在尝试使用以下命令(在 RStudio 中)读取 R 中的文件:

fileRaw <- read.csv(file = "file.csv", header = TRUE, stringsAsFactors = FALSE)

file.csv 看起来像这样:

然而,当它读入 R 时,我得到:

如您所见,LOCATION 似乎无缘无故地更改为 ï..LOCATION

我尝试添加 check.names = FALSE,但这只会让情况变得更糟,因为 LOCATION 现在被 LOCATION 取代了。给出了什么?

我该如何解决这个问题?为什么 R/RStudio 这样做?

文件开头有一个UTF-8 BOM。尝试以 UTF-8 格式读取,或从文件中删除 BOM。

The UTF-8 representation of the BOM is the (hexadecimal) byte sequence 0xEF,0xBB,0xBF. A text editor or web browser misinterpreting the text as ISO-8859-1 or CP1252 will display the characters  for this.

编辑:看起来使用 fileEncoding = "UTF-8-BOM" 修复了 RStudio 中的问题。

使用 fileEncoding = "UTF-8-BOM" 解决了我的问题并顺利读取文件。

使用 fileEncoding = "UTF-8"/encoding = "UTF-8" 没有解决问题。