7.1 count()
What it does: Collapses the rows and counts the number of observations per group of values.
Count the number of values for each cut
:
diamonds %>% count(cut)
# is the same as
diamonds %>% group_by(cut) %>% count()
# is the same as
diamonds %>%
group_by(cut) %>%
summarize(n = n())
Count the number of values for each cut
and color
:
diamonds %>% count(cut, clarity)
# is the same as
diamonds %>% group_by(cut, clarity) %>% count()
diamonds %>% group_by(cut, clarity) %>% summarize(n = n())