Created
July 11, 2014 12:58
-
-
Save reinholdsson/67008ee3e671ff23b568 to your computer and use it in GitHub Desktop.
R: merge multiple data tables
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome, thanks!