I was hoping for some help on passing a string of filter criteria into a data.table. I've tried all manners of parse and eval, and can't seem to figure it out
I tried to recreate an example using the iris dataset:
iris <- data.table(iris)
vars <- 'setosa'
filter <- 'Species == vars & Petal.Length >= 4'
data <- iris[filter,
list(sep.len.tot = sum(Sepal.Length), sep.width.total = sum(Sepal.Width)),
by = 'Species']
So the filter string has a vars variable within it (that changes based on a loop). I'm trying to filter the data based on the filter string.
Is there a data.table specific method of evaluating the string?
Hope that makes sense!