Photo by Daniel Cheung on Unsplash
This week we’ll do some data gymnastics to refresh and review what we learned over the past few weeks using (simulated) data from Lego sales in 2018 for a sample of customers who bought Legos in the US.
Open the project for this assignment in the course Posit Cloud workspace.
Open the Quarto document for the assignment and render it before making any changes. Make sure the document renders without errors.
This first render is a useful check that the project, packages, data, and files are all working correctly.
Before we introduce the data, let’s warm up with a simple exercise.
🧶 ✅ Throughout this assignment, remember to render your document regularly. After rendering, check the output to make sure your code, output, figures, and written responses appear as you expect.
If one of these packages is not installed, run the appropriate install.packages() command in your Console.
For example:
You only need to install a package once.
Do not put install.packages() commands in the code you render for your assignment.
The data can be found in the dsbox package, and it’s called lego_sales.
Since the dataset is distributed with the package, we don’t need to load it separately; it becomes available when we load the package.
You can find out more about the dataset by inspecting its documentation, which you can access by running ?lego_sales in the Console or using the Help menu in RStudio to search for lego_sales.
You can also find this information here.
Answer the following questions using pipelines.
For each question, state your answer in a sentence, e.g. “In this sample, the three most common first names of purchasers are …”.
Note that the answers to all questions are within the context of this particular sample of sales. You shouldn’t make inferences about the population of all Lego sales based on this sample.
✏️ What are the three most common first names of purchasers?
✏️ What are the three most common themes of Lego sets purchased?
✏️ Among the most common theme of Lego sets purchased, what is the most common subtheme?
🧶 ✅ Complete Exercises 1–3 and write your answers in sentences. Then render the document. Check that your code runs, the output appears correctly, and your written responses answer each question in the context of this sample.
Hint: Use the case_when() function.
age_group and group the ages into the following categories: “18 and under”, “19 - 25”, “26 - 35”, “36 - 50”, “51 and over”.Hint: You will need to consider quantity of purchases.
Hint: You will need to consider quantity of purchases as well as price of Lego sets.
Hint: The str_sub()
function will be helpful here!
✏️ Which Lego theme has made the most money for Lego?
✏️ Which area code has spent the most money on Legos?
In the US, the area code is the first 3 digits of a phone number.
🧶 ✅ Complete Exercises 4–8 and render the document. Check that your new age_group variable is created correctly, each pipeline runs, and your written responses for Exercises 5–8 agree with the output produced by your code.
🧶 ✅ Complete your question, visualization, and written interpretation for Exercise 9. Then render your document one final time. Read through the rendered document from beginning to end. Make sure all of your code runs, all output and figures appear correctly, and every exercise marked with ✏️ includes a written response before you submit your work.