Exam 1 review
Suggested answers
-
b, c, f, g -
The
blizzard_salarydataset has 409 rows.The
percent_incrvariable is numerical and continuous.The
salary_typevariable is categorical.
Figure 1 - A shared x-axis makes it easier to compare summary statistics for the variable on the x-axis.
c - It’s a value higher than the median for hourly but lower than the mean for salaried.
b - There is more variability around the mean compared to the hourly distribution.
a, b, e - Pie charts and waffle charts are for visualizing distributions of categorical data only. Scatterplots are for visualizing the relationship between two numerical variables.
c -
mutate()is used to create or modify a variable.a -
"Poor", "Successful", "High", "Top"b - Option 2. The plot in Option 1 shows the number of employees with a given performance rating for each salary type while the plot in Option 2 gives the proportion of employees with a given performance rating for each salary type. In order to assess the relationship between these variables (e.g., how much more likely is a Top rating among Salaried vs. Hourly workers), we need the proportions, not the counts.
There may be some
NAs in these two variables that are not visible in the plot.The proportions under Hourly would go in the Hourly bar, and those under Salaried would go in the Salaried bar.
c -
filter(salary_type != "Hourly" & performance_rating == "Poor")- There are 5 observations for “not Hourly” “and” Poor.a -
arrange()- The result is arranged in increasing order ofannual_salary, which is the default forarrange().c, d, e, f.
-
Part 1: The following should be fixed:
There should be a
|after#beforelabelThere should be a
:after label, not=There shouldn’t be a space in the chunk label, it should be
plot-blizzardThere should be spaces after commas in the code
There should be spaces on both sides of
=in the codeThere should be a space before
+geom_boxplot()should be on the next line and indentedThere should be a
+at the end of thegeom_boxplot()linelabs()should be indented
Part 2: The warning is caused by
NAin the data. It means that 39 observations wereNAs and are not plotted/represented on the plot. -
Part 1:
- Render: Run all of the code and render all of the text in the document and produce an output.
- Commit: Take a snapshot of your changes in Git with an appropriate message.
- Push: Send your changes off to GitHub.
Part 2: c - Rendering or committing isn’t sufficient to send your changes to your GitHub repository, a push is needed. A pull is also not needed to view the changes in the browser.
d
a, d
a, d
c
b
a
b
a, d
b, c, e
a
a, c, e
a, b, c, d
a, d
-
Part 1: The
NArow represents vault routines by gymnasts whosecountryvalue did not match anyentityin thecontinentsdataset. In aleft_join(), every row of the left data frame (gymnastics) is kept, and when no match is found in the right data frame, the columns coming from the right data frame (includingcontinent) are filled withNA. When we thengroup_by(continent)andsummarize(), all of these unmatched routines are grouped together into a singleNAgroup.Part 2: The
mean_vault_scoreof athletes from these three countries is 13.7, they’re the ones in theNAgroup in the output. country_inflation_longhas 38 × 33 = 1,254 rows (ok to not calculate the final answer, but just show the multiplication) and 3 columns:country,year, andinflation_rate. Each row represents a single country/year combination — the inflation rate for one country in one year.pivot_longer()took the year and turned them into rows: the column names (the years) went into a newyearcolumn, and the values (the inflation rates) went into a newinflation_ratecolumn.names_transform = as.numericconverted theyearvalues from character strings to numeric values.-
Part 1: The resulting data frame shows the five countries with the largest ratio of their 2025 inflation rate to their 1993 inflation rate, in descending order of that ratio. Each
inf_ratiovalue tells us how many times larger (or smaller) a country’s inflation rate in 2025 is compared to 1993 — e.g., aninf_ratioof 2.20 for New Zealand means its 2025 inflation rate was 2.2 times its 1993 rate.Part 2: Without the
filter()step, the pipeline would still run, but countries missing a 1993 or 2025 value would end up withNAforinf_ratio— division involving anNAreturnsNA. This could be misleading because the reader can’t tell whether a country was excluded due to missing data or simply didn’t rank in the top five, andarrange()placesNAs last, silently burying these countries rather than flagging them. Filtering first makes the missing-data handling explicit.Part 3:
summarize()collapses the data down to summary statistics (one row per group, or one row overall if ungrouped), computing aggregates like a mean or maximum. It would not create a newinf_ratiocolumn with one value per country, and the subsequentselect()/arrange()steps would no longer have per-country rows to work with.mutate()is needed here because the goal is to add a new column computed from existing columns while keeping one row per country.Part 4: They would need to add a
group_by()country step before the summarize so the summary statistic is calculated for each country. (Optional) They can also remove thrselect(country, inf_ratio)step because the result from the grouped summary would only have these columns anyway. But inclusion of this step wouldn’t result in an error.Part 5: The distribution is unimodal and right-skewed, with most countries clustered between about 0.1 and 0.75 and a small number of countries with much higher ratios stretching out to just over 2. The dashed vertical line at 1 marks the point where a country’s 2025 inflation rate is exactly equal to its 1993 rate. Countries to the left of the line had a lower inflation rate in 2025 than in 1993, while countries to the right (9 of 32) had a higher rate in 2025.

