【发布时间】:2015-05-14 17:11:28
【问题描述】:
我收到此错误,但相关帖子中的修复似乎不适用我正在使用取消分组,尽管不再需要它(can I switch the grouping variable in a single dplyr statement? 但请参阅Format column within dplyr chain)。此外,我的 group_by 调用中没有引号,并且我没有应用任何作用于分组列 (R dplyr summarize_each --> "Error: cannot modify grouping variable") 的函数,但我仍然收到此错误:
> games2 = baseball %>%
+ ungroup %>%
+ group_by(id, year) %>%
+ summarize(total=g+ab, a = ab+1, id = id)%>%
+ arrange(desc(total)) %>%
+ head(10)
Error: cannot modify grouping variable
这是 plyr 自带的棒球套装:
id year stint team lg g ab r h X2b X3b hr rbi sb cs bb so ibb hbp sh sf gidp
4 ansonca01 1871 1 RC1 25 120 29 39 11 3 0 16 6 2 2 1 NA NA NA NA NA
44 forceda01 1871 1 WS3 32 162 45 45 9 4 0 29 8 0 4 0 NA NA NA NA NA
68 mathebo01 1871 1 FW1 19 89 15 24 3 1 0 10 2 1 2 0 NA NA NA NA NA
99 startjo01 1871 1 NY2 33 161 35 58 5 1 1 34 4 2 3 0 NA NA NA NA NA
102 suttoez01 1871 1 CL1 29 128 35 45 3 7 3 23 3 1 1 0 NA NA NA NA NA
106 whitede01 1871 1 CL1 29 146 40 47 6 5 1 21 2 2 4 1 NA NA NA NA NA
我在dplyr 之前加载了plyr。其他要检查的错误?感谢您的任何更正/建议。
【问题讨论】: