使用FUN = count调用聚合函数时出现找不到对象的错误

时间:2019-04-17 17:18:16

标签: r

调用聚合函数时,出现错误Error in match.fun(FUN) : object 'count' not found

我尝试过更新R以及使用plyr软件包,但后来却没有给我想要的结果。

aggregate(soybean.table, by=list(soybean$seed.tmt, soybean$germination), FUN=count)

1 个答案:

答案 0 :(得分:0)

countdplyrplyr中的一个功能。 dplyr/plyr count需要data.frame/data.table/tbl_df作为输入。使用aggregate时,查找行数的选项将是length

aggregate(soybean.table, by=list(soybean$seed.tmt, soybean$germination), FUN= length)

作为可重复的示例

aggregate(mtcars, list(mtcars$vs, mtcars$am), FUN = length)

最好选择一个列并按感兴趣的列进行分组,因为length可以是相同的,只要分组变量是相同的,例如

aggregate(mpg ~ vs + am, mtcars, FUN = length)

或者使用其他列名称

aggregate(cbind(Count = seq_along(mpg))~ vs + am, mtcars, FUN = length)