Using select_ and starts_with R

后端 未结 1 909
你的背包
你的背包 2021-01-29 08:24

Why doesn\'t this code work?

mtcars %>% select_(\"starts_with(\'d\')\")

Error in eval(expr, envir, enclos) : could not find function \"starts_with\"
<         


        
相关标签:
1条回答
  • 2021-01-29 09:09

    The difference between select() and select_() is their non-stadard / standard evaluation of the argument. If a function like starts_with() is used as an argument of select_() it should be quoted with a tilde:

    library(dplyr)
    mtcars %>% select_(~starts_with('d'))
    

    This yields the same output as the normal use of select:

    identical(mtcars %>% select_(~starts_with('d')), mtcars %>% select(starts_with('d')))
    #[1] TRUE
    

    For more information see the vignette on non-standard evaluation: vignette("nse").

    0 讨论(0)
提交回复
热议问题