亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

dplyr:如何在函數內使用group_by?

dplyr:如何在函數內使用group_by?

手掌心 2019-11-30 10:38:25
我想dplyr::group_by在另一個函數中使用函數,但是我不知道如何將參數傳遞給該函數。有人可以提供一個有效的例子嗎?library(dplyr)data(iris)iris %.% group_by(Species) %.% summarise(n = n()) # ## Source: local data frame [3 x 2]##      Species  n## 1  virginica 50## 2 versicolor 50## 3     setosa 50mytable0 <- function(x, ...) x %.% group_by(...) %.% summarise(n = n())mytable0(iris, "Species") # OK## Source: local data frame [3 x 2]##      Species  n## 1  virginica 50## 2 versicolor 50## 3     setosa 50mytable1 <- function(x, key) x %.% group_by(as.name(key)) %.% summarise(n = n())mytable1(iris, "Species") # Wrong!# Error: unsupported type for column 'as.name(key)' (SYMSXP)mytable2 <- function(x, key) x %.% group_by(key) %.% summarise(n = n())mytable2(iris, "Species") # Wrong!# Error: index out of bounds
查看完整描述

3 回答

  • 3 回答
  • 0 關注
  • 989 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號