Say I have this dataset
test <- data.table(X = rep(1, 3), Y = rep("a", 3))
which gives us
test
# X Y
#1: 1 a
#2: 1 a
#3: 1 a
I'm wondering why
test[, X[Y == "a"], keyby = .(X)]
gives
# X V1
#1: 1 1
#2: 1 NA
#3: 1 NA
Thank you in advance for your answers!