I have a data.table in R like below
col1 col2 col3
A AA 1
C BB 2
DT <- data.table(col1=c('A','C'), col2=c('AA','BB'), col3=c(1,2))
I want to filter the data.table such that col1 is in A/B/C
and col2 is in AA/CC/
. If I know the number of columns to search is fixed then I can do
DT[Vectorize(grepl)(col1, "A/B/C") & Vectorize(grepl)(col2, "AA/CC/")]
- How can I filter if the number of columns to filter on is dynamic?
- Is there a way to increase the speed of this filter?