r - dplyr Error: cannot modify grouping variable even when first applying ungroup -


i'm getting error fixes in related posts don't seem apply i'm using ungroup, though it's no longer needed (can switch grouping variable in single dplyr statement? see format column within dplyr chain). have no quotes in group_by call , i'm not applying functions act on grouped-by columns (r dplyr summarize_each --> "error: cannot modify grouping variable") i'm still getting error:

>  games2 = baseball %>% +  ungroup %>%  +  group_by(id, year) %>% +  summarize(total=g+ab, = ab+1, id = id)%>% +  arrange(desc(total)) %>% +  head(10) error: cannot modify grouping variable 

this baseball set comes plyr:

           id year stint team lg  g  ab  r  h x2b x3b hr rbi sb cs bb 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 

i loaded plyr before dplyr. other bugs check for? corrections/suggestions.

not clear doing. think following looking for:

games2 = baseball %>%      group_by(id, year) %>%       mutate(total=g+ab, = ab+1)%>%       arrange(desc(total)) %>%      head(10) > games2 source: local data frame [10 x 24] groups: id, year            id year stint team lg   g  ab   r   h x2b x3b hr rbi sb cs bb ibb hbp sh sf gidp total   1  aaronha01 1954     1  ml1 nl 122 468  58 131  27   6 13  69  2  2 28 39  na   3  6  4   13   590 469 2  aaronha01 1955     1  ml1 nl 153 602 105 189  37   9 27 106  3  1 49 61   5   3  7  4   20   755 603 3  aaronha01 1956     1  ml1 nl 153 609 106 200  34  14 26  92  2  4 37 54   6   2  5  7   21   762 610 4  aaronha01 1957     1  ml1 nl 151 615 118 198  27   6 44 132  1  1 57 58  15   0  0  3   13   766 616 5  aaronha01 1958     1  ml1 nl 153 601 109 196  34   4 30  95  4  1 59 49  16   1  0  3   21   754 602 6  aaronha01 1959     1  ml1 nl 154 629 116 223  46   7 39 123  8  0 51 54  17   4  0  9   19   783 630 7  aaronha01 1960     1  ml1 nl 153 590 102 172  20  11 40 126 16  7 60 63  13   2  0 12    8   743 591 8  aaronha01 1961     1  ml1 nl 155 603 115 197  39  10 34 120 21  9 56 64  20   2  1  9   16   758 604 9  aaronha01 1962     1  ml1 nl 156 592 127 191  28   6 45 128 15  7 66 73  14   3  0  6   14   748 593 10 aaronha01 1963     1  ml1 nl 161 631 121 201  29   4 44 130 31  5 78 94  18   0  0  5   11   792 632 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -