[datatable-help] Update on auto-join

Stefano Grioni sgrioni at chicagobooth.edu
Mon Nov 9 02:43:36 CET 2015


Hello,

As I was reading through the vignette on data handling and joins, it was
not immediately evident to me how to do an update on auto-join using only
data table.

I have managed to do what I need using by using SQL, but I don't find it
particularly elegant and performance will probably be terrible on large
datasets:

tmp <- sqldf("select a.Field1, a.Field2, a.Field3, b.Output from MyDataset
a INNER JOIN MyDataset b on a.Field1 =b.Field1 and *a.Field2 = b.Field2+1*
and a.Field3=b.Field3")
tmp <- as.data.table(tmp)
setkey(MyDataset, Field1, Field2, Field3)
setkey(tmp, Field1, Field2, Field3)
MyDataset[tmp,Field4 := i.Output, nomatch=0]

I tried to do the same using twice the same data frame but I can't see how
to integrate the join condition on Field2 (see above).

Is there an elegant way to address this?

Many thanks

Stefano
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/datatable-help/attachments/20151109/3742e8ca/attachment-0001.html>


More information about the datatable-help mailing list