pass grouped dataframe to own function in dplyr

ぐ巨炮叔叔 提交于 2019-12-01 04:58:00

For those who get here from google. Let's say you wrote your own print function.

printFunction <- function(dat) print(dat)
df <- data.frame(a = 1:6, b = 1:2)

As it was asked here

df %>% 
    group_by(b) %>% 
    printFunction(.)

prints entire data. To get dplyr print multiple tables grouped by, you should use do

df %>% 
    group_by(b) %>% 
    do(printFunction(.))
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!