A Beginner's Introduction to R Through the Tidyverse

Section 4 of 5

Summarising Data

The tidyverse offers a variety of ways to summarise data.

Generating summaries with summarise and group_by

In this section, we will calculate a summary value for a column. We will then group the output based on another column.

For example, we will get the mean value of mpg for each of the cylinders. There are 3 unique values in the cylinder column (4, 6, 8).

In tidyverse, we can use a summarise or summarize function. In the example below, we take the mean of mpg, by specifying mean(mpg) and then we save it as average_mpg.

summarise

Grouping and Summarising

Instead of doing this three times, we can get a single table. There may be uses for getting the values separately. The group_by function offers a simple way to get things all at once.

summarise

Exercise

In the mtcars dataset, calculate the mean value of the weight (wt) grouped by the carb column. Try group_by(carb) and average_weight = mean(wt).

summarise

Loading...

Loading...

Go to Next Section Conclusion →

Sections in this course

A Beginner's Introduction to R Through the Tidyverse

0%0/9