In this lesson, you will learn to:
Reshape your dataset by pivoting longer or wider
Use mutating joins and filtering joins to combine different datasets with related information.
Decompose a complicated problem into small, manageable steps.
Please read the Decomposition and Hidden Assumptions sections only - stop when you reach the beginning of the Turn it into a recipe (let’s make an algorithm) section.
(A few more tricks for data cleaning/wrangling, if you’re interested.)
Question 1: Create a new dataset called cereals_3
, that has three columns:
The name of the cereal
A column called “Nutrient” with values protein
, fat
, or fiber
.
A column called “Amount” with the corresponding amount of the nutrient.
Question 2: Why didn’t we have to add a rowid
to pivot wider in this case?
Cereals in this dataset are placed on shelf 1, 2, or 3. We would like to know if these cereal placements correspond to different nutritional values; for example, perhaps sugary cereals made for children are on a lower shelf.
Create a new dataset called cereals_4
, that has four columns:
The name of the manufacturer
The mean amount of sugar in cereals on shelf 1.
The mean amount of sugar in cereals on shelf 2.
The mean amount of sugar in cereals on shelf 3.