简体   繁体   English

将NSE传递到dplyr的过滤器

[英]Passing NSE to dplyr's filter

library(dplyr)

specials <- names(mtcars)[1:2]
specials[1]

i=1

setup is complete, this works... 设定完成,可以运作...

mtcars %>%
  select_(specials[i], ~gear, ~carb)

why does the nse fail on adding the filter? 为什么nse添加过滤器失败?

mtcars %>%
  select_(specials[i], ~gear, ~carb) %>%
  filter_(specials[i] == 21.4)

We may need the interp 我们可能需要interp

library(lazyeval)
library(dplyr)
mtcars %>%
      select_(specials[i], ~gear, ~carb) %>% 
      filter_(interp(~nm == 21.4, nm = as.name(specials[1])))
#  mpg gear carb
#1 21.4    3    1
#2 21.4    4    2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM