In previous versions of data.table
NA, NaN,Inf
values could exist in the key, but you could not join
or use binary scan to select these rows in a consistent manner with other key values.
See Select NA in a data.table in R and data.table subsetting by NaN doesn't work for examples of SO questions that deal with these issues (and you can trace the history through the answers to Feature requests within the data.table project)
Now, in 1.9.2 (and above) such things will work.
# an example data set
DT <- data.table(A = c(NA,NaN,Inf,Inf,-Inf,NA,NaN,1,2,3),
B =letters[1:10], key = 'A')
# selection using binary search
DT[.(Inf)]
# A B
# 1: Inf c
# 2: Inf d
DT[.(-Inf)]
# A B
# 1: -Inf e
# note that you need to use the right kind of NA
DT[.(NA_real_)]
# A B
# 1: NA a
# 2: NA f
DT[.(NaN)]
# A B
# 1: NaN b
# 2: NaN g
# grouping works
DT[,.N,by=A]
# A N
# 1: NA 2
# 2: NaN 2
# 3: -Inf 1
# 4: 1 1
# 5: 2 1
# 6: 3 1
# 7: Inf 2