根据另一个data.table删除data.table中的行 [英] Remove rows in data.table according to another data.table

查看:127
本文介绍了根据另一个data.table删除data.table中的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为 dtA data.table

我的实际 dtA 有62871932行和3列:

My actual dtA has 62871932 rows and 3 columns:

  date    company    value
198101          A        1
198101          A        2
198101          B        5
198102          A        2
198102          B        5
198102          B        6

data.table dtB 有一些我想从 dtA 中删除​​的列,所以 dtB 就像规则:

data.table dtB have some columns I want to remove from dtA, so dtB is like the rules:

实际 dtB 有19615280行和3列:

Actual dtB has 19615280 rows and 3 columns:

  date    company    value
198101          A        2
198102          B        5

最终结果是:

  date    company    value
198101          A        1
198101          B        5
198102          A        2
198102          B        6

它不是那么简单:

dtA=dtA[!(dtB$company %in% dtA$company)] 

,因为它还取决于日期和值。

because it also depends on date and value.

我试图将两个表合并在一起,并且用不声明的形式将其链接:

I tried to merge two tables together and chain it with not in statement:

dtA=dtA[dtB, on=date][!(company %in% comapny) & !(value %in% value)]

我收到此消息:


Join导致超过2 ^ 31行(内部vecseq达到物理
限制)。

Join results in more than 2^31 rows (internal vecseq reached physical limit). Very likely misspecified join.

有什么想法吗?

推荐答案

使用反联接:

dtA[!dtB, on=.(date, company, value)]

这将使用 dtA on <中的列来匹配 dtA 中未在 dtB 中找到的所有记录。 / code>。

This matches all records in dtA that are not found in dtB using the columns in on.

这篇关于根据另一个data.table删除data.table中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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