使用 data.table 进行左连接 [英] Left join using data.table

查看:33
本文介绍了使用 data.table 进行左连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个data.table:

答:

  A  B
1: 1 12
2: 2 13
3: 3 14
4: 4 15

乙:

   A  B
1: 2 13
2: 3 14

我有以下代码:

merge_test = merge(dataA, dataB, by="A", all.data=TRUE)

我明白了:

   A B.x B.y
1: 2  13  13
2: 3  14  14

但是,我希望最终合并表中的 dataA 中的所有行.有没有办法做到这一点?

However, I want all the rows in dataA in the final merged table. Is there a way to do this?

推荐答案

你可以试试这个:

# used data
# set the key in 'B' to the column which you use to join
A <- data.table(a = 1:4, b = 12:15)
B <- data.table(a = 2:3, b = 13:14, key = 'a') 

B[A]

这篇关于使用 data.table 进行左连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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