dplyr:group_by和group_by_函数之间有什么区别? [英] dplyr: whats the difference between group_by and group_by_ functions?

查看:373
本文介绍了dplyr:group_by和group_by_函数之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法弄清楚基于下划线的函数对于group_by_()函数。

I can't figure out what the underscore-based function is for the group_by_() function.

从group_by帮助中:

From the group_by help:

by_cyl <- group_by(mtcars, cyl)  
summarise(by_cyl, mean(disp), mean(hp))  

产生预期:

Source: local data frame [3 x 3]  
    cyl mean(disp)  mean(hp)
1   4   105.1364  82.63636
2   6   183.3143 122.28571
3   8   353.1000 209.21429

但是这样:

by_cyl <- group_by_(mtcars, cyl)  

产生错误:

"Error in as.lazy_dots(list(...)) : object 'cyl' not found"  

所以我的问题是下划线版本是做什么的?而且,在什么情况下,我想使用它,而不是常规?

So my question is what does the underscore version do? And also, under what circumstances would I want to use it, rather than the "regular" one?

谢谢

推荐答案

非标准评估小插曲在这里有帮助: http://cran.r-project.org/web/packages/dplyr/vignettes/nse.html

The dplyr Non-Standard Evaluation vignette helps here: http://cran.r-project.org/web/packages/dplyr/vignettes/nse.html


Dplyr在所有最重要的
单表动词中使用非标准评估(NSE):filter(),mutate(),summarize(),arrange(),
select ()和group_by()。 NSE非常重要,不仅可以节省您的输入,而且还可以将
R代码翻译成SQL。然而,虽然NSE是很好的交互式使用它是
难以编程。这个小插图描述了如何在dplyr中选择退出
NSE,而只依靠SE(连同一点
引用)。

Dplyr uses non-standard evaluation (NSE) in all of the most important single table verbs: filter(), mutate(), summarise(), arrange(), select() and group_by(). NSE is important not only to save you typing, but for database backends, is what makes it possible to translate your R code to SQL. However, while NSE is great for interactive use it’s hard to program with. This vignette describes how you can opt out of NSE in dplyr, and instead rely only on SE (along with a little quoting).

...

使用NSE的dplyr中的每个函数都有一个使用SE的版本。
有一个一致的命名方案:SE是NSE名称,$ on
结束。例如,SE版本的summarize()是summarise_(),
的这个SE版本的arrange()是arrange_()。这些功能与其NSE表兄弟的工作非常的非常的
,但输入必须是引用

Every function in dplyr that uses NSE also has a version that uses SE. There’s a consistent naming scheme: the SE is the NSE name with _ on the end. For example, the SE version of summarise() is summarise_(), the SE version of arrange() is arrange_(). These functions work very similarly to their NSE cousins, but the inputs must be "quoted"

这篇关于dplyr:group_by和group_by_函数之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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