Homework 8

Instructions

Answer each of the following questions. Be sure to display all your code in the rendered version (use echo: true throughout1).

1 You can make this a global option for your whole document by putting it directly in the YAML of your qmd:

---
title: "My Document"
execute:
  echo: true
---

Exercises

Question 1:

Given a vector of birthdates2, write a function to compute the age in years3.

2 Assume mdy format for this vector.

3 Depending upon how you want to solve this problem, the lubridate functions today() and time_length() could be useful here :)

Question 2:

For each of the following functions list all arguments that use tidy evaluation and describe whether they use data-masking or tidy-selection: distinct(), count(), group_by()4, rename_with(), slice_min(), slice_sample().

4 Note: group_by() doesn’t list what type of tidy evaluation it uses for its ... argument but you can find the answer in the introduction to this article.

Question 3:

Build up a rich plotting function by incrementally implementing each of the steps below:

  • Draw a scatterplot given dataset and x and y variables.
  • Add a line of best fit (i.e. a linear model with no standard errors)5.
  • Add a title that includes the names of the variables used.

5 geom_smooth() has a method and se argument that will be necessary to specify here.

Test your function with the built-in cars, swiss, and iris datasets.

Before you submit:

Have you remembered to add embed-resources: true to your YAML?

Due Dates

# Homework Due Peer Review Due
1 7 October 12 October
2 14 October 19 October
3 21 October 26 October
4 28 October 2 November
5 11 November 16 November
6 18 November 21 November
7 25 November 30 November
8 2 December 7 December
9 9 December 14 December