- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我无法弄清楚 group_by_() 函数的基于下划线的函数是什么。
从 group_by 帮助:
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"
最佳答案
dplyr 非标准评估小插图在此处提供帮助:http://cran.r-project.org/web/packages/dplyr/vignettes/nse.html
备注 : 上面的链接现在已经过时了,但是可以在该包的github页面上找到相同的信息。
https://github.com/tidyverse/dplyr/blob/34423af89703b0772d59edcd0f3485295b629ab0/vignettes/nse.Rmd
Dplyr uses non-standard evaluation (NSE) in all of the most importantsingle 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 yourR code to SQL. However, while NSE is great for interactive use it’shard to program with. This vignette describes how you can opt out ofNSE in dplyr, and instead rely only on SE (along with a littlequoting).
...
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 _ onthe end. For example, the SE version of summarise() is summarise_(),the SE version of arrange() is arrange_(). These functions work verysimilarly to their NSE cousins, but the inputs must be “quoted”
关于r - dplyr:group_by 和 group_by_ 函数有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28667059/
我正在编写一个函数,要求用户在函数调用中定义一个或多个分组变量。然后使用 dplyr 对数据进行分组,如果只有一个分组变量,它会按预期工作,但我还没有想出如何使用多个分组变量进行分组。 例子: x %
我想创建一个简单的函数,它将使用 summarise_ 和 group_by_ 函数。我知道非标准评估存在问题,但我可以修复它。 library(dplyr) test_function %
我无法弄清楚 group_by_() 函数的基于下划线的函数是什么。 从 group_by 帮助: by_cyl <- group_by(mtcars, cyl) summarise(by_cyl,
我有一些代码将分组变量指定为字符串。 group_var % group_by_(group_var) %>% summarize(mean_mpg = mean(mpg)) 关于
我是一名优秀的程序员,十分优秀!