本文介绍了fread无法读取第一列为空的.csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
说我有第一个 test.csv
,看起来像这样
Say I have the first test.csv
that looks like this
,a,b,c,d,e
如果我尝试使用 read.csv
,它工作正常。
read.csv("test.csv",header=FALSE)
# V1 V2 V3 V4 V5 V6
#1 NA a b c d e
#Warning message:
#In read.table(file = file, header = header, sep = sep, quote = quote, :
# incomplete final line found by readTableHeader on 'test.csv'
但是,如果我尝试使用 fread
读取此文件,我会收到一个错误。
However, if I attempt to read this file using fread
, i get an error instead.
require(data.table)
fread("test.csv",header=FALSE)
#Error in fread("test.csv", header = FALSE) :
# Not positioned correctly after testing format of header row. ch=','
Why does this happen and what can I do to correct this?
推荐答案
为什么会发生这种情况,我该怎么办?运行代码。它似乎工作现在 - 同样为其他人?我认为这可能是一个问题,没有一个新行在结束(因此从 read.csv
的警告,但 fread
处理结束时是否有新行。
I've tried making that csv file and running the code. It seems to work now - same for other people? I thought it might be an issue with not having a new line at the end (hence the warning from read.csv
), but fread
copes fine whether there's an new line at the end or not.
这篇关于fread无法读取第一列为空的.csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!