# HW 04 - Legos and instructors

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.

# Packages

In this assignment we will work with the tidyverse as usual ans the dsbox package for the data.

library(tidyverse)
library(dsbox)

## Lego sales

We have (simulated) data from lego sales in 2018 for a sample of customers who bought legos in the US. The dataset is called lego_sales. You can find descriptions of each of the variables in the help file for the dataset, which you can access by running ?lego_sales in your Console.

Answer the following questions using pipelines. For each question, state your answer in a sentence, e.g. “The first three common names of purchasers are …”.

1. What are the three most common first names of purchasers?

2. What are the three most common themes of lego sets purchased?

3. Among the most common theme of lego sets purchased, what is the most common subtheme?

Hint: Use the case_when() function.

1. Create a new variable called 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.

1. Which age group has purchased the highest number of lego sets.

Hint: You will need to consider quantity of purchases as well as price of lego sets.

1. Which age group has spent the most money on legos?

2. Come up with a question you want to answer using these data, and write it down. Then, create a data visualization that answers the question, and explain how your visualization answers the question.