Assessment – data aggregation with dplyr

Jul 24, 2014 • Kara Woo
  1. Which of the following creates a data frame of average petal length and width by species from the iris dataset?
<span class="co"># A</span>
iris %>%
<span class="kw">group_by</span>(Species) %>%
<span class="kw">summarize</span>(<span class="kw">mean</span>(Petal.Length), <span class="kw">mean</span>(Petal.Width))

<span class="co"># B</span>
iris %>%
<span class="kw">summarize</span>(<span class="kw">mean</span>(Petal.Length), <span class="kw">mean</span>(Petal.Width))

<span class="co"># C</span>
iris %>%
<span class="kw">group_by</span>(Species) %>%
<span class="kw">summarize</span>(<span class="kw">mean</span>(Petal.Length)) %>%
<span class="kw">summarize</span>(<span class="kw">mean</span>(Petal.Width))

<span class="co"># D</span>
<span class="kw">summarize</span>(iris, <span class="kw">group_by</span>(Species), <span class="kw">mean</span>(Petal.Length), <span class="kw">mean</span>(Petal.Width))
  1. Using the warpbreaks dataset, generate a data frame of the total number of breaks by wool type and tension.