使用select_和starts_with R [英] Using select_ and starts_with R

查看:239
本文介绍了使用select_和starts_with R的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么此代码不起作用?

Why doesn't this code work?

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

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

这是简化的示例.我正在尝试将select_命令传递给函数.

This is simplified example. I am trying to pass the select_ command to a function.

推荐答案

select()select_()之间的区别是它们对参数的非标准/标准评估.如果将starts_with()之类的函数用作select_()的参数,则应使用代字号引起来:

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'))

这将产生与通常使用select相同的输出:

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

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

有关更多信息,请参见关于非标准评估的小插曲:vignette("nse").

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

这篇关于使用select_和starts_with R的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆