I have to deal with huge data sets, that is why I have to use data.table package. I would like to pick only rows which have appropriate values in given column.
dt <- data.table(a = rep(c("A", "B", "C"), 3),
b = 1:9)
n <- c("A", "C")
What I can do:
dt[ a %in% n]
a b
1: A 1
2: C 3
3: A 4
4: C 6
5: A 7
6: C 9
What if I do not know name of column before and get it from function as string? I tried:
dt[ "a" %in% n]
Empty data.table (0 rows) of 2 cols: a,b
dt[ "a" %in% n, with = F]
Error in `[.data.table`(dt, "a" %in% n, with = F) :
j must be provided when with=FALSE
dt[ as.name("a") %in% n ]
Error in match(x, table, nomatch = 0L) :
'match' requires vector arguments
Question - is it possible to use string in such a task?