Module lessons (2/2)
Mutations, group_by and summarise
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()andsummarise(). - 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) andgroup_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
- 1Create and transform columns with
mutate() - 2Explore the visual difference in the simulator
- 3Split–Apply–Combine with
group_by()andsummarise() - 4Test yourself: guided exercises
- 5Concept check
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.