Homework 9

Key

Click link above for answers to 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 throughout1).

Exercises

Question 1:

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

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

Due Dates

# Homework Due Peer Review Due
1 2 April 7 April
2 9 April 14 April
3 16 April 21 April
4 23 April 28 April
5 30 April 5 May
6 7 May 12 May
7 14 May 19 May
8 21 May 26 May
9 28 May 2 June

Footnotes

  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
    ---
    ↩︎
  2. You’ll need to download the palmerpenguins package in order to use penguins dataset.↩︎