lets say I have a data.table with columns A, B and C
I\'d like to write a function that applies a filter (for example A>1) but \"A\" needs to be dynamic (the functio
If your data is
a <- c(1:9)
b <- c(10:18)
# create a data.frame
df <- data.frame(a,b)
# or a data.table
dt <- data.table(a,b)
you can store your condition(s) in a variable x
x <- quote(a >= 3)
and filter the data.frame using dplyr
(subsetting with [] won't work)
library(dplyr)
filter(df, x)
or using data.table
as suggested by @Frank
library(data.table)
dt[eval(x),]