I want to do the following:
If say I am working with the iris
data which is of class data.frame
and I store a column name into a variable col <- "Species"
and I want to pull the following subset:
iris[iris$Petal.Width == 0.2, c("Sepal.Width", "Petal.Width", col)]
The code works and returns a table as expected. However, if I convert the data to a data.table
and run the same line of code, I get just the column names returned instead of the subset. Like this:
iris[iris$Petal.Width == 0.2, c("Sepal.Width", "Petal.Width", col)]
[1] "Sepal.Width" "Petal.Width" "Species"
How would I change the notation to get the same result from a data.table
?