Data science

Stage 1 · Lesson 5 of 7

Grouping and summarising

R for data: the tidyverse

Grouping splits rows by one or more columns, computes a summary for each group, and combines the results into a new table: people call it split, apply, combine. It is how you get orders per region, average score per or revenue per month.

In it is groupby followed by agg; in R it is group_by followed by summarise. Name your output columns clearly and count rows in each group alongside every average, so a group of 3 is not mistaken for one of 3,000.

Common trapaveraging averages: the mean of per-region means is not the overall mean when regions have different numbers of rows, so compute overall figures from the raw rows or weight by group size.

A question to check yourself, an AI practice session and 1 cheat sheet entry come with the full roadmap. Unlock

Resources for this stage

Start with

  • BookFree
    R for Data Science (2e)

    Wickham, Çetinkaya-Rundel, Grolemund · Beginner

    Free online: the Whole game and Transform chapters teach the tidyverse verbs in the order you need them

Practise

  • Pick one dataset on a topic you care about and repeat every operation in this stage on it

Keep handy

  • Set up projects, the console and Quarto documents properly before you start

Mark this stage as not done?