Skip to main content
Module 4 · Lesson 2 of 28/18 in the course~22 min
Module lessons (2/2)

Mutations, group_by and summarise

Lesson preview7 hands-on exercises readyCourse R · Module 4 — Tidyverse and Pipeline dplyr

Derive columns with mutate() and calculate aggregate metrics by category using group_by() %>% summarise().

What you'll learn in this lesson

  • Derive new columns or transform existing columns vectorized with mutate().
  • Understand the Split–Apply–Combine paradigm by combining group_by() and summarise().
  • Count observations by category with n() and calculate multiple metrics in a single aggregation.
  • Distinguish between group_by() %>% summarise() (reduces to 1 row per group) and group_by() %>% mutate() (adds the group statistic while keeping all rows).

Overview

Most real-world analyzes follow the same two-step script: compute new derived fields for each row (mutate()) and then summarize the results by category, month, or segment (group_by() + summarise()).

mutate(df, nuova_col = espressione) keeps all rows and adds new columns at the end. You can even reuse a newly created column in the same mutate() call, separating it with a comma.

Sections covered in this lesson

  1. 1Create and transform columns with mutate()
  2. 2Explore the visual difference in the simulator
  3. 3Split–Apply–Combine with group_by() and summarise()
  4. 4Test yourself: guided exercises
  5. 5Concept check
Pro Lesson · Module 4 — Tidyverse and Pipeline dplyr

Unlock "Mutations, group_by and summarise" and the full Course R curriculum

Derive columns with mutate() and calculate aggregate metrics by category using group_by() %>% summarise().

Unlock all 7 hands-on exercises in this lesson plus every advanced WebAssembly module with automated checks.

  • Instant access to all advanced modules in Course R plus 17 more courses
  • Hands-on browser exercises with automated test suites and solutions
  • 14-day money-back guarantee processed via Paddle.com

14-day guarantee · Cancel anytimeModule 1, all 18 interactive games, and cheatsheets are always free.