【发布时间】:2020-10-18 09:55:12
【问题描述】:
我有带有数据的 csv 文件:
filename <- "myfile.csv"
看起来像这样:
A,"B","C","D"
1,"2.4","5","6"
我正在使用data.table 库来读取这个文件:
table <- fread(filename, header = F, sep = ",", quote = "", stringsAsFactors = F)
然后我得到:
1: "A ""B"" ""C"" ""D"""
2: "1 ""2.4"" ""5"" ""6"""
我不明白为什么我得到这么多",以及如何正确读取我的数据。
附:如果没有quote,我会收到警告:
Found and resolved improper quoting in first 100 rows. If the fields are not quoted (e.g. field separator does not appear within any field), try quote="" to avoid this warning.
而数据是:
1: A,""B" "C" "D""
2: 1,""2.4" "5" "6""
所以它也不能正常工作 - 我需要 4 列,但我得到 3。
也许我必须使用另一个函数来读取我的数据?
原始数据为here。
【问题讨论】:
-
您不需要
quote参数,也不需要其他参数。 -
@Jaap,编辑了我的问题,很遗憾没有用
-
你用的是什么版本的data.table?
-
无法在 data.table
1.13.0上重现。 -
@user438383,我有
1.13.0。也许原始文件有问题?在我的问题中添加了链接。
标签: r dataframe data.table