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 do I get the complement of dtsub (i.e. the rows in dt which are not in dtsub)? Please generalize the solution to work for any data table.
Note: I'm sure this has been asked before, but my google searches came up empty. If this is a duplicate, please mark it as so and point me in the right direction.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With