edwindj · GitHub

Hi,

Currently count does not 'respect' group_by statements, which is not intuitive (I observed this multiple times when training novice R/dplyr users).

Example:

data(diamonds, package="ggplot2")
diamonds %>% count(cut)
diamonds %>% group_by(cut) %>% count # gives total count, not group_by
# Source: local data frame [1 x 1]
#
# n
# (int)
#1 53940
diamonds %>% group_by(cut) %>% count(clarity) # gives count by clarity (but not cut)
# Source: local data frame [8 x 2]
# 
# clarity     n
# (fctr) (int)
#1      I1   741
#2     SI2  9194
#3     SI1 13065
#4     VS2 12258
# ...

I know that one way to 'fix' this is to use tally and to expand the group_by statement, however I will submit a PR in which count expands the current grouping.

Read the original on github.com ↗