调用聚合函数时,出现错误Error in match.fun(FUN) : object 'count' not found
我尝试过更新R以及使用plyr软件包,但后来却没有给我想要的结果。
aggregate(soybean.table, by=list(soybean$seed.tmt, soybean$germination), FUN=count)
答案 0 :(得分:0)
count
是dplyr
和plyr
中的一个功能。 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)