Is there a fast way to get indices of a value from data.table? I have set a column as key, however, I struggle to find efficient way to get its indices?
x <- sample(letters, 200, replace = TRUE)
y <- rnorm(200)
DT <- data.table(x, y, key = "x")
df <- data.frame(x, y)
Execution time:
system.time(for(i in 1:1000) DT[.("g"), which= TRUE]) # 0.3 sec
system.time(for(i in 1:1000) which(DT$x == "g")) # 0.004 sec
system.time(for(i in 1:1000) which(df$x == "g")) # 0.004 sec
I guess currently it is not able to use key for finding index in the last two execution. Is there any fast way?