Reputation: 2561
How can I subset iris_dt
using the vector subz
and achieve the same results as the line above
library(data.table)
iris_dt <- data.table(iris)
setindex(iris_dt, Sepal.Length)
setindex(iris_dt, Species)
iris_dt[.(6.7, 'virginica'), on = c('Sepal.Length', 'Species')]
subz <- c(6.7, 'virginica')
Upvotes: 0
Views: 55
Reputation: 33498
You need to set key, and avoid using c
because of data type coercion.
setkey(iris_dt, Sepal.Length, Species)
subz <- list(6.7, 'virginica')
iris_dt[subz]
Upvotes: 1