In order to perform a left join to df1
and add H
column from df2
, you can combine binary join with the update by reference operator (:=
)
setkey(setDT(dt1), A)
dt1[dt2, H := i.H]
See here and here for detailed explanation on how it works
With the devel version (v >= 1.9.5) we could make it even shorter by specifying the key
within setDT
(as pointed by @Arun)
setDT(dt1, key = "A")[dt2, H := i.H]
Edit 24/7/2015
You can now run a binary join using the new on
parameter without setting keys
setDT(dt1)[dt2, H := i.H, on = c(A = "E")]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…