Track 14 · Practical Data Analysis · Lesson 6 of 11

Grouping and aggregation

Summarise a variable within groups, build pivot-style tables of counts and percentages, and combine group results correctly.

30 minIntermediate8 graded exercisesMembers

A regional manager asks: which branch sells the most, and do loyalty-card members spend more per visit? Both questions are answered by the same move — split the transactions into groups, summarise each group, and put the results side by side — but the two answers need different summaries, and a careless combination of group averages gives the wrong company-wide figure.

Grouping (also called aggregation or split–apply–combine) means: split the rows by the values of a grouping variable (store, customer type, month), apply a summary to each group (count, total, mean, median, percentage), and combine the results into one small table. Almost every business report is built this way — a pivot table in a spreadsheet is the same idea.

Included with a Formula Quest membership

It has 8 graded exercises with feedback, hints and worked solutions. After it you will be able to:

  • Split rows by a grouping variable and choose the summary (count, total, mean/median, percentage) that answers the question
  • Recover group totals as n × mean and combine group means with weights n
  • Read two-way tables with row or column percentages, choosing the direction deliberately
  • Report group summaries with their sizes and check for rows missing a group label