fread 的填充选项 [英] Fill option for fread

查看:16
本文介绍了fread 的填充选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这个 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

使用 read.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 以及 ?fread<中提到的 sep/代码>).然后可以将可变长度向量读入 list 列,其中每个单元格本身就是一个向量.但是,不使用 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.

您能否将其添加到列表?这样您就会在其状态发生变化时收到通知.

Could you add it to the list please? That way you'll get notified when its status changes.

有很多像这样的不规则数据格式吗?我只记得曾经看过常规文件,其中不完整的行将被视为错误.

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.

更新:不太可能完成.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 的填充选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆