With data.table
You can choose between either nomatch=NA:
DT[c("A", "D"), on = "V4", nomatch = NA] #returns a row with "D" even if not found
or nomatch=NULL (same behaviour as dplyr):
DT[c("A", "D"), on = "V4", nomatch = 0] # keep only rows found in V4
With dplyr
filter(DF, V4 %in% c("A", "D")) # we only have equivalent to *nomatch=0* behaviour.
This returns the same output of
DT[c("A", "D"), on = "V4", nomatch = NA]
Reproducible example: