【发布时间】:2023-03-23 17:50:02
【问题描述】:
我有一个大的制表符分隔的数据表,我正在尝试使用 data.table 包 fread 函数将其读入 R。但是,fread 遇到错误。如果我使用 read.delim,表格会正确读入,但我不知道如何配置 fread 以便正确处理数据。
为了寻找解决方案,我安装了 data.table 的开发版本,所以我目前正在运行 data.table v1.9.7,在 R v3.2.2 下,在 Ubuntu 15.10 上运行。
我已将问题从我的大表中隔离到几行,您可以download it here。
当我使用 fread 时:
> fread('problemRows.txt')
Error in fread("problemRows.txt") :
Expecting 8 cols, but line 3 contains text after processing all cols. It is very likely that this is due to one or more fields having embedded sep=',' and/or (unescaped) '\n' characters within unbalanced unescaped quotes. fread cannot handle such ambiguous cases and those lines may not have been read in as expected. Please read the section on quotes in ?fread.
我尝试使用 read.delim 使用的参数:
fread('problemRows.txt', sep="\t", quote="\"")
但我得到了同样的错误。
关于如何正确读取此内容的任何想法?我不确定到底是什么问题。
谢谢!
【问题讨论】:
-
第二行代码还有一个额外的“双引号”
标签: r data.table