The data table J(7, 'f') is literally a single-line data.table that you connect to your data.table . When you call x[i] , you look at each line in i and find all matches for that in x . By default, NA used for rows in i that don't match anything, which is easier to see by adding another column to the DT :
DT <- data.table(A=7:3,B=letters[5:1],C=letters[1:5]) setkey(DT, A, B) DT[J(7,"f")] # ABC # 1: 7 f NA
What you see is the only line in J that doesn't match anything in DT . To prevent data.table from reporting a mismatch, you can use nomatch=0
DT[J(7,"f"), nomatch=0]
source share