data.table fread如何忽略空行 [英] data.table fread how to ignore empty line

查看:88
本文介绍了data.table fread如何忽略空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来像文件中的第二行是空的,列名将不会被读取。我已经玩过开关,如标题,跳过,从文档,但不能让它工作。

It looks like if the second line in the file is empty, the column names will not be read. I've played with switches such as header, skip, from the documentation but can't get it to work.

如果我的文件中的第二行是空的,如何忽略这个事实,仍然读取第一行作为列名称?

In case the second line in my file is empty, how to ignore this fact and still read the first line as column names?

第二行为空:

> fread('c1 c2\n\n1 2\n3 4\n')

   V1 V2
1:  1  2
2:  3  4

第二行不为空:

> fread('c1 c2\n1 2\n3 4\n')
   c1 c2
1:  1  2
2:  3  4


推荐答案

当前版本的 data.table 1.9.8+)添加了一个似乎解决此问题的 blank.lines.skip 参数:

The current version of data.table (1.9.8+) adds a blank.lines.skip argument that seems to resolve this problem:

fread('c1 c2\n\n1 2\n3 4\n',blank.lines.skip = TRUE)
#    c1 c2
# 1:  1  2
# 2:  3  4

这篇关于data.table fread如何忽略空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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