问题描述
假设我有这个txt档案:
Let's say I have this txt file:
"AA",3,3,3,3
"CC","ad",2,2,2,2,2
"ZZ",2
"AA",3,3,3,3
"CC","ad",2,2,2,2,2
使用 csv
我可以:
> read.csv("linktofile.txt", fill=T, header=F)
V1 V2 V3 V4 V5 V6 V7
1 AA 3 3 3 3 NA NA
2 CC ad 2 2 2 2 2
3 ZZ 2 NA NA NA NA NA
4 AA 3 3 3 3 NA NA
5 CC ad 2 2 2 2 2
但 fread
给予
> library(data.table)
> fread("linktofile.txt")
V1 V2 V3 V4 V5 V6 V7
1: CC ad 2 2 2 2 2
我可以使用 fread
获得相同的结果吗?
Can I get the same result with fread
?
推荐答案
目前不我不知道 read.csv
的填充功能。在计划是添加读取双重限定文件( sep2
以及 sep
如?fread
中所述。然后,可变长度向量可以被读入列表
列中,其中每个单元本身是向量。但不填充NA。
Not currently; I wasn't aware of read.csv
's fill feature. On the plan was to add the ability to read dual-delimited files (sep2
as well as sep
as mentioned in ?fread
). Then variable length vectors could be read into a list
column where each cell was itself a vector. But, not padding with NA.
您可以将其添加到?
这里有很多不规则的数据格式吗?我只记得看到常规文件,其中不完整的行将被视为错误。
Are there many irregular data formats like this out there? I only recall ever seeing regular files, where the incomplete lines would be considered an error.
UPDATE :很不可能完成。 fread
针对正常分隔的文件(每行具有相同的列数)进行了优化。然而,当实现 sep2
时,不规则文件可以读入 list
列(每个单元格本身为向量)没有填写单独的列,因为 read.csv
可以。
UPDATE : Very unlikely to be done. fread
is optimized for regular delimited files (where each row has the same number of columns). However, irregular files could be read into list
columns (each cell itself a vector) when sep2
is implemented; not filled in separate columns as read.csv
can do.
这篇关于填充选项为fread的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!