Doing a merge between a populated data.table and another one that is empty introduces one NA row in the resulting data.table:
a = data.table(c=c(1,2),key='c')
b = data.table(c=3,key='c')
b=b[c!=3]
b
# Empty data.table (0 rows) of 1 col: c
merge(a,b,all=T)
# c
# 1: NA
# 2: 1
# 3: 2
Why? I expected that it would return only the rows of data.table a
, as it does with merge.data.frame:
> merge.data.frame(a,b,all=T,by='c')
# c
#1 1
#2 2