R评估错误中的read_csv问题:必须将列1命名为

时间:2018-07-20 18:55:53

标签: r csv

我是R的新手,正在尝试读取一个csv文件,该文件包含一列数据,这些数据用逗号隔开,并且引号与此类似:

"First Name", "Last Name", "City", "State", "Country", "Zip Code"
"Amy", "Smith", "San Fransisco", "California", "USA", "10000"
"John", "Parker", "New York", "New York", "USA", "10010"
"Homer", "Smith", "New Haven", "Connecticut", "USA", "21292"

如何导入文件,以使逗号变成列而引号消失?

First Name   Last Name     City          State     Country   Zip Code
 Amy           Smith   San Fransisco   California    USA       10000
 John         Parker     New York       New York     USA       10010
 Homer         Smith     New Haven     Connecticut   USA       21292

我尝试了

read_csv("path to my file.csv", col_names= TRUE, col_types = NULL, header = FALSE)

但是我得到了:

Parsed with column specification:
cols(
  col_character()
)
Error in read_tokens_(data, tokenizer, col_specs, col_names, locale_,  : 
  Evaluation error: Column 1 must be named.

1 个答案:

答案 0 :(得分:0)

我在电视中阅读时遇到类似的问题。我将文件编码更改为UTF-8,这对我来说解决了。 不优雅,但是我这样做: 1)在Sublime Text中打开文件 2)另存为“ UTF-8”

为我工作...