2

我认为 dplyr 很棒。但是,我最近更新了软件包,似乎汇总不再按组汇总。升级前用于按组汇总的类似于以下代码的内容:

iris_tdt <- tbl_dt(iris)
iris_tdt %.% group_by(Species) %.% summarise(avg_petal_width = mean(Petal.Width))

  avg_petal_width
1        1.199333

这用于输出带有 Species 和 avg_petal_width 的表。现在 Species 列似乎已被删除,并且 avg_petal_width 聚合为单个值。group_by 似乎正在工作,所以我猜这是摘要的问题。

grp <- group_by(iris_tdt,Species)
groups(grp)

[[1]]
Species

甚至 Vignette 中的示例也无法正常工作。

hflights_df <- tbl_df(hflights)
planes <- group_by(hflights_df, TailNum)
delay <- summarise(planes,
  dist = mean(Distance, na.rm = TRUE),
  delay = mean(ArrDelay, na.rm = TRUE))

delay
      dist    delay
1 787.7832 7.094334

任何建议将不胜感激。

packageDescription("dplyr")$Version #--> 0.1.2
R.version.string #--> "R version 3.0.2 (2013-09-25)"
4

1 回答 1

5

You may have another summarise function, probably from the plyr package.

# Works
library(dplyr)
iris_tdt <- tbl_dt(iris)
iris_tdt %.% 
  group_by(Species) %.% 
  summarise(avg_petal_width = mean(Petal.Width))

# No longer works...
library(plyr)
iris_tdt <- tbl_dt(iris)
iris_tdt %.% 
  group_by(Species) %.% 
  summarise(avg_petal_width = mean(Petal.Width))

If you really need both packages, you can try to load dplyr last, or prefix all the affected functions (summarise, mutate, etc.) with their namespace (dplyr::summarise, etc.)

于 2014-03-11T15:12:50.570 回答