Skip to content

Instantly share code, notes, and snippets.

@reinholdsson
Created July 11, 2014 12:58
Show Gist options
  • Save reinholdsson/67008ee3e671ff23b568 to your computer and use it in GitHub Desktop.
Save reinholdsson/67008ee3e671ff23b568 to your computer and use it in GitHub Desktop.
R: merge multiple data tables
library(data.table)
x <- data.table(A = c(3,2,1), B = 4:6)
y <- data.table(A = 1:4, C = 5:8)
z <- data.table(A = 2:3, D = 5:6)
tbls <- list(x, y, z)
lapply(tbls, function(i) setkey(i, A))
merged <- Reduce(function(...) merge(..., all = T), tbls)
@bfatemi
Copy link

bfatemi commented May 4, 2016

Awesome, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment