R计数函数中的dplyr包问题无法识别数据框内的组

时间:2016-10-18 03:09:20

标签: r count dplyr

我正在重新运行以前使用dplyr包运行的旧代码。它现在停留在我计算一个名为mutated_df的数据框中每个组中特定日期出现的次数的位置,其形式如下:

> mutated_df
Source: local data frame [196,077 x 3]
Groups: Date [138]

Date Value     group
   (date) (int)    (fctr)
1  2016-01-28    84 upper-mid
2  2016-01-28   125       max
3  2016-01-28    78       mid
4  2016-01-28    NA        NA
5  2016-01-28    86 upper-mid
6  2016-01-28    NA        NA
7  2016-01-28   113     upper
8  2016-01-28    NA        NA
9  2016-01-28    95 upper-mid
10 2016-01-29   101     upper
..        ...   ...       ...

为了得到我的计数:

c <- count(mutated_df, Date, group)

但得到错误:

Error in count(mutated_df, Date, group) : object 'group' not found

mutated_df的结构更详细地说是:

structure(list(Date = structure(c(16895, 16895, 16895, 16895, 
16895, 16895, 16895, 16895, 16895, 16895), class = "Date"), Value =     
c(89.5999985, 93.1999969, 86, 91.4000015, 91.4000015, 91.4000015, 84.1999969, 
84.1999969, 89.5999985, 93.1999969), group = structure(c(4L, 
5L, 3L, 5L, 5L, 5L, 3L, 3L, 4L, 5L), .Label = c("lower", "lower-mid", 
"mid", "upper-mid", "upper", "max"), class = "factor")), .Names = c("Date", 
"Value", "group"), class = c("grouped_df", "tbl_df", "tbl", "data.frame"
), row.names = c(NA, -10L), vars = list(Date), drop = TRUE, indices = list(
    0:9), group_sizes = 10L, biggest_group_size = 10L, labels = structure(list(
    Date = structure(16895, class = "Date")), class = "data.frame", row.names = c(NA, 
-1L), vars = list(Date), drop = TRUE, .Names = "Date"))

为什么这个错误刚出现在曾经运行良好的代码中的任何想法?谢谢!

0 个答案:

没有答案