Suppose I have two datasets that I want to left-join,
i <- data.table(id=1:3, k=7:9, l=7:9, m=7:9, n=7:9)
and
x <- data.table(id=c(1,2), x=c(10,20))
To left-join, keeping all lines in i
, I execute
x[i, .(id=i.id, k=i.k, l=i.l, m=i.m, n=i.n, x=x.x), on=.(id=id)]
but I wonder whether there is an easier and more efficient way that makes it unnecessary to spell out all the columns from i
.
For example, in the reverse case (that is, when I want to keep all columns from i
), I could use the :=
operator, as in x[i, k:=i.k, on=.(id=id)]
. My understanding is that this makes things also more efficient because columns do not need to be copied. Is there something comparable for this case?