[datatable-help] Update table from other table

Juan Manuel Truppia jmtruppia at gmail.com
Thu Sep 11 22:16:04 CEST 2014


What is the best data.table way of doing something similar to UPDATE FROM
in SQL?

I used to do something like

dta = data.table(idx = c(1, 2, 3), a = runif(3), key = "idx")
dtb = data.table(idx = c(1, 3), b = runif(3), key = "idx")
dta[dtb, b := b]

However, after the 1.9.3 and the explicit .EACHI, it fails sometimes, but I
can't determine when.

So, just to be sure, I do

dta[dtb, b := b, .EACHI = TRUE, nomatch = 0]

Is the .EACHI and the nomatch necessary?

In this case, I want the row with idx 1 and 3 (the matching ones) to end
with a b value from the matching b column in dtb, and the row with idx 2
(the one that isn't in dtb) to end up with NA in column b.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20140911/eca2694f/attachment.html>


More information about the datatable-help mailing list