... dplyr verbs: group


Once again we assume that you've got the dataframe set up appropriately.


# This command makes sure that the chickweight dataframe is clean.
df <- ChickWeight %>% ungroup() %>% as.data.frame()

We see how we can combine verbs to query the data.

df %>%
  filter(Time <= 10) %>%
  group_by(Time, Diet) %>%
  summarise(mean_weight = mean(weight), var_weight = var(weight), n = n())

Note that the image used in this video can originally be found over at software carpentry. It's a pretty cool learning source if you haven't seen it yet!

Feedback? See an issue? Something unclear? Feel free to mention it here.

If you want to be kept up to date, consider signing up for the newsletter.