Select rows from a data frame based on values in a vector
Similar to above, using filter
from dplyr
:
filter(df, fct %in% vc)
Have a look at ?"%in%"
.
dt[dt$fct %in% vc,]
fct X
1 a 2
3 c 3
5 c 5
7 a 7
9 c 9
10 a 1
12 c 2
14 c 4
You could also use ?is.element
:
dt[is.element(dt$fct, vc),]