Merging multiple data.tables
I am aware that one can merge (join) two data.table
with the merge
function or the [.data.table
function. However, if I have say 10, data.table
s and want to use do.call
to merge them all together, is there a function that would do this? Currently I resort to do.call(cbind, ...)
which works for only very special cases.
Not sure, but maybe (untested) :
Reduce(merge,list(DT1,DT2,DT3,...))
To flesh out the solution suggested by @Henk in comments, here is how to use this to select the all = TRUE
option in a concise formulation:
MergedDT = Reduce(function(...) merge(..., all = TRUE), List_of_DTs)
The latest version of data.table (1.10.5) has an easy syntax for table join, which can also be chained.
set(DT1, key)
set(DT2, key)
...
set(DT10, key)
DT_cmb <- DT1[DT2,][DT3,]...[DT10,]