How to get an addition to a subset of a data table?

set.seed(77)
dt<-data.table(a=seq(1,5))
> dt
   a
1: 1
2: 2
3: 3
4: 4
5: 5

dtsub<-dt[sample(5,3)]
> dtsub
   a
1: 2
2: 3
3: 4

How to get dtsub padding (i.e. strings in dt that are not in dtsub)? Please generalize the solution to work in any data table.

Note. I am sure this was asked earlier, but my Google searches were empty. If this is a duplicate, mark it that way and point me in the right direction.

+3
source share
1 answer
library(data.table)
set.seed(77)
dt<-data.table(a=seq(1,5))
dtsub<-dt[sample(5,3)]

setkey(dt,a)
setkey(dtsub,a)

dt[!dtsub]
#   a
#1: 1
#2: 5
+7
source

All Articles