jamborta
jamborta

Reputation: 5210

outer join data.table R

Just wondering if there is an efficient way to do outer joins with data table such as

a <- data.table(a=c(1,2,3),b=c(3,4,5))
b <- data.table(a=c(1,2),k=c(1,2))
merge(a,b,by="a",all.x=T)

this works fine, but it is not as efficient as the inner join with bigger data, as the following runs very fast, but the above is really slow.

setkey(a,a)
setkey(b,a)
a[b,]

Upvotes: 16

Views: 14985

Answers (1)

Justin
Justin

Reputation: 43245

b[a,] is the "outer join" you're looking for.

Take a look at ?merge.data.table for more specifics.

Upvotes: 11

Related Questions