I have noticed that data.frame
and data.table
row subsetting differ when it comes to NA values.
Clean code:
DF <- data.frame(COL1 = c(1, 2, NA))
DF[DF$COL1 == 1, ]
DF[DF$COL1 != 1, ]
DT <- data.table::data.table(COL1 = c(1, 2, NA))
DT[COL1 == 1, ]
DT[COL1 != 1, ]
Code with results:
> DF <- data.frame(COL1 = c(1, 2, NA))
> DF[DF$COL1 == 1, ]
[1] 1 NA
> DF[DF$COL1 != 1, ]
[1] 2 NA
> DT <- data.table::data.table(COL1 = c(1, 2, NA))
> DT[COL1 == 1, ]
COL1
1: 1
> DT[COL1 != 1, ]
COL1
1: 2
Is there any special reasons for that?
Thanks