Homework 8
Instructions
Answer each of the following questions. Be sure to display all your code in the rendered version (use echo: true
throughout).
Exercises
Question 1:
Given a vector of birthdates1, write a function to compute the age in years2.
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()
3, rename_with()
, slice_min()
, slice_sample()
.
Question 3:
Build up a rich plotting function by incrementally implementing each of the steps below:
- Draw a scatterplot given
dataset
andx
andy
variables. - Add a line of best fit (i.e. a linear model with no standard errors)4.
- Add a title that includes the names of the variables used.
Test your function with the built-in cars
, swiss
, and iris
datasets.
Footnotes
Assume
mdy
format for this vector.↩︎Depending upon how you want to solve this problem, the lubridate functions
today()
andtime_length()
could be useful here :)↩︎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.↩︎geom_smooth()
has amethod
andse
argument that will be necessary to specify here.↩︎