Homework 9

Instructions

Answer each of the following questions using the iterative techniques covered in lecture. Be sure to display all your code in the rendered version (use echo: true throughout or set this in your YAML header).

Exercises

Question 1:

Compute the number of unique values in each column of palmerpenguins::penguins1.

Question 2:

Compute the mean of every column in mtcars.

Question 3:

Group diamonds by cut, clarity, and color then count the number of observations and compute the mean of each numeric column.

Question 4:

What happens if you use a list of functions in across(), but don’t name them? How is the output named?

Question 5:

  1. Explain what each step of the following pipeline does. If you haven’t seen the function before, look up its help page to learn the specifics of what it does.
diamonds |> 
  split(diamonds$cut) |>
  map(\(df) lm(price ~ carat, data = df)) |> 
  map(summary) |> 
  map_dbl("r.squared")
1
A function from base R that does not use tidy evaluation and therefore requires base indexing with $
>      Fair      Good Very Good   Premium     Ideal 
> 0.7383940 0.8509539 0.8581622 0.8556336 0.8670887

Footnotes

  1. You’ll need to download the palmerpenguins package in order to use penguins dataset.↩︎