I have an r dataframe
of the form:
cond.expr <- data.frame("label" = c("foo", "bar", "baz"),
"dim" = c("long","lat","long"),
"cond" = c("!=", ">", "=="),
"value" = c(NA, 0, 5))
I would like to read cond.expr
as a set of conditional expressions that can subsequently be applied to a data set. So if I have the following data set:
data <- data.frame("label" = c("foo", "foo", "bar", "bar","baz","baz"),
"long" = c(NA, 40,35,30,5,0),
"lat" = c(2,3,1,-1,0,4 ))
And apply something of the form filter(data, cond.expr)
I should get the following result:
label long lat
1 foo 40 3
2 bar 30 -1
3 baz 0 4
I wondered if some form of AST for the conditional expression would work here?