Reputation: 1116
I have two tables
library(data.table)
X <- data.table(id=1:4, a=1, b=2, c=3, d=4, e=5, f=6)
I <- data.table(id=1:3, g=7, z=26)
and I would like to inner-join one column of I
into X
without specifying that I would like to keep a
to f
.
If I were to do a left-join, I could simply
X[I, g:=i.g, on="id"]
without specifying that a
to f
should be kept. I look for something similar for an inner join.
Upvotes: 0
Views: 71
Reputation: 6441
You could filter it out afterwards:
I[X, on = "id", nomatch = 0,][,!"z"]
id g a b c d e f
1: 1 7 1 2 3 4 5 6
2: 2 7 1 2 3 4 5 6
3: 3 7 1 2 3 4 5 6
Upvotes: 0
Reputation: 33548
look for something similar for an inner join?
Inner join can be done with:
X[I, on = "id", nomatch = 0]
Or
I[X, on = "id", nomatch = 0]
Upvotes: 0