【问题标题】:Getting object not found error when calling Aggregate Function with FUN=count使用 FUN=count 调用聚合函数时出现找不到对象错误
【发布时间】:2019-04-17 17:18:16
【问题描述】:

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

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

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

【问题讨论】:

  • 我认为你需要 length 而不是 count count 来自 dplyr,它需要一个 data.framae 作为输入
  • @akrun 把它当作一个答案并发布它,因为它有效。

标签: r


【解决方案1】:

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多