用引号引起来的字符串中的EOF ...则列比列名称多

时间:2019-06-29 19:04:14

标签: r csv eof read.csv

我正在尝试从CSV文件导入数据,并且遇到了典型的“带引号的字符串内的EOF”问题。正如许多其他帖子所建议的那样,我将报价设置如下:

orionwebdata <- read.csv("OrionWebData.csv", quote = "")

但是随后出现以下错误:

Error in read.table(file = file, header = header, sep = sep, quote = quote,  : 
more columns than column names

我猜想通过删除引号,可以读取引号中的一些逗号,并在不应拆分的地方拆分行。建议使用fread的其他帖子:

orionwebdata <- fread("OrionWebData.csv", quote = "")

但是随后出现以下错误:

Warning messages:
1: In fread("OrionWebData.csv", quote = "") :
  Detected 401 column names but the data has 400 columns. Filling rows automatically. Set fill=TRUE explicitly to avoid this warning.
2: In fread("OrionWebData.csv", quote = "") :
  Stopped early on line 7. Expected 401 fields but found 411. Consider fill=TRUE and comment.char=. First discarded non-empty line: <<"2019","0141900001024020","01","01","C","000","   "," ","   ","   "," ","   ","   "," ","   ","0162168","0000000","0000000","00162168","003.72","0000","    ","    ","  ","00"," ","0","0"," ","  ","      ","0000000"," "," ","       ","       "," "," "," ","0","  ","  ","  ","  ","     ","  ","  ","  ","  ","     ","  ","  ","  ","  ","     ","  ","  ","  ","  ","     ","  ","  ","  ","  ","     ","  ","  ","  ","  ","     ","  ","  ","  ","  ","     ","  ","  ","  ","  ","     ","   ","    ","   

关于如何解决此问题的任何建议?

2 个答案:

答案 0 :(得分:0)

检查是否绝对用逗号分隔。当我没有明确地说出'sep = '\t'时,我在一个稍微奇怪的制表符分隔文件上使用read.table遇到了这个错误,所以我认为由于怪异,它猜测分隔符有误-您可以尝试使用read.csv使用sep =','显式写入或具有不同sep值的read.table。

答案 1 :(得分:0)

由于某种原因,如果我在Excel中打开此文件,请将其另存为制表符分隔的文件,然后在R中使用以下命令打开:

orionwebdata <- read.delim("OrionWebData_tab.txt", sep = "\t")

然后它起作用。我猜逗号分隔符由于某些原因是有问题的,而计算机却能够正确解释制表符,尽管我不确定为什么这样做。