我可以将列字符串传递给dplyr的过滤器函数吗?

时间:2017-04-12 04:32:12

标签: r dplyr

我想参数化dplyr的过滤功能。例如 而不是

mtcars %>% filter(mpg <20)

我想要一个函数,我可以传递列索引,以便我可以

a <- c(4,6)
df <- mtcars %>% filter(cyl %in% a) #- This works

但是

df <- mtcars %>% filter_("cyl %in% a") #Gives 'a' not found

  df <- mtcars %>% filter_("cyl %in% 'a'") # gives 0 rows

我将使用一个变量,我正在使用“cyl”。 我错过了什么?

0 个答案:

没有答案