In R: subset or dplyr::filter with variable from vector
df <- data.frame(a=LETTERS[1:4], b=rnorm(4) ) vals <- c("B","D") I can filter/subset df with values in val with: dplyr::filter(df, a %in% vals) subset(df, a %in% vals) Both gives: a b 2 B 0.4481627 4 D 0.2916513 What if I have a variable name in a vector, e.g.: > names(df)[1] [1] "a" Then it doesnt work - I guess because its quoted dplyr::filter(df, names(df)[1] %in% vals) [1] a b <0 rows> (or 0-length row.names) How do you do this ? UPDATE ( what if its dplyr::tbl_df(df) ) Answers below work fine for data.frames, but not for dplyr::tbl_df wrapped data: df<-dplyr::tbl_df(df) dplyr::filter(df,