<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>BioDASH</title>
    <link>https://biodash.github.io/</link>
      <atom:link href="https://biodash.github.io/index.xml" rel="self" type="application/rss+xml" />
    <description>BioDASH</description>
    <generator>Wowchemy (https://wowchemy.com)</generator><language>en-us</language><lastBuildDate>Thu, 30 Mar 2023 00:00:00 +0000</lastBuildDate>
    <image>
      <url>https://biodash.github.io/media/logo_hu6407506e646a281542ecb299640680ce_37988_300x300_fit_lanczos_2.png</url>
      <title>BioDASH</title>
      <link>https://biodash.github.io/</link>
    </image>
    
    <item>
      <title>R4DS Chapter 10: ggplot layers, part 2</title>
      <link>https://biodash.github.io/codeclub/s05e09/</link>
      <pubDate>Thu, 30 Mar 2023 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s05e09/</guid>
      <description>&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;h3 id=&#34;session-goals&#34;&gt;Session goals&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Recap last week&amp;rsquo;s material on aesthetic mappings and geom layers&lt;/li&gt;
&lt;li&gt;Learn about the difference between local and global aesthetic mappings&lt;/li&gt;
&lt;li&gt;See several additional aesthetic mappings (like &lt;code&gt;shape&lt;/code&gt; and &lt;code&gt;fill&lt;/code&gt;) and geoms (like &lt;code&gt;geom_boxplot&lt;/code&gt; and &lt;code&gt;geom_violin&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;See an example of a geom from an &amp;ldquo;extension&amp;rdquo; package to make a ridgeway plot&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;setting-up&#34;&gt;Setting up&lt;/h3&gt;
&lt;p&gt;The &lt;em&gt;ggplot2&lt;/em&gt; package is one of the core &lt;em&gt;tidyverse&lt;/em&gt; packages, so it&amp;rsquo;s generally most convenient to load it along with the rest of the tidyverse:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# If you don&#39;t have the tidyverse installed, first do so as follows:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;tidyverse&#34;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching core tidyverse packages&lt;/span&gt; ──────────────────────── tidyverse 2.0.0 ──&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr    &lt;/span&gt; 1.1.0     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;readr    &lt;/span&gt; 2.1.4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;forcats  &lt;/span&gt; 1.0.0     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;stringr  &lt;/span&gt; 1.5.0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2  &lt;/span&gt; 3.4.1     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tibble   &lt;/span&gt; 3.1.8&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;lubridate&lt;/span&gt; 1.9.2     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr    &lt;/span&gt; 1.3.0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;purrr    &lt;/span&gt; 1.0.1     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt; masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::filter()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;    masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::lag()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Use the &lt;a href=&#39;http://conflicted.r-lib.org/&#39;&gt;conflicted package&lt;/a&gt; to force all conflicts to become errors&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We&amp;rsquo;ll talk about formatting plots to your heart&amp;rsquo;s delight in Chapter 12, but one trick for now is &lt;strong&gt;setting a different &lt;em&gt;ggplot&lt;/em&gt; plotting &amp;ldquo;theme&amp;rdquo; for the entire R session:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# - Overview of themes: https://ggplot2.tidyverse.org/reference/ggtheme.html&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# - The default base_size is 11, setting to 13 will make any text larger&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/theme_get.html&#39;&gt;theme_set&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggtheme.html&#39;&gt;theme_minimal&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;base_size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;13&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;102----aesthetic-mappings&#34;&gt;10.2 &amp;ndash; Aesthetic mappings&lt;/h2&gt;
&lt;h3 id=&#34;recap-of-last-week&#34;&gt;Recap of last week&lt;/h3&gt;
&lt;p&gt;In last week&amp;rsquo;s session, we worked with the built-in &lt;code&gt;iris&lt;/code&gt; dataframe, which has flower measurements for 3 species of iris:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Sepal.Length Sepal.Width Petal.Length Petal.Width Species&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1          5.1         3.5          1.4         0.2  setosa&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2          4.9         3.0          1.4         0.2  setosa&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3          4.7         3.2          1.3         0.2  setosa&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4          4.6         3.1          1.5         0.2  setosa&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5          5.0         3.6          1.4         0.2  setosa&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6          5.4         3.9          1.7         0.4  setosa&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We learned that we create ggplots by &amp;ldquo;mapping&amp;rdquo; variables (dataframe columns) to so-called &amp;ldquo;aesthetics&amp;rdquo; such as the &lt;code&gt;x&lt;/code&gt;-axis, the &lt;code&gt;y&lt;/code&gt;-axis, and &lt;code&gt;color&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If we map the &lt;code&gt;iris&lt;/code&gt; dataframe column &lt;code&gt;Petal.Length&lt;/code&gt; to the &lt;code&gt;x&lt;/code&gt;-axis aesthetic, then the values from that column will be plotted along the x-axis.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If we map the &lt;code&gt;iris&lt;/code&gt; dataframe column &lt;code&gt;Species&lt;/code&gt; to the &lt;code&gt;color&lt;/code&gt; aesthetic, then observations are colored according to the values in the &lt;code&gt;Species&lt;/code&gt; column, i.e. according to which species of iris they belong to.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Recall: wrapping code inside &#34;aes()&#34; conveys that we are mapping aesthetics&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-5-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h3 id=&#34;other-aesthetics&#34;&gt;Other aesthetics&lt;/h3&gt;
&lt;p&gt;Several other aesthetics exist, such as &lt;code&gt;fill&lt;/code&gt; (like &lt;code&gt;color&lt;/code&gt;, but then to &lt;em&gt;fill in&lt;/em&gt; areas), point &lt;code&gt;shape&lt;/code&gt; and &lt;code&gt;size&lt;/code&gt;, line &lt;code&gt;linewidth&lt;/code&gt; and &lt;code&gt;linetype&lt;/code&gt;, and &lt;code&gt;alpha&lt;/code&gt; (transparency).&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s try &lt;code&gt;shape&lt;/code&gt; instead of &lt;code&gt;color&lt;/code&gt; to distinguish the iris species:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;, shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-6-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Or &lt;code&gt;size&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Using &lt;span style=&#39;color: #00BB00;&#39;&gt;size&lt;/span&gt; for a discrete variable is not advised.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-7-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Why would &lt;em&gt;ggplot&lt;/em&gt; give us a warning here?&lt;/strong&gt; When &lt;em&gt;is&lt;/em&gt; size a useful aesthetic?&lt;/p&gt;
&lt;h3 id=&#34;visual-properties&#34;&gt;Visual properties&lt;/h3&gt;
&lt;p&gt;While &lt;code&gt;color&lt;/code&gt; and the other &amp;ldquo;visual properties&amp;rdquo; mentioned above can be used as an aesthetic, they can also be set manually for all the data at once:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;, shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;blue&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-8-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The key difference in the syntax of the code above is &lt;em&gt;not&lt;/em&gt; that &lt;code&gt;color&lt;/code&gt; is specified inside &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_point.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_point()&lt;/code&gt;&lt;/a&gt; rather than &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/ggplot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplot()&lt;/code&gt;&lt;/a&gt;: as we&amp;rsquo;ll see below, aesthetic mappings can be set in either location. Instead, it is that we are not specifying &lt;code&gt;color&lt;/code&gt; inside an &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/aes.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;aes()&lt;/code&gt;&lt;/a&gt; function call.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;103----geometric-objects&#34;&gt;10.3 &amp;ndash; Geometric objects&lt;/h2&gt;
&lt;p&gt;Last week, we learned that ggplot geometric objects (i.e., &amp;ldquo;&lt;strong&gt;geoms&lt;/strong&gt;&amp;quot;) are essentially plot types, which are added to a plot with &lt;code&gt;geom_...()&lt;/code&gt; functions.&lt;/p&gt;
&lt;p&gt;And that different geoms can be layered on top of each other, such as when you want to show the raw data points (&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_point.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_point()&lt;/code&gt;&lt;/a&gt;) along with summaries of the data such as a trend line (&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_smooth.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_smooth()&lt;/code&gt;&lt;/a&gt;).&lt;/p&gt;
&lt;h3 id=&#34;local-vs-global-aesthetics&#34;&gt;Local vs global aesthetics&lt;/h3&gt;
&lt;p&gt;It&amp;rsquo;s useful to understand the distinction between &amp;ldquo;global&amp;rdquo; and &amp;ldquo;local&amp;rdquo; aesthetics:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Global aesthetics&lt;/strong&gt; apply to all geoms in the plot, and are added in the initial &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/ggplot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplot()&lt;/code&gt;&lt;/a&gt; call (or in a stand-alone &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/aes.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;aes()&lt;/code&gt;&lt;/a&gt; layer).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Local aesthetics&lt;/strong&gt; apply only to the geom to which they are added.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For instance, if we globally map &lt;code&gt;Species&lt;/code&gt; to &lt;code&gt;color&lt;/code&gt;, this will apply to the &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_point.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_point()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_smooth.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_smooth()&lt;/code&gt;&lt;/a&gt; calls below it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_smooth.html&#39;&gt;geom_smooth&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using method = &#39;loess&#39; and formula = &#39;y ~ x&#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-9-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;(Note also that in case of &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_smooth.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_smooth()&lt;/code&gt;&lt;/a&gt;, which summarizes the data using a statistical function, this summarizing is done entirely &lt;em&gt;separately&lt;/em&gt; for each species!)&lt;/p&gt;
&lt;p&gt;In contrast, when we define the &lt;code&gt;color&lt;/code&gt; mapping &lt;em&gt;locally&lt;/em&gt;, and &lt;em&gt;only&lt;/em&gt; for &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_point.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_point()&lt;/code&gt;&lt;/a&gt;, we get this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_smooth.html&#39;&gt;geom_smooth&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using method = &#39;loess&#39; and formula = &#39;y ~ x&#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-10-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now, we got a single line (and a single statistical fit) that ignores the &lt;code&gt;Species&lt;/code&gt; identity of each flower.&lt;/p&gt;
&lt;h3 id=&#34;many-different-geoms-same-syntax&#34;&gt;Many different geoms, same syntax&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;ggplot&lt;/em&gt; has dozens of different geoms &amp;ndash; for an overview, see &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/main/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this cheatsheet&lt;/a&gt; that Jessica linked to last week or the ggplot &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/#geoms&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;reference on geoms&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s see a couple more commonly used geoms. Last week we talked a bit about how a scatterplot does not always make it easy to compares the distributions of a variable among groups.&lt;/p&gt;
&lt;p&gt;Useful plot types for showing and comparing distributions are histograms, density plots, box plots, and violin plots. Notice below that we use nearly identical code to make these different plots (in this case, to show the distribution of &lt;code&gt;Petal.Length&lt;/code&gt; among iris species):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Left&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Right&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_density.html&#39;&gt;geom_density&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;95%&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In the plots above, we only needed one axis (&lt;code&gt;x&lt;/code&gt;), since the other axis consisted of counts/density computed by the plot itself. For box and violin plots, we do specify an x-axis when we want to show multiple groups:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Left&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Right:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_violin.html&#39;&gt;geom_violin&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;95%&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h3 id=&#34;geoms-from-ggplot-extension-packages&#34;&gt;Geoms from ggplot &amp;ldquo;extension&amp;rdquo; packages&lt;/h3&gt;
&lt;p&gt;There are also many &lt;a href=&#34;https://exts.ggplot2.tidyverse.org/gallery/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ggplot extension packages (see this link for an overview)&lt;/a&gt;. Some of these offer additional geoms, like the recently popular &amp;ldquo;ridgeline&amp;rdquo; plots from the &lt;em&gt;ggridges&lt;/em&gt; package.&lt;/p&gt;
&lt;p&gt;First, we&amp;rsquo;ll have to install the package:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;ggridges&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then we can load it and use the ridgeplot geom &lt;a href=&#34;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_density_ridges()&lt;/code&gt;&lt;/a&gt; just like any other geom:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/&#39;&gt;ggridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Sepal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#39;&gt;geom_density_ridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Picking joint bandwidth of 0.181&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-16-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;A plot like this can be improved a bit, for instance by making the density shapes semi-transparent. We&amp;rsquo;ll do that in the exercises below.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout Rooms&lt;/h2&gt;
&lt;p&gt;The following exercises use another built-in R dataframe, &lt;code&gt;mpg&lt;/code&gt;, which has some statistics on cars.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mpg&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 11&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   manufacturer model displ  year   cyl trans      drv     cty   hwy fl    class &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; audi         a4      1.8  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999     4 auto(l5)   f        18    29 p     compa…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; audi         a4      1.8  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999     4 manual(m5) f        21    29 p     compa…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; audi         a4      2    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008     4 manual(m6) f        20    31 p     compa…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; audi         a4      2    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008     4 auto(av)   f        21    30 p     compa…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; audi         a4      2.8  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999     6 auto(l5)   f        16    26 p     compa…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; audi         a4      2.8  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999     6 manual(m5) f        18    26 p     compa…&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You will be using the following columns:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;displ&lt;/code&gt; is the engine size (&amp;ldquo;displacement&amp;rdquo;)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;hwy&lt;/code&gt; is gas mileage (miles per gallon) when driving on a highway&lt;/li&gt;
&lt;li&gt;&lt;code&gt;drv&lt;/code&gt; is the type of &amp;ldquo;drive train&amp;rdquo;, where &lt;code&gt;f&lt;/code&gt; = front-wheel drive, &lt;code&gt;r&lt;/code&gt; = rear wheel drive, &lt;code&gt;4&lt;/code&gt; = 4wd&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;Along the same lines as our last &lt;code&gt;iris&lt;/code&gt; plot above, make a ridgeline plot of mileage (&lt;code&gt;hwy&lt;/code&gt;) for cars with different drive trains (&lt;code&gt;drive&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;And like in our &lt;code&gt;iris&lt;/code&gt; plot, also map the &lt;code&gt;fill&lt;/code&gt; aesthetic to &lt;code&gt;drive&lt;/code&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mpg&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;hwy&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;drv&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;drv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#39;&gt;geom_density_ridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Picking joint bandwidth of 1.28&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-18-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s try to make the plot you made in Exercise 1 a bit nicer.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;One issue is that the density shapes overlap. We can elegantly solve this by making them semi-transparent, which we can do by setting &lt;code&gt;alpha&lt;/code&gt;, e.g. to 0.5 (you would do this in the same way you would e.g. &lt;em&gt;set&lt;/em&gt; (not &lt;em&gt;map&lt;/em&gt;!) the color).&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;To set alpha to 0.5, use &lt;code&gt;geom_density_ridges(alpha = 0.5)&lt;/code&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mpg&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;hwy&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;drv&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;drv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#39;&gt;geom_density_ridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Picking joint bandwidth of 1.28&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-19-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;What do you think would happen if you &lt;em&gt;also&lt;/em&gt; map the &lt;code&gt;color&lt;/code&gt; aesthetic to &lt;code&gt;drive&lt;/code&gt;? Check if you&amp;rsquo;re right by making the plot.&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;When we map the &lt;code&gt;color&lt;/code&gt; aesthetic, the &lt;strong&gt;lines&lt;/strong&gt; (as opposed to the &lt;em&gt;fills&lt;/em&gt;) around the density shapes will get different colors:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mpg&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;hwy&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;drv&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;drv&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;drv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#39;&gt;geom_density_ridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Picking joint bandwidth of 1.28&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-20-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;As soon as we use the &lt;code&gt;color&lt;/code&gt; and/or &lt;code&gt;fill&lt;/code&gt; aesthetics, a legend will pop up. Do we need a legend in this case? Make the legend disappear by adding &lt;code&gt;show.legend = FALSE&lt;/code&gt; inside &lt;a href=&#34;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_density_ridges()&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;We don&amp;rsquo;t need a legend for &lt;code&gt;drv&lt;/code&gt; here because we are already showing this information along the y-axis (for that matter, we don&amp;rsquo;t need different colors, but it makes the plot prettier). We can turn off the legend as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mpg&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;hwy&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;drv&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;drv&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;drv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#39;&gt;geom_density_ridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;, show.legend &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Picking joint bandwidth of 1.28&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-21-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Why does the following code not result in a plot with blue points? Does &lt;em&gt;ggplot&lt;/em&gt;&amp;rsquo;s behavior here make sense to you, or would you have expected an error?&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mpg&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;displ&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;hwy&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;blue&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Can you correct the error to create a plot with blue points?&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;First, let&amp;rsquo;s see the plot that the code produces:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mpg&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;displ&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;hwy&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;blue&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-23-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The error in the code is that &lt;code&gt;color = &amp;quot;blue&amp;quot;&lt;/code&gt; was placed &lt;em&gt;inside&lt;/em&gt; the &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/aes.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;aes()&lt;/code&gt;&lt;/a&gt; function. As such, &lt;code&gt;color&lt;/code&gt; was interpreted as an aesthetic mapping, not as a visual property.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Here is the correct code and plot:&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mpg&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;displ&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;hwy&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;             color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;blue&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-24-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You might have been surprised that the initial code did not result in an error, since we normally map dataframe columns (like &lt;code&gt;displ&lt;/code&gt; and &lt;code&gt;hwy&lt;/code&gt; in this plot) to aesthetics, and &lt;code&gt;&amp;quot;blue&amp;quot;&lt;/code&gt; is not a name of one of the columns in &lt;code&gt;mpg&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But, because &lt;code&gt;&amp;quot;blue&amp;quot;&lt;/code&gt; was quoted, it was interpreted as a stand-alone &lt;em&gt;vector&lt;/em&gt; instead. And in turn, because of R&amp;rsquo;s automatic vector recycling, &lt;code&gt;&amp;quot;blue&amp;quot;&lt;/code&gt; was repeated as many times as needed, under the hood, to map it to all observations in the plot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;h3 id=&#34;bonus-exercise&#34;&gt;Bonus Exercise&lt;/h3&gt;
&lt;p&gt;What happens if you map an aesthetic to something other than a variable name, like &lt;code&gt;aes(color = displ &amp;lt; 5)&lt;/code&gt;? Note, you&amp;rsquo;ll also need to specify &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Do you understand why this code produces the resulting plot?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You can for example plot the &lt;code&gt;mpg&lt;/code&gt; data with &lt;code&gt;displ&lt;/code&gt; along the x-axis and &lt;code&gt;hwy&lt;/code&gt; along the y-axis.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To understand what is happening: what would &lt;code&gt;displ &amp;lt; 5&lt;/code&gt; by itself return? (To directly test this, run &lt;code&gt;mpg$displ &amp;lt; 5&lt;/code&gt;.)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;In the resulting plot, the &lt;code&gt;color&lt;/code&gt; aesthetic will be mapped to &lt;em&gt;whether or not the value of &lt;code&gt;displ&lt;/code&gt; is below 5&lt;/em&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mpg&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;displ&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;hwy&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;displ&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-25-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;By itself, &lt;code&gt;displ &amp;lt; 5&lt;/code&gt; within the ggplot functions will return in a logical vector: a vector with &lt;code&gt;TRUE&lt;/code&gt; and &lt;code&gt;FALSE&lt;/code&gt; for each corresponding &lt;code&gt;displ&lt;/code&gt; value that tells us whether this value is smaller than 5 (=&amp;gt; &lt;code&gt;TRUE&lt;/code&gt;) or not (=&amp;gt; &lt;code&gt;FALSE&lt;/code&gt;). To see this in a stand-alone manner, we can run:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;mpg&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;displ&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   [1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [13]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [25] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [37]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [49]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [61]  TRUE FALSE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [73] FALSE FALSE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [85]  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [97]  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [109]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [121]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE FALSE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [133]  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [145]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [157]  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [169]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [181]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [193]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE FALSE  TRUE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [205]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [217]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [229]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Next, &lt;em&gt;ggplot&lt;/em&gt; is able to map this vector to the color aesthetic in the plot, just like it maps dataframe columns to an aesthetic (after all, dataframe columns are just vectors, too).&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Chapter 10 - Visualizing Data, 1</title>
      <link>https://biodash.github.io/codeclub/s05e08_ggplot-1/</link>
      <pubDate>Thu, 23 Mar 2023 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s05e08_ggplot-1/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New To Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has some pointers that might be helpful if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Please open RStudio before Code Club to test things out &amp;ndash; if you run into issues, join early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Learn the philosophy of &lt;strong&gt;coding&lt;/strong&gt; a graphic.&lt;/li&gt;
&lt;li&gt;Learn the basic &lt;strong&gt;template&lt;/strong&gt; of a &lt;strong&gt;ggplot2&lt;/strong&gt; graphic, so you can reuse it for multiple chart types.&lt;/li&gt;
&lt;li&gt;Learn how you can quickly add visual information to a graphic using &lt;strong&gt;aesthetics&lt;/strong&gt; and &lt;strong&gt;layers&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;intro-the-ggplot2-philosophy&#34;&gt;Intro: The ggplot2 philosophy&lt;/h2&gt;
&lt;p&gt;We have already seen that in R, instead of manually manipulating data frames as you might do when editing Excel sheets, we &lt;strong&gt;code&lt;/strong&gt; the operations we want to perform using &lt;strong&gt;dplyr&lt;/strong&gt; verbs like &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt;, and so on.&lt;/p&gt;
&lt;p&gt;In a similar way when performing visualization, instead of clicking on a chart type in Excel, we &lt;strong&gt;code the chart&lt;/strong&gt; in R.&lt;/p&gt;
&lt;p&gt;And just as &lt;strong&gt;dplyr&lt;/strong&gt; gives us efficient ways to manipulate data frames, &lt;strong&gt;ggplot2&lt;/strong&gt; (which is also part of the tidyverse) gives us efficient ways to manipulate charts/plots/graphics (we use these terms interchangeably).&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;gg&lt;/strong&gt; in &lt;strong&gt;ggplot2&lt;/strong&gt; stands for &lt;em&gt;grammar of graphics&lt;/em&gt;, a systematic approach for designing statistical plots developed by Leland Wilkinson. The idea behind this was to think about &amp;lsquo;pulling apart&amp;rsquo; various plots into their shared component pieces, then provide code that could put them together again. We can then create new plots like we create new sentences (once we understand this grammar).&lt;/p&gt;
&lt;p&gt;There are two parts to this. First, the &amp;lsquo;nouns and verbs&amp;rsquo; we need to work with plots are very different than those we need to work with data frames. &lt;strong&gt;ggplot2&lt;/strong&gt; is like a mini-language of its own, with its own verbs and syntax.&lt;/p&gt;
&lt;p&gt;Second, this notion of pulling apart a graphic leads to the idea of &lt;em&gt;layers&lt;/em&gt;. You can build up a plot of any complexity by &lt;em&gt;overlaying&lt;/em&gt; different views of the same data.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s a learning curve here for sure, but there are a couple of things that help us.&lt;/p&gt;
&lt;p&gt;First, every graphic shares a &lt;em&gt;common template&lt;/em&gt;. This is like thinking about the sentence &amp;ldquo;The cat sat on the mat&amp;rdquo; grammatically as the template &lt;code&gt;NP V PP&lt;/code&gt; (&lt;code&gt;N&lt;/code&gt;oun &lt;code&gt;P&lt;/code&gt;hrase &amp;ldquo;The cat&amp;rdquo;, &lt;code&gt;V&lt;/code&gt;erb &amp;ldquo;sat&amp;rdquo;, &lt;code&gt;P&lt;/code&gt;repositional &lt;code&gt;P&lt;/code&gt;hrase &amp;ldquo;on the mat&amp;rdquo;). Once you understand this structure you can &amp;ldquo;say&amp;rdquo; a &lt;em&gt;lot&lt;/em&gt; of different things.&lt;/p&gt;
&lt;p&gt;(And I mean a &lt;em&gt;lot&lt;/em&gt;. The &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ggplot cheat sheet&lt;/a&gt; lists over 40 plot-types, but because this is a language, users can create their own &lt;a href=&#34;https://exts.ggplot2.tidyverse.org/gallery/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;extensions&lt;/a&gt; that you can also utilize, adding over 80 more.)&lt;/p&gt;
&lt;p&gt;Second, the way we put layers together is identical to the way we use pipes. You can read &lt;code&gt;%&amp;gt;%&lt;/code&gt; as &amp;ldquo;and then&amp;rdquo;: &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; &lt;em&gt;and then&lt;/em&gt; &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; &lt;em&gt;and then&lt;/em&gt; &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt;. In graphics, we can say &amp;ldquo;show this layer, and then &lt;em&gt;overlay&lt;/em&gt; this layer, and then &lt;em&gt;overlay&lt;/em&gt; this layer&amp;rdquo;, etc., using a very similar syntax.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;So how does this work in practice? We&amp;rsquo;ll work through visualizing the &lt;strong&gt;iris&lt;/strong&gt; dataset that you&amp;rsquo;ve seen before. This is an extremely famous &lt;a href=&#34;https://en.m.wikipedia.org/wiki/Iris_flower_data_set&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;dataset&lt;/a&gt; that was first analyzed by R. A. Fisher in 1936: &lt;em&gt;The use of multiple measurements in taxonomic problems&lt;/em&gt;. He was attempting to use petal and sepal measurements to discriminate one species from another.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ggplot2&lt;/strong&gt; is part of the tidyverse package so we need to load that first:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# this assumes you&#39;ve already installed tidyverse&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching packages&lt;/span&gt; ─────────────────────────────────────── tidyverse 1.3.2 ──&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2&lt;/span&gt; 3.4.0      &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;purrr  &lt;/span&gt; 1.0.1 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tibble &lt;/span&gt; 3.1.8      &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr  &lt;/span&gt; 1.0.10&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr  &lt;/span&gt; 1.2.1      &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;stringr&lt;/span&gt; 1.5.0 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;readr  &lt;/span&gt; 2.1.3      &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;forcats&lt;/span&gt; 0.5.2 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt; masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::filter()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;    masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::lag()&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And recall that the &lt;strong&gt;iris&lt;/strong&gt; dataset (3 species, 50 observations per species) is automatically available to us:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Sepal.Length Sepal.Width Petal.Length Petal.Width Species&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1          5.1         3.5          1.4         0.2  setosa&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2          4.9         3.0          1.4         0.2  setosa&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3          4.7         3.2          1.3         0.2  setosa&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4          4.6         3.1          1.5         0.2  setosa&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5          5.0         3.6          1.4         0.2  setosa&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6          5.4         3.9          1.7         0.4  setosa&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What is the correlation between petal length and width in these species? Are longer petals also wider? We can visualize this with a scatterplot. But first let&amp;rsquo;s look a the ggplot template. (Note the package is &lt;strong&gt;ggplot2&lt;/strong&gt;, the command is &lt;code&gt;ggplot&lt;/code&gt;.)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ggplot(data = &amp;lt;DATA&amp;gt;) + 
  &amp;lt;GEOM_FUNCTION&amp;gt;(mapping = aes(&amp;lt;MAPPINGS&amp;gt;))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These are the obligatory parts of any plot. The first argument to &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/ggplot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplot()&lt;/code&gt;&lt;/a&gt; is the data frame:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-3-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This is not very interesting! but it&amp;rsquo;s notable that it is &lt;em&gt;something&lt;/em&gt;. &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/ggplot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplot()&lt;/code&gt;&lt;/a&gt; has created a base coordinate system (a base layer) that we can add visual layers to. The &lt;em&gt;add a layer&lt;/em&gt; operator is &amp;ldquo;&lt;strong&gt;+&lt;/strong&gt;&amp;rdquo;, which is the ggplot equivalent of the pipe symbol, and &lt;strong&gt;it must occur at the end of the line&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The next argument specifies the kind plot we want: scatterplot, bar chart, fitted line, boxplot, pie chart, etc. &lt;strong&gt;ggplot2&lt;/strong&gt; refers to these as &lt;strong&gt;geoms&lt;/strong&gt;: the geometrical object that a plot uses to represent data. You can see an overview of many of these geoms in the &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;cheat sheet&lt;/a&gt;. The geom for a scatterplot is &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_point.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_point()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;But we also require a &lt;code&gt;mapping&lt;/code&gt; argument, which maps the &lt;em&gt;variables&lt;/em&gt; in the dataset we want to focus on to their &lt;em&gt;visual representation&lt;/em&gt; in the plot.&lt;/p&gt;
&lt;p&gt;And finally we need to specify an &lt;strong&gt;aesthetic&lt;/strong&gt; for the geometric objects in the plot, which will control things like shape, color, transparency, etc. Perhaps surprisingly, for a scatterplot, the x and y coordinates are aesthetics, since these control, not the shape or color, but the relative position of the points in the coordinate system.&lt;/p&gt;
&lt;p&gt;Here is our complete plot:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-4-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;There is clearly a positive correlation between length and width. And we can make this even more apparent by visually fitting a line to the data, by &lt;em&gt;overlaying&lt;/em&gt; another geom in the same plot.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_smooth.html&#39;&gt;geom_smooth&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using method = &#39;loess&#39; and formula = &#39;y ~ x&#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-5-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;There is clearly some code redundancy here, and we really don&amp;rsquo;t want the x, y mapping of these two layers to be independent. We can extract the common mapping information and move it to the top level:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;, mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_smooth.html&#39;&gt;geom_smooth&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using method = &#39;loess&#39; and formula = &#39;y ~ x&#39;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-6-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;So we have the possibility of &lt;em&gt;local&lt;/em&gt; layer specifications, and &lt;em&gt;global&lt;/em&gt; specifications. Global specifications are &lt;em&gt;inherited&lt;/em&gt; by all the local layers.&lt;/p&gt;
&lt;h3 id=&#34;the-power-of-aesthetics&#34;&gt;The power of aesthetics&lt;/h3&gt;
&lt;p&gt;The aim of Fisher&amp;rsquo;s paper was to try to discriminate different species based on their morphological measurements. It looks from this plot that there are two distinct clusters. Do these clusters correspond to different species? There are two clusters, but three species. How can we explore this further?&lt;/p&gt;
&lt;p&gt;Our current plot uses two numeric variables: &lt;code&gt;Petal.Length&lt;/code&gt; and &lt;code&gt;Petal.width&lt;/code&gt;. We can add a third categorical variable, like &lt;code&gt;Species&lt;/code&gt;, to a two dimensional scatterplot by mapping it to a different visual aesthetic. We&amp;rsquo;ve mapped length and width to x,y coordinates. Now we&amp;rsquo;ll simultaneously map species to &lt;code&gt;color&lt;/code&gt; by expanding our list of aesthetics:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mapping&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-7-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The R help for a specific geoms will list, among other things, all the aesthetics that geom supports.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout Rooms&lt;/h2&gt;
&lt;p&gt;In the exercises we&amp;rsquo;ll be looking a little more at the &lt;strong&gt;iris&lt;/strong&gt; data, and in addition, the NHANES data we used last week, and the left-joined bird dataset we built &lt;a href=&#34;https://biodash.github.io/codeclub/03_joining-datasets/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;some time ago&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Please install the NHANES dataset:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;NHANES&#34;&lt;/span&gt;, repos &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;http://cran.us.r-project.org&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Once installed, load it with:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;A prebuilt joined data set on birds can be downloaded using the code below.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# create a data directory for the new file if you haven&#39;t done so yet:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;data/birds&#34;&lt;/span&gt;, recursive &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# set the url&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;joined_data_url&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/S05E08_ggplot-1/joined_data.tsv&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# set the path for the downloaded file&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;joined_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;data/birds/joined_data.tsv&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#download to file&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;joined_data_url&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;joined_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# read file&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_tsv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;joined_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Rows: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;311441&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Columns: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;9&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;──&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Column specification&lt;/span&gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;────────────────────────────────────────────────────────&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Delimiter:&lt;/span&gt; &#34;\t&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;chr&lt;/span&gt;  (4): species, locality, stateProvince, species_en&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;dbl&lt;/span&gt;  (4): adult_body_mass_g, adult_svl_cm, longevity_y, litter_or_clutch_size_n&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dttm&lt;/span&gt; (1): eventDate&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Use `spec()` to retrieve the full column specification for this data.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Specify the column types or set `show_col_types = FALSE` to quiet this message.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Revisit the &lt;strong&gt;iris&lt;/strong&gt; data set, and plot sepal width (y) against sepal length (x) colored by species. Which morphological character, petals or sepals, provides the greatest discrimination between species?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;Simply reuse the code we used for petals. You can often leverage code from an old plot for a new one. &lt;br&gt; &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mapping&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Sepal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Sepal.Width&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Note this solution shows yet another way to position global mapping information: as its own layer. This can help readability and avoid too many nested parentheses.&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Use the NHANES data set to plot body mass index (y) against height (x). Color by gender. Which gender has the highest BMI?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;&lt;code&gt;glimpse()&lt;/code&gt; the dataset to identify the variable names. &lt;br&gt; &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Height&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;BMI&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Gender&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 366 rows containing missing values (`geom_point()`).&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Use the same plot but now color by physical activity. How active are those people with the highest BMI?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;Again, &lt;code&gt;glimpse()&lt;/code&gt; the dataset to identify the variable names. &lt;br&gt; &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Height&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;BMI&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;PhysActive&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 366 rows containing missing values (`geom_point()`).&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Often plotting the data allows us to identify outliers, which may be data-entry errors, or genuinely extreme data. Using the &lt;code&gt;joined_data&lt;/code&gt; set, plot adult body mass (y) against longevity (x). Identify extreme data points at the high end of body mass. How can we identify what these points represent?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt; Examine the plot to find an appropriate threshold value, and filter the data using that value. How many data points are there passing that threshold? What species are represented by these data points? How many weights are reported? Why is the plot misleading here? &lt;br&gt; &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 24089 rows containing missing values (`geom_point()`).&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-15-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 228 × 9&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species   local…¹ state…² eventDate           speci…³ adult…⁴ adult…⁵ longe…⁶&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Cygnus o… Findlay Ohio    2008-02-17 &lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt; Mute S…   &lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;230    142.    27.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Cygnus o… Dundee  Ohio    2004-02-16 &lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt; Mute S…   &lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;230    142.    27.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Cygnus o… 44805 … Ohio    2006-02-18 &lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt; Mute S…   &lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;230    142.    27.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Cygnus o… 45011 … Ohio    2005-02-19 &lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt; Mute S…   &lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;230    142.    27.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Cygnus b… 45042 … Ohio    2009-02-13 &lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt; Trumpe…   &lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;300    159.    26.5&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Cygnus o… 44813 … Ohio    2007-02-19 &lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt; Mute S…   &lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;230    142.    27.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Cygnus o… Spencer Ohio    2008-02-16 &lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt; Mute S…   &lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;230    142.    27.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Cygnus o… 44903 … Ohio    2009-02-16 &lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt; Mute S…   &lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;230    142.    27.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Cygnus o… 44601 … Ohio    2002-02-16 &lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt; Mute S…   &lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;230    142.    27.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Cygnus o… Avon L… Ohio    2007-02-17 &lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt; Mute S…   &lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;230    142.    27.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 218 more rows, 1 more variable: litter_or_clutch_size_n &amp;lt;dbl&amp;gt;, and&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   abbreviated variable names ¹​locality, ²​stateProvince, ³​species_en,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ⁴​adult_body_mass_g, ⁵​adult_svl_cm, ⁶​longevity_y&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/distinct.html&#39;&gt;distinct&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 2 × 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species          &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Cygnus olor      &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Cygnus buccinator&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/distinct.html&#39;&gt;distinct&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 2 × 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   adult_body_mass_g&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;             &lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;230&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;             &lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;300&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;h3 id=&#34;bonus-exercise-a-new-geom&#34;&gt;Bonus exercise: a new geom!&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Revisit the &lt;strong&gt;iris&lt;/strong&gt; data and generate a density histogram for sepal length, categorized by species.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;Use &lt;code&gt;geom_density()&lt;/code&gt;. Check the help to see what aesthetics it supports. Note that while you &#39;color&#39; a point, you &#39;fill&#39; an area. &lt;br&gt; &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mapping&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Sepal.Length&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_density.html&#39;&gt;geom_density&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-19-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Note, what does the &lt;strong&gt;alpha&lt;/strong&gt; aesthetic control? &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>S05E07: R4DS (2e) - Ch. 9 - Workflow: scripts and projects</title>
      <link>https://biodash.github.io/codeclub/s05e07_scripts-projects/</link>
      <pubDate>Thu, 09 Mar 2023 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s05e07_scripts-projects/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Today we are going to talk about tools that will help you organize and execute your code, and get help when you need it:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;scripts: a &lt;code&gt;.R&lt;/code&gt; file where you can write code, execute code, and save code for future use.&lt;/li&gt;
&lt;li&gt;projects: a .&lt;code&gt;Rproj&lt;/code&gt; file that allows you to keep all the files associated with an a analysis together.&lt;/li&gt;
&lt;li&gt;reprex: a &lt;strong&gt;repr&lt;/strong&gt;oducible &lt;strong&gt;ex&lt;/strong&gt;ample that allows someone else to help you troubleshoot your problem.&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;r-scripts-r&#34;&gt;R Scripts (&lt;code&gt;.R&lt;/code&gt;)&lt;/h2&gt;
&lt;p&gt;If you have the conventional layout in RStudio, your scripts will be loaded in the top left quadrant of your screen.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/rstudio.png width=&#34;90%&#34; alt=&#34;A screenshot of the RStudio IDE, with a script in the top left corner (and highlighted in a red box), the environment in the top right, the console in the bottom left, and the files panel in the bottom right.&#34;&gt;
&lt;/p&gt;
&lt;p&gt;You could simply type any code you want to execute into the console to run it, but long term this is not a good or practical solution. It can get cramped, and most of the time you want to save your code you write so you can use it again in the future.&lt;/p&gt;
&lt;p&gt;The R script file acts like a text file where you can write code, and then send it to the console. You can also save the file so you can use/edit it later.&lt;/p&gt;
&lt;h3 id=&#34;running-code&#34;&gt;Running code&lt;/h3&gt;
&lt;p&gt;There are a few different ways in which you can execute code from your script by sending it to the console.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;By using Run in the top right corner of your Environment pane.
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/run.png width=&#34;30%&#34; alt=&#34;A screenshot of the RStudio IDE, showing the different Run options.&#34;&gt;
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;Using a keyboard shortcut: place your cursor on the line you want to run and type &lt;code&gt;Cmd + Enter&lt;/code&gt; on a Mac/Linux, or &lt;code&gt;Ctrl + Enter&lt;/code&gt; on a PC.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;code-diagnostics&#34;&gt;Code diagnostics&lt;/h3&gt;
&lt;p&gt;RStudio gets continually smarter in pointing out potential mistakes in your code to you, so you can fix them. Below are some examples of what this will look like.&lt;/p&gt;
&lt;p&gt;If you put non-allowable characters in an object name:&lt;/p&gt;
&lt;p align=&#34;left&#34;&gt;
&lt;img src=img/spaces_in_names.png width=&#34;30%&#34; alt=&#34;A screenshot of the RStudio IDE, an error when you put a space in an object name for the code my data &lt;- 1:10, you will see a red x on the left by your line numbers, and the diagnostic unexpected token data, and unexpected token &lt;-.&#34;&gt;
&lt;/p&gt;
If you are missing a parentheses:
&lt;p align=&#34;left&#34;&gt;
&lt;img src=img/missing_parentheses.png width=&#34;50%&#34; alt=&#34;A screenshot of the RStudio IDE, an error when you put a space in an object name, you will see a red x on the left by your line numbers, and the diagnostic unexpected end of document.&#34;&gt;
&lt;/p&gt;
&lt;h3 id=&#34;saving-and-naming&#34;&gt;Saving and naming&lt;/h3&gt;
&lt;p&gt;Talking about conventions for saving and naming might sound picky, but doing this in a systematic and predictable way will help you (and anyone who uses your code) in the future. In general you want your names to be:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Machine&lt;/strong&gt; readable: don&amp;rsquo;t contain any spaces, symbols, or otherwise unallowable characters. &lt;em&gt;For example&lt;/em&gt;, R will not prevent you from using spaces in column names, but it will from that point forward need to be encased in backticks which you will definitely find annoying.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Human&lt;/strong&gt; readable: contain names that indicate to you and others what is contained within that object. &lt;em&gt;For example&lt;/em&gt;, if you name all your dataframes Data, Data1, Data2, Data3, Data 4&amp;hellip; you will have trouble in the future remembering the differences between them.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Some inherent organizational structure&lt;/strong&gt;, like numbering the names of scripts in the order they are run, making sub-folders, so it&amp;rsquo;s easy to understand what comes from where, and to find what you&amp;rsquo;re looking for. &lt;em&gt;For example&lt;/em&gt;, I like to make sub-folders for data, output, figs, so that my parent directory stays organized. If you have a few scripts and they need to run sequentially, it would be a good idea to name them so that order is apparent, like &lt;code&gt;01_data-import-wrangling.R&lt;/code&gt;, &lt;code&gt;02_stat-analysis.R&lt;/code&gt;, &lt;code&gt;03_plot-figs.R&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;br&gt;
&lt;h2 id=&#34;r-projects-rproj&#34;&gt;R Projects (&lt;code&gt;.Rproj&lt;/code&gt;)&lt;/h2&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/setwd_v_rproj.png width=&#34;60%&#34; alt=&#34;A cartoon of a cracked glass cube looking frustrated with casts on its arm and leg, with bandaids on it, containing “setwd”, looks on at a metal riveted cube labeled “R Proj” holding a skateboard looking sympathetic, and a smaller cube with a helmet on labeled “here” doing a trick on a skateboard.&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Artwork by &lt;a href=&#34;https://twitter.com/allison_horst&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;@allison_horst&lt;/a&gt;&lt;/p&gt;
&lt;h3 id=&#34;a-reminder-about-directories&#34;&gt;A reminder about directories&lt;/h3&gt;
&lt;p&gt;A couple of weeks ago, Jelmer shared with us some information about &lt;a href=&#34;https://biodash.github.io/codeclub/s05e05/#interlude-file-locations&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;getting and your working directory&lt;/a&gt; using &lt;a href=&#34;https://rdrr.io/r/base/getwd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;getwd()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://rdrr.io/r/base/getwd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;setwd()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The reason why we have to do this is because we need to indicate in R where it should be looking for importing files, and where it should be writing out files from our analyses. R cannot read your mind, so you have to tell it where this location is.&lt;/p&gt;
&lt;h3 id=&#34;why-saving-your-environment-is-a-bad-idea&#34;&gt;Why saving your environment is a bad idea&lt;/h3&gt;
&lt;p&gt;By default, R will save, or ask if you if you want to save your environment. Your environment contains all of the working objects, data, functions that you have been using for your analysis.&lt;/p&gt;
&lt;p&gt;We recommend that you turn off this auto-saving of your environment to aid in your own reproducible analysis in the future. You can do that by going to Tools &amp;gt; Global Options&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/clean-slate.png width=&#34;90%&#34; alt=&#34;A screenshot of global options, general, unchecking to restore workspace at startup, and setting save workspace to RData to never.&#34;&gt;
&lt;/p&gt;
&lt;h3 id=&#34;making-a-reprex&#34;&gt;Making a reprex&lt;/h3&gt;
&lt;p&gt;It is likely that as you travel on your coding journey, you will come across a problem that despite whatever you try, you are struggling to solve. You might want to post about your problem on &lt;a href=&#34;https://stackoverflow.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Stack Overflow&lt;/a&gt; so you can get some help.&lt;/p&gt;
&lt;p&gt;To do this, you should create a reprex: a &lt;strong&gt;repr&lt;/strong&gt;oducible &lt;strong&gt;ex&lt;/strong&gt;ample.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/reprex.png width=&#34;80%&#34; alt=&#34;A side-by-side comparison of a monster providing problematic code to tech support when it is on a bunch of crumpled, disorganized papers, with both monsters looking sad and very stressed (left), compared to victorious looking monsters celebrating when code is provided in a nice box with a bow labeled “reprex”. Title text reads “reprex: make reproducible examples. Help them help everyone!” Learn more about reprex.&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Artwork by &lt;a href=&#34;https://twitter.com/allison_horst&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;@allison_horst&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Within your reprex, you should:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;include everything you need to make your code reproducible. That includes any &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; calls and any necessary objects.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;think minimalistically - don&amp;rsquo;t use more or more complicated data if you example can be simpler. If you can use built in datasets from R (think, &lt;code&gt;mtcars&lt;/code&gt;, &lt;code&gt;iris&lt;/code&gt;), do so.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;make sure its easy for someone to reproduce what you did via copy and pasting your code (no screenshots!)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Often the process of creating the reprex will help you figure out the answer to your own problem.&lt;/p&gt;
&lt;p&gt;This isn&amp;rsquo;t just good for posting about coding problems, if you want to ask your lab mate, instructor, collaborator, friend about a problem and you&amp;rsquo;d like their help in solving it, make it easy for them to help you.&lt;/p&gt;
&lt;p&gt;Here is some more information about creating a good reprex &lt;a href=&#34;https://reprex.tidyverse.org/articles/reprex-dos-and-donts.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;from the package reprex&lt;/a&gt; and &lt;a href=&#34;https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/16532098&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;on Stack overflow&lt;/a&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout Rooms&lt;/h2&gt;
&lt;p&gt;We are going to practice what we&amp;rsquo;ve gone over today with some breakout exercises.&lt;/p&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;Set yourself up an R project for your Code Club files. Store it in a permanent and logical space on your computer (i.e., not your downloads folder or desktop), and once you&amp;rsquo;ve done it, open it up and use it for the rest of Code Club.&lt;/p&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;p&gt;Using your new project, take a file from a past Code Club or from your research, and load it into R using what you&amp;rsquo;ve learned in the past two sessions (&lt;a href=&#34;https://biodash.github.io/codeclub/s05e05/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Data Import&lt;/a&gt; and &lt;a href=&#34;https://biodash.github.io/codeclub/s05e06/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Data Import 2&lt;/a&gt;). Also try and export what you&amp;rsquo;ve just imported and save it in a subfolder called &amp;ldquo;output&amp;rdquo;.&lt;/p&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;p&gt;Go to the RStudio Tips Twitter account, &lt;a href=&#34;https://twitter.com/rstudiotips&#34;&gt;https://twitter.com/rstudiotips&lt;/a&gt; and find one tip that looks interesting. Practice using it!&lt;/p&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;p&gt;What other common mistakes will RStudio diagnostics report? Read &lt;a href=&#34;https://support.posit.co/hc/en-us/articles/205753617-Code-Diagnostics&#34;&gt;https://support.posit.co/hc/en-us/articles/205753617-Code-Diagnostics&lt;/a&gt; to find out.&lt;/p&gt;
&lt;h3 id=&#34;bonus-1&#34;&gt;Bonus 1&lt;/h3&gt;
&lt;p&gt;Try and create a reprex for a coding problem you&amp;rsquo;ve run into.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>S05E05: R for Data Science (2e) - Ch. 8 - Data Import, Part II</title>
      <link>https://biodash.github.io/codeclub/s05e06/</link>
      <pubDate>Thu, 02 Mar 2023 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s05e06/</guid>
      <description>&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Today we will continue with the &lt;a href=&#34;https://r4ds.hadley.nz/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R for Data Science chapter 8 on importing data&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We will cover a few more tricks to import data with &lt;em&gt;readr&lt;/em&gt;, and will also cover &lt;em&gt;exporting&lt;/em&gt; data. We will talk about:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Controlling column types when reading data,&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Reading data from multiple files, and&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Writing to a file.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;We will again be using the &lt;code&gt;tidyverse&lt;/code&gt; and &lt;code&gt;janitor&lt;/code&gt; packages, so we first need make sure these packages are installed, and then load them for the current session using &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; commands:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# If you don&#39;t have these installed:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#install.packages(&#34;tidyverse&#34;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#install.packages(&#34;janitor&#34;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# To load the packages&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching core tidyverse packages&lt;/span&gt; ──────────────────────── tidyverse 2.0.0 ──&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr    &lt;/span&gt; 1.1.0     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;readr    &lt;/span&gt; 2.1.4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;forcats  &lt;/span&gt; 1.0.0     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;stringr  &lt;/span&gt; 1.5.0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2  &lt;/span&gt; 3.4.1     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tibble   &lt;/span&gt; 3.1.8&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;lubridate&lt;/span&gt; 1.9.2     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr    &lt;/span&gt; 1.3.0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;purrr    &lt;/span&gt; 1.0.1     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt; masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::filter()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;    masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::lag()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Use the &lt;a href=&#39;http://conflicted.r-lib.org/&#39;&gt;conflicted package&lt;/a&gt; to force all conflicts to become errors&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/sfirke/janitor&#39;&gt;janitor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Attaching package: &#39;janitor&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; The following objects are masked from &#39;package:stats&#39;:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     chisq.test, fisher.test&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;br&gt;
&lt;h2 id=&#34;book-chapter-83-and-84&#34;&gt;Book Chapter 8.3 and 8.4&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s switch to &lt;a href=&#34;https://r4ds.hadley.nz/data-import.html#sec-col-types&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;the book&lt;/a&gt; for this part.&lt;/p&gt;
&lt;hr&gt;
&lt;br&gt;
&lt;h2 id=&#34;breakout-rooms-i&#34;&gt;Breakout Rooms I&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;ll use the &lt;code&gt;03-sales.csv&lt;/code&gt; file from the examples in the book. You can download it as follows to your current R working directory:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;url_csv&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://github.com/biodash/biodash.github.io/raw/master/content/codeclub/S05E06/03-sales.csv&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;url_csv&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;03-sales.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;Read the &lt;code&gt;03-sales.csv&lt;/code&gt; file, but with the following twist: read &lt;em&gt;all&lt;/em&gt; columns as &lt;em&gt;factors&lt;/em&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Use the &lt;code&gt;col_types&lt;/code&gt; argument and within that, call the &lt;code&gt;cols&lt;/code&gt; function and specify a &lt;code&gt;.default&lt;/code&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;03-sales.csv&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;         col_types &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/cols.html&#39;&gt;cols&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;.default &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/parse_factor.html&#39;&gt;col_factor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   month year  brand item  n    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; March 2019  1     1234  3    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; March 2019  1     3627  1    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; March 2019  1     8820  3    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; March 2019  2     7253  1    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; March 2019  2     8766  3    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; March 2019  2     8288  6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;br&gt;
&lt;h2 id=&#34;book-chapter-85-and-86&#34;&gt;Book Chapter 8.5 and 8.6&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s switch back to &lt;a href=&#34;https://r4ds.hadley.nz/data-import.html#sec-writing-to-a-file&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;the book&lt;/a&gt; for this part.&lt;/p&gt;
&lt;hr&gt;
&lt;br&gt;
&lt;h2 id=&#34;breakout-rooms-i-1&#34;&gt;Breakout Rooms I&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;p&gt;Write the dataframe that you read in Exercise 1 to a CSV file. Recall that all columns in the dataframe are stored as &lt;em&gt;factors&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Then, read the CSV file you just created back in, without specifying any additional arguments to &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_csv()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Check whether the columns are still factors, and explain why.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Assign the initial &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_csv()&lt;/code&gt;&lt;/a&gt; output to a dataframe, then use &lt;a href=&#34;https://readr.tidyverse.org/reference/write_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;write_csv()&lt;/code&gt;&lt;/a&gt; to write it to a CSV file.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Recall that a CSV file is a plain text file. Can a plain text file store &amp;ldquo;metadata&amp;rdquo; about column types?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;sales&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;03-sales.csv&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;                  col_types &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/cols.html&#39;&gt;cols&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;.default &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/parse_factor.html&#39;&gt;col_factor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/write_delim.html&#39;&gt;write_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sales&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;sales.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;sales.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Rows: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;6&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Columns: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;──&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Column specification&lt;/span&gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;────────────────────────────────────────────────────────&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Delimiter:&lt;/span&gt; &#34;,&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;chr&lt;/span&gt; (1): month&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;dbl&lt;/span&gt; (4): year, brand, item, n&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Use `spec()` to retrieve the full column specification for this data.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Specify the column types or set `show_col_types = FALSE` to quiet this message.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   month  year brand  item     n&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; March  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;019     1  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;234     3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; March  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;019     1  &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;627     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; March  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;019     1  &lt;span style=&#39;text-decoration: underline;&#39;&gt;8&lt;/span&gt;820     3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; March  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;019     2  &lt;span style=&#39;text-decoration: underline;&#39;&gt;7&lt;/span&gt;253     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; March  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;019     2  &lt;span style=&#39;text-decoration: underline;&#39;&gt;8&lt;/span&gt;766     3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; March  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;019     2  &lt;span style=&#39;text-decoration: underline;&#39;&gt;8&lt;/span&gt;288     6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;When we read the file back in, the columns are no longer factors but characters and numerics, because this sort of information is lost when writing to a plain text file.&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;p&gt;Repeat what you did in Exercise 2, but now write to and read from an &lt;code&gt;RDS&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;Again, check whether the columns are still factors, and explain why.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Use the &lt;a href=&#34;https://readr.tidyverse.org/reference/read_rds.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;write_rds()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://readr.tidyverse.org/reference/read_rds.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_rds()&lt;/code&gt;&lt;/a&gt; functions.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;sales&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;03-sales.csv&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;                  col_types &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/cols.html&#39;&gt;cols&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;.default &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/parse_factor.html&#39;&gt;col_factor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_rds.html&#39;&gt;write_rds&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sales&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;sales.rds&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_rds.html&#39;&gt;read_rds&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;sales.rds&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   month year  brand item  n    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; March 2019  1     1234  3    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; March 2019  1     3627  1    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; March 2019  1     8820  3    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; March 2019  2     7253  1    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; March 2019  2     8766  3    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; March 2019  2     8288  6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The columns are still factors because RDS files preserve all information about R objects, including column type information.&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>S05E05: R for Data Science (2e) - Ch. 8 - Data Import</title>
      <link>https://biodash.github.io/codeclub/s05e05/</link>
      <pubDate>Thu, 23 Feb 2023 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s05e05/</guid>
      <description>&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;h3 id=&#34;setting-up&#34;&gt;Setting up&lt;/h3&gt;
&lt;p&gt;Today, we&amp;rsquo;ll talk about reading data into R.&lt;/p&gt;
&lt;p&gt;If you want to follow along yourself, you need to download several practice files. All code to do so can be found on this page, but if you don&amp;rsquo;t want to keep copy-pasting lines of code, I recommend that you download this R script with all of today&amp;rsquo;s code, open it, and run the code from there:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;url_script&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://github.com/biodash/biodash.github.io/raw/master/content/codeclub/S05E05/codeclub_S05E05.R&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;url_script&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;codeclub_S05E05.R&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To clean up column names, we&amp;rsquo;ll use the &lt;em&gt;janitor&lt;/em&gt; package, which you can install as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;janitor&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We&amp;rsquo;ll mostly be using the &lt;em&gt;readr&lt;/em&gt; package, which is part of the core tidyverse, and is therefore loaded by &lt;a href=&#34;https://tidyverse.tidyverse.org&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library(tidyverse)&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching core tidyverse packages&lt;/span&gt; ──────────────────────── tidyverse 2.0.0 ──&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr    &lt;/span&gt; 1.1.0     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;readr    &lt;/span&gt; 2.1.4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;forcats  &lt;/span&gt; 1.0.0     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;stringr  &lt;/span&gt; 1.5.0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2  &lt;/span&gt; 3.4.1     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tibble   &lt;/span&gt; 3.1.8&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;lubridate&lt;/span&gt; 1.9.2     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr    &lt;/span&gt; 1.3.0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;purrr    &lt;/span&gt; 1.0.1     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt; masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::filter()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;    masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::lag()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Use the &lt;a href=&#39;http://conflicted.r-lib.org/&#39;&gt;conflicted package&lt;/a&gt; to force all conflicts to become errors&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We also need to download a couple of files to practice importing data (copy-and-paste this entire code block into R with the Copy button in the top right):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;url_csv&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://github.com/biodash/biodash.github.io/raw/master/content/codeclub/S05E05/students.csv&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;url_csv&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;students.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;url_csv_noheader&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://github.com/biodash/biodash.github.io/raw/master/content/codeclub/S05E05/students_noheader.csv&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;url_csv_noheader&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;students_noheader.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;url_csv_meta&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://github.com/biodash/biodash.github.io/raw/master/content/codeclub/S05E05/students_with_meta.csv&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;url_csv_meta&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;students_with_meta.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;url_tsv&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://github.com/biodash/biodash.github.io/raw/master/content/codeclub/S05E05/students.tsv&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;url_tsv&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;students.tsv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;rectangular-plain-text-files&#34;&gt;Rectangular, plain-text files&lt;/h3&gt;
&lt;p&gt;We&amp;rsquo;ll focus on reading &lt;strong&gt;rectangular plain text&lt;/strong&gt; files, which is by far the most common input file type for R. By &lt;em&gt;rectangular&lt;/em&gt;, I mean that these files have rows and columns. The columns in rectangular files are most commonly separated by either:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Commas&lt;/strong&gt;: such files are often called &lt;strong&gt;CSV&lt;/strong&gt; files, for Comma-Separated Values. They are usually saved with a &lt;code&gt;.csv&lt;/code&gt; or simply a &lt;code&gt;.txt&lt;/code&gt; extension. Here is an example &amp;ndash; this is the &lt;code&gt;students.csv&lt;/code&gt; file you just downloaded (with some data on students and the food they eat):&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- --&gt;
&lt;pre&gt;&lt;code&gt;Student ID,Full Name,favourite.food,mealPlan,AGE
1,Sunil Huffmann,Strawberry yoghurt,Lunch only,4
2,Barclay Lynn,French fries,Lunch only,5
3,Jayendra Lyne,N/A,Breakfast and lunch,7
4,Leon Rossini,Anchovies,Lunch only,
5,Chidiegwu Dunkel,Pizza,Breakfast and lunch,five
6,Güvenç Attila,Ice cream,Lunch only,6
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Tabs&lt;/strong&gt;: such files are often called &lt;strong&gt;TSV&lt;/strong&gt; files, for Tab-Separated Values. They are usually saved with a &lt;code&gt;.tsv&lt;/code&gt; or again, simply a &lt;code&gt;.txt&lt;/code&gt; extension. Here is an example &amp;ndash; this is the &lt;code&gt;students.tsv&lt;/code&gt; file you just downloaded (showing the exact same data as in the CSV above):&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- --&gt;
&lt;pre&gt;&lt;code&gt;Student ID      Full Name       favourite.food  mealPlan        AGE
1       Sunil Huffmann  Strawberry yoghurt      Lunch only      4
2       Barclay Lynn    French fries    Lunch only      5
3       Jayendra Lyne   N/A     Breakfast and lunch     7
4       Leon Rossini    Anchovies       Lunch only
5       Chidiegwu Dunkel        Pizza   Breakfast and lunch     five
6       Güvenç Attila   Ice cream       Lunch only      6
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We will be using functions from the &lt;em&gt;readr&lt;/em&gt; package today, though it&amp;rsquo;s worth mentioning base R has similar functions you may run into, like &lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read.table()&lt;/code&gt;&lt;/a&gt;. But the &lt;em&gt;readr&lt;/em&gt; functions are faster and have several other nice features.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;basics-of-reading-rectangular-files&#34;&gt;Basics of reading rectangular files&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;ll start by reading the &lt;code&gt;students.csv&lt;/code&gt; CSV file that you have downloaded and that we saw above.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;CSV files can be read with &lt;em&gt;readr&lt;/em&gt;&amp;rsquo;s &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_csv()&lt;/code&gt;&lt;/a&gt; function&lt;/strong&gt;, which is the function we&amp;rsquo;ll mostly use today. But note that below, I&amp;rsquo;ll often say that &amp;ldquo;&lt;em&gt;readr&lt;/em&gt;&amp;rdquo; does this and that, instead of referring to the specific function. That is because the &lt;em&gt;readr&lt;/em&gt; functions for different file types all behave very similarly, which is nice!&lt;/p&gt;
&lt;p&gt;We will first use the &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_csv()&lt;/code&gt;&lt;/a&gt; function in the most basic possible way &amp;ndash; we only provide it with a file name:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;students&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;students.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Rows: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;6&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Columns: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;──&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Column specification&lt;/span&gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;────────────────────────────────────────────────────────&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Delimiter:&lt;/span&gt; &#34;,&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;chr&lt;/span&gt; (4): Full Name, favourite.food, mealPlan, AGE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;dbl&lt;/span&gt; (1): Student ID&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Use `spec()` to retrieve the full column specification for this data.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Specify the column types or set `show_col_types = FALSE` to quiet this message.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We have stored the contents of the file in the dataframe &lt;code&gt;students&lt;/code&gt;, which we&amp;rsquo;ll print below. The function is quite chatty and prints the following information about what it has done to screen:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;How many rows and columns it read&lt;/li&gt;
&lt;li&gt;Which column delimiter it used&lt;/li&gt;
&lt;li&gt;How many and which columns were assigned to each data type&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;A column in an R dataframe can only contain a single formal data type. If a mixture of types (e.g. numbers and character strings) is present in one column, all entries will be &lt;em&gt;coerced to a single data type&lt;/em&gt;. That data type is typically &lt;code&gt;chr&lt;/code&gt; (character), since a number can be represented as a character string but not vice versa.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;&lt;em&gt;readr&lt;/em&gt; infers the column types&lt;/strong&gt; when you don&amp;rsquo;t specify them, as above: 4 columns were interpreted as character columns (&lt;code&gt;chr&lt;/code&gt;), and 1 column as numeric (&lt;code&gt;dbl&lt;/code&gt; for &amp;ldquo;double&amp;rdquo;, i.e. a floating point number). Let&amp;rsquo;s take a look at the resulting dataframe (tibble), paying attention to the column types:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;students&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   `Student ID` `Full Name`      favourite.food     mealPlan            AGE  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;            1 Sunil Huffmann   Strawberry yoghurt Lunch only          4    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;            2 Barclay Lynn     French fries       Lunch only          5    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;            3 Jayendra Lyne    N/A                Breakfast and lunch 7    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;            4 Leon Rossini     Anchovies          Lunch only          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;            5 Chidiegwu Dunkel Pizza              Breakfast and lunch five &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;            6 Güvenç Attila    Ice cream          Lunch only          6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Rarely, &lt;em&gt;readr&lt;/em&gt; will misinterpret column types. In that case, it&amp;rsquo;s possible to &lt;strong&gt;manually specify the column types&lt;/strong&gt;: we&amp;rsquo;ll see how to do this next week.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;interlude-file-locations&#34;&gt;Interlude: File locations&lt;/h2&gt;
&lt;p&gt;In the above example, we simply provided a file name without a location to &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_csv()&lt;/code&gt;&lt;/a&gt;. Doing so signals to R that the file is present in your current R &amp;ldquo;working directory&amp;rdquo; (directory is just another word for &amp;ldquo;folder&amp;rdquo;). The &lt;code&gt;students.csv&lt;/code&gt; file should have indeed been in your working directory: when we ran &lt;code&gt;download.file&lt;/code&gt; above, we similarly provided it with only a file name, and the file should have therefore also been downloaded to our working directory.&lt;/p&gt;
&lt;p&gt;But if the file is located elsewhere, that code will fail: &lt;em&gt;readr&lt;/em&gt; will &lt;em&gt;not&lt;/em&gt; search your computer for a file with this name.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;To see what your working directory is, you can run &lt;a href=&#34;https://rdrr.io/r/base/getwd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;getwd()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/getwd.html&#39;&gt;getwd&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;/home/jelmer/Dropbox/mcic/website/hugodown/content/codeclub/S05E05&#34;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And your working directory is also shown at the top of the RStudio console pane.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;If the file you want to read is not in your current working directory, you can:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Change your working directory with &lt;a href=&#34;https://rdrr.io/r/base/getwd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;setwd()&lt;/code&gt;&lt;/a&gt; (generally not recommended)&lt;/li&gt;
&lt;li&gt;Include the &lt;em&gt;location&lt;/em&gt; of the file when calling &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_csv()&lt;/code&gt;&lt;/a&gt; (and other functions)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If the file is in a folder &amp;ldquo;downstream&amp;rdquo; from your working directory, you can easily find it by typing a quote symbol (double &lt;code&gt;&amp;quot;&lt;/code&gt; or single &lt;code&gt;&#39;&lt;/code&gt;) either in a script or in the console, and pressing &lt;kbd&gt;Tab&lt;/kbd&gt;. This allows you to browse your files starting from your working directory:&lt;/p&gt;
&lt;figure&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/path_completion.png width=&#34;50%&#34;&gt;
&lt;figcaption&gt;
You can browse files by opening quotes and pressing Tab!
&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;p&gt;If that&amp;rsquo;s not the case, it may be easiest to copy the location using your computer&amp;rsquo;s file browser, and paste that location into your code.&lt;/p&gt;
&lt;p&gt;Here are two examples of including folder names with a function like &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_csv()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Don&#39;t try to run this, you won&#39;t have files at these locations&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# This is just meant as a general example&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;data/more_students.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;C:/Users/jelmer/R_data/other_students.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note that in R, you can &lt;em&gt;always&lt;/em&gt; use &lt;strong&gt;forward slashes &lt;code&gt;/&lt;/code&gt;&lt;/strong&gt; to separate folders, regardless of your operating system (If you have Windows, which generally uses backslashes &lt;code&gt;\&lt;/code&gt; instead, then backslashes will also work.)&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;In two weeks, we&amp;rsquo;ll talk about &lt;strong&gt;RStudio &amp;ldquo;Projects&amp;rdquo;&lt;/strong&gt;, which can make your life a lot easier when it comes to file paths and never having to change your working directory.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;common-challenges-with-input-files&#34;&gt;Common challenges with input files&lt;/h2&gt;
&lt;h3 id=&#34;no-column-names&#34;&gt;No column names&lt;/h3&gt;
&lt;p&gt;Some files have no first line with column names. That leads to problems when using all the defaults:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;students_noheader.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 5 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     `1` `Sunil Huffmann` `Strawberry yoghurt` `Lunch only`        `4`  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;     2 Barclay Lynn     French fries         Lunch only          5    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;     3 Jayendra Lyne    N/A                  Breakfast and lunch 7    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;     4 Leon Rossini     Anchovies            Lunch only          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;     5 Chidiegwu Dunkel Pizza                Breakfast and lunch five &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;     6 Güvenç Attila    Ice cream            Lunch only          6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Oops! The first row of data was interpreted as column names. We can tell &lt;em&gt;readr&lt;/em&gt; to not do this by adding &lt;code&gt;col_names = FALSE&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;students_noheader.csv&#34;&lt;/span&gt;, col_names &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;      X1 X2               X3                 X4                  X5   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;     1 Sunil Huffmann   Strawberry yoghurt Lunch only          4    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;     2 Barclay Lynn     French fries       Lunch only          5    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;     3 Jayendra Lyne    N/A                Breakfast and lunch 7    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;     4 Leon Rossini     Anchovies          Lunch only          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;     5 Chidiegwu Dunkel Pizza              Breakfast and lunch five &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;     6 Güvenç Attila    Ice cream          Lunch only          6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;That&amp;rsquo;s better! But of course, we can&amp;rsquo;t automatically get useful column names, and they are now named &lt;code&gt;X1&lt;/code&gt;, &lt;code&gt;X2&lt;/code&gt;, etc. We could set the column names after reading the file, but we can also provide a vector of column names to the &lt;code&gt;col_names&lt;/code&gt; argument of &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_csv()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# (I am creating a vector with column names up front. But this is just for code&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#  clarity -- you can also pass the names to read_csv directly.)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;student_colnames&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;student_id&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;full_name&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;fav_food&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;meal_plan&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;age&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;students_noheader.csv&#34;&lt;/span&gt;, col_names &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;student_colnames&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   student_id full_name        fav_food           meal_plan           age  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;          1 Sunil Huffmann   Strawberry yoghurt Lunch only          4    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;          2 Barclay Lynn     French fries       Lunch only          5    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;          3 Jayendra Lyne    N/A                Breakfast and lunch 7    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;          4 Leon Rossini     Anchovies          Lunch only          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;          5 Chidiegwu Dunkel Pizza              Breakfast and lunch five &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;          6 Güvenç Attila    Ice cream          Lunch only          6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;extra-header-or-metadata-lines&#34;&gt;Extra header or metadata lines&lt;/h3&gt;
&lt;p&gt;Other files will contain lines at the top that are not part of the table, but contain some sort of annotations or metadata, for instance:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# This file contains important information
# about some of our students
Student ID,Full Name,favourite.food,mealPlan,AGE
1,Sunil Huffmann,Strawberry yoghurt,Lunch only,4
2,Barclay Lynn,French fries,Lunch only,5
3,Jayendra Lyne,N/A,Breakfast and lunch,7
4,Leon Rossini,Anchovies,Lunch only,
5,Chidiegwu Dunkel,Pizza,Breakfast and lunch,five
6,Güvenç Attila,Ice cream,Lunch only,6
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Since there are two &amp;ldquo;metadata lines&amp;rdquo;, we can tell &lt;em&gt;readr&lt;/em&gt; to skip those first 2 lines with the &lt;code&gt;skip = n&lt;/code&gt; argument:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;students_with_meta.csv&#34;&lt;/span&gt;, skip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   `Student ID` `Full Name`      favourite.food     mealPlan            AGE  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;            1 Sunil Huffmann   Strawberry yoghurt Lunch only          4    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;            2 Barclay Lynn     French fries       Lunch only          5    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;            3 Jayendra Lyne    N/A                Breakfast and lunch 7    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;            4 Leon Rossini     Anchovies          Lunch only          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;            5 Chidiegwu Dunkel Pizza              Breakfast and lunch five &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;            6 Güvenç Attila    Ice cream          Lunch only          6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Another way of skipping lines is with the &lt;code&gt;comment&lt;/code&gt; argument, which can be used when all metadata lines start with a certain character, like &lt;code&gt;#&lt;/code&gt; in our case:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;students_with_meta.csv&#34;&lt;/span&gt;, comment &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;#&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   `Student ID` `Full Name`      favourite.food     mealPlan            AGE  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;            1 Sunil Huffmann   Strawberry yoghurt Lunch only          4    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;            2 Barclay Lynn     French fries       Lunch only          5    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;            3 Jayendra Lyne    N/A                Breakfast and lunch 7    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;            4 Leon Rossini     Anchovies          Lunch only          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;            5 Chidiegwu Dunkel Pizza              Breakfast and lunch five &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;            6 Güvenç Attila    Ice cream          Lunch only          6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Why might it be preferable to use &lt;code&gt;comment&lt;/code&gt; over &lt;code&gt;skip&lt;/code&gt;, when possible?&lt;/p&gt;
&lt;h3 id=&#34;missing-values-denotations&#34;&gt;Missing values denotations&lt;/h3&gt;
&lt;p&gt;R has a special data type for missing values: &lt;code&gt;NA&lt;/code&gt;. It is important for downstream analyses that missing values are actually interpreted by R as &lt;code&gt;NA&lt;/code&gt;s.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;na&lt;/code&gt; argument of the &lt;em&gt;readr&lt;/em&gt; functions controls which values are interpreted as &lt;code&gt;NA&lt;/code&gt;. The default is to interpret &lt;strong&gt;empty cells&lt;/strong&gt; and &lt;strong&gt;cells that only contain &amp;ldquo;NA&amp;rdquo;&lt;/strong&gt; as &lt;code&gt;NA&lt;/code&gt;. In R code, this default is &lt;code&gt;c(&amp;quot;&amp;quot;, &amp;quot;NA&amp;quot;)&lt;/code&gt;, as we can see in the &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_csv()&lt;/code&gt;&lt;/a&gt; help.&lt;/p&gt;
&lt;p&gt;However, a file sometimes use other symbols to denote missing values, such as &lt;code&gt;999&lt;/code&gt;, &lt;code&gt;X&lt;/code&gt;, &lt;code&gt;-&lt;/code&gt;, or &lt;code&gt;N/A&lt;/code&gt;, like in the &lt;code&gt;students.csv&lt;/code&gt; file. It turns out that our &lt;code&gt;students.csv&lt;/code&gt; file uses empty cells &lt;em&gt;and&lt;/em&gt; &lt;code&gt;N/A&lt;/code&gt; (and even plain &lt;code&gt;NA&lt;/code&gt;s&amp;hellip;), so we&amp;rsquo;ll have to tell &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_csv()&lt;/code&gt;&lt;/a&gt; about that as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;students.csv&#34;&lt;/span&gt;, na &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;N/A&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   `Student ID` `Full Name`      favourite.food     mealPlan            AGE  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;            1 Sunil Huffmann   Strawberry yoghurt Lunch only          4    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;            2 Barclay Lynn     French fries       Lunch only          5    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;            3 Jayendra Lyne    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;                 Breakfast and lunch 7    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;            4 Leon Rossini     Anchovies          Lunch only          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;            5 Chidiegwu Dunkel Pizza              Breakfast and lunch five &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;            6 Güvenç Attila    Ice cream          Lunch only          6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Compare this to the output when reading in without specifying &lt;code&gt;na&lt;/code&gt; &amp;ndash; pay attention the the 3rd value in the &lt;code&gt;favourite.food&lt;/code&gt; column:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;students.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   `Student ID` `Full Name`      favourite.food     mealPlan            AGE  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;            1 Sunil Huffmann   Strawberry yoghurt Lunch only          4    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;            2 Barclay Lynn     French fries       Lunch only          5    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;            3 Jayendra Lyne    N/A                Breakfast and lunch 7    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;            4 Leon Rossini     Anchovies          Lunch only          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;            5 Chidiegwu Dunkel Pizza              Breakfast and lunch five &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;            6 Güvenç Attila    Ice cream          Lunch only          6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;crappy-column-names&#34;&gt;Crappy column names&lt;/h3&gt;
&lt;p&gt;You might have noticed the backticks around &lt;code&gt;Student ID&lt;/code&gt; and &lt;code&gt;Full Name&lt;/code&gt; when we display the dataframe. This is because these column names contain spaces, which are &lt;em&gt;allowed&lt;/em&gt; but quite inconvenient in R.&lt;/p&gt;
&lt;p&gt;We could go ahead and rename columns after reading in the file, e.g.:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# You&#39;ll need to use the backticks to refer to the column name with spaces!&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;students.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/rename.html&#39;&gt;rename&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;student_id &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Student ID`&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   student_id `Full Name`      favourite.food     mealPlan            AGE  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;          1 Sunil Huffmann   Strawberry yoghurt Lunch only          4    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;          2 Barclay Lynn     French fries       Lunch only          5    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;          3 Jayendra Lyne    N/A                Breakfast and lunch 7    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;          4 Leon Rossini     Anchovies          Lunch only          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;          5 Chidiegwu Dunkel Pizza              Breakfast and lunch five &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;          6 Güvenç Attila    Ice cream          Lunch only          6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;But the &lt;code&gt;students.csv&lt;/code&gt; file has terribly inconsistent column name styling throughout, with &lt;code&gt;favourite.food&lt;/code&gt; (&lt;code&gt;.&lt;/code&gt; separating words), &lt;code&gt;mealPlan&lt;/code&gt; (&amp;ldquo;camel case&amp;rdquo;), and &lt;code&gt;AGE&lt;/code&gt; (all caps) as the other column names. Renaming all columns gets tedious quickly, and would in fact become a serious chore if the file had, say, 50 columns.&lt;/p&gt;
&lt;p&gt;The really nice &lt;code&gt;clean_names()&lt;/code&gt; function from the &lt;em&gt;janitor&lt;/em&gt; package converts all column names to &amp;ldquo;snake case&amp;rdquo; style (all lowercase, words separated by underscores, as we saw last week):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;students.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;janitor&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://sfirke.github.io/janitor/reference/clean_names.html&#39;&gt;clean_names&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   student_id full_name        favourite_food     meal_plan           age  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;          1 Sunil Huffmann   Strawberry yoghurt Lunch only          4    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;          2 Barclay Lynn     French fries       Lunch only          5    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;          3 Jayendra Lyne    N/A                Breakfast and lunch 7    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;          4 Leon Rossini     Anchovies          Lunch only          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;          5 Chidiegwu Dunkel Pizza              Breakfast and lunch five &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;          6 Güvenç Attila    Ice cream          Lunch only          6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;The notation above with &lt;code&gt;janitor::&lt;/code&gt; in front of the function name is making explicit that this function is part of the &lt;em&gt;janitor&lt;/em&gt; package; also, when we use this notation, we don&amp;rsquo;t need to have the package &lt;em&gt;loaded&lt;/em&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;other-file-types&#34;&gt;Other file types&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;In the breakout rooms, you&amp;rsquo;ll practice with a &lt;strong&gt;TSV file&lt;/strong&gt;: as we discussed above, these are tab-delimited. They can be read with &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_tsv()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For rectangular plain text files with a &lt;strong&gt;different delimiter&lt;/strong&gt; than commas or tabs (e.g., spaces), you can use &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_delim()&lt;/code&gt;&lt;/a&gt; and specify the delimiter.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Excel files&lt;/strong&gt; can be read with the &lt;em&gt;readxl&lt;/em&gt; package: see the bonus exercise.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Unstructured&lt;/strong&gt; (non-rectangular) plain text files can be read with the base R &lt;a href=&#34;https://rdrr.io/r/base/readLines.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;readLines()&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Sometimes you will create complex &lt;strong&gt;R objects&lt;/strong&gt; that aren&amp;rsquo;t easily saved as a plain text file. These can be saved as binary (non-human readable) &lt;code&gt;.rds&lt;/code&gt; files with &lt;a href=&#34;https://readr.tidyverse.org/reference/read_rds.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;write_rds()&lt;/code&gt;&lt;/a&gt; and read with &lt;a href=&#34;https://readr.tidyverse.org/reference/read_rds.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_rds()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout rooms&lt;/h2&gt;
&lt;p&gt;If you haven&amp;rsquo;t done so already, please download the CSV and TSV files and make sure you have &lt;em&gt;janitor&lt;/em&gt; installed (see the code in the Introduction).&lt;/p&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1-a-tsv-file&#34;&gt;Exercise 1: A TSV file&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s try &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_csv()&lt;/code&gt;&lt;/a&gt;&amp;rsquo;s counterpart for TSV (tab-separated) files: &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_tsv()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;students.tsv&lt;/code&gt; file that you have downloaded contains the exact same data as the &lt;code&gt;students.csv&lt;/code&gt; file we&amp;rsquo;ve practiced with.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Read in &lt;code&gt;students.tsv&lt;/code&gt;, making sure to get the &lt;code&gt;NA&lt;/code&gt;s right,&lt;/strong&gt; &lt;strong&gt;and to clean up the column names like we did above.&lt;/strong&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Since missing values are represented both as &amp;ldquo;N/A&amp;rdquo; and empty cells (&amp;quot;&amp;quot;), we&amp;rsquo;ll use &lt;code&gt;na = c(&amp;quot;N/A&amp;quot;, &amp;quot;&amp;quot;)&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We pipe the output to the &lt;code&gt;clean_names()&lt;/code&gt; function to get consistently &amp;ldquo;snake case&amp;rdquo;-styled column names.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_tsv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;students.tsv&#34;&lt;/span&gt;, na &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;N/A&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;janitor&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://sfirke.github.io/janitor/reference/clean_names.html&#39;&gt;clean_names&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Rows: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;6&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Columns: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;──&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Column specification&lt;/span&gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;────────────────────────────────────────────────────────&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Delimiter:&lt;/span&gt; &#34;\t&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;chr&lt;/span&gt; (4): Full Name, favourite.food, mealPlan, AGE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;dbl&lt;/span&gt; (1): Student ID&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Use `spec()` to retrieve the full column specification for this data.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Specify the column types or set `show_col_types = FALSE` to quiet this message.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   student_id full_name        favourite_food     meal_plan           age  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;          1 Sunil Huffmann   Strawberry yoghurt Lunch only          4    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;          2 Barclay Lynn     French fries       Lunch only          5    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;          3 Jayendra Lyne    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;                 Breakfast and lunch 7    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;          4 Leon Rossini     Anchovies          Lunch only          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;          5 Chidiegwu Dunkel Pizza              Breakfast and lunch five &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;          6 Güvenç Attila    Ice cream          Lunch only          6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2-a-challenging-file&#34;&gt;Exercise 2: A challenging file&lt;/h3&gt;
&lt;p&gt;Start by downloading the following CSV file:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;url_tsv&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://github.com/biodash/biodash.github.io/raw/master/content/codeclub/S05E05/exercise2.csv&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;url_tsv&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;exercise2.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now, try reading in this &lt;code&gt;exercise2.csv&lt;/code&gt; file, which has the following content:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;# This file is still incomplete
1,Sunil Huffmann,Strawberry yoghurt,Lunch only,4
2,Barclay Lynn,French fries,Lunch only,5
3,Jayendra Lyne,N/A,Breakfast and lunch,7
4,Leon Rossini,Anchovies,Lunch only,
5,Chidiegwu Dunkel,Pizza,Breakfast and lunch,five
6,Güvenç Attila,Ice cream,Lunch only,6
% More data will be entered soon!
&lt;/code&gt;&lt;/pre&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Notice that there are metadata / comment lines both at the start and the end of the file!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;code&gt;comment&lt;/code&gt; argument also works for lines that aren&amp;rsquo;t at the top of the file.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;But you cannot specify multiple &lt;code&gt;comment&lt;/code&gt; symbols to &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_csv()&lt;/code&gt;&lt;/a&gt;, so you&amp;rsquo;ll have to use both the &lt;code&gt;skip&lt;/code&gt; &lt;em&gt;and&lt;/em&gt; &lt;code&gt;comment&lt;/code&gt; arguments.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You&amp;rsquo;ll also want to take care of the fact that there is no line with column names.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;We&amp;rsquo;ll take care of ignoring the first metadata line with &lt;code&gt;skip = 1&lt;/code&gt;, and the trailing line with &lt;code&gt;comment = %&lt;/code&gt; since that line starts with a &lt;code&gt;%&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We use &lt;code&gt;col_names = FALSE&lt;/code&gt; to make sure the first row of data does not get wrongly interpreted as column names&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;exercise2.csv&#34;&lt;/span&gt;, skip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, comment &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;%&#34;&lt;/span&gt;, col_names &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Rows: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;6&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Columns: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;──&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Column specification&lt;/span&gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;────────────────────────────────────────────────────────&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Delimiter:&lt;/span&gt; &#34;,&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;chr&lt;/span&gt; (4): X2, X3, X4, X5&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;dbl&lt;/span&gt; (1): X1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Use `spec()` to retrieve the full column specification for this data.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Specify the column types or set `show_col_types = FALSE` to quiet this message.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;      X1 X2               X3                 X4                  X5   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;     1 Sunil Huffmann   Strawberry yoghurt Lunch only          4    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;     2 Barclay Lynn     French fries       Lunch only          5    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;     3 Jayendra Lyne    N/A                Breakfast and lunch 7    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;     4 Leon Rossini     Anchovies          Lunch only          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;     5 Chidiegwu Dunkel Pizza              Breakfast and lunch five &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;     6 Güvenç Attila    Ice cream          Lunch only          6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The code above resulted in column names like &lt;code&gt;X1&lt;/code&gt; and &lt;code&gt;X2&lt;/code&gt;. To get descriptive column names, we&amp;rsquo;ll have to write a vector with such names, and pass those to &lt;code&gt;col_names =&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;student_colnames&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;student_id&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;full_name&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;fav_food&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;meal_plan&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;age&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;exercise2.csv&#34;&lt;/span&gt;, skip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, comment &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;%&#34;&lt;/span&gt;, col_names &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;student_colnames&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Rows: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;6&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Columns: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;──&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Column specification&lt;/span&gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;────────────────────────────────────────────────────────&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Delimiter:&lt;/span&gt; &#34;,&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;chr&lt;/span&gt; (4): full_name, fav_food, meal_plan, age&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;dbl&lt;/span&gt; (1): student_id&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Use `spec()` to retrieve the full column specification for this data.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Specify the column types or set `show_col_types = FALSE` to quiet this message.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   student_id full_name        fav_food           meal_plan           age  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;          1 Sunil Huffmann   Strawberry yoghurt Lunch only          4    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;          2 Barclay Lynn     French fries       Lunch only          5    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;          3 Jayendra Lyne    N/A                Breakfast and lunch 7    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;          4 Leon Rossini     Anchovies          Lunch only          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;          5 Chidiegwu Dunkel Pizza              Breakfast and lunch five &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;          6 Güvenç Attila    Ice cream          Lunch only          6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;bonus-reading-an-excel-file&#34;&gt;Bonus: reading an Excel file&lt;/h3&gt;
&lt;p&gt;In this exercise, you&amp;rsquo;ll use a function from the &lt;em&gt;readxl&lt;/em&gt; package to read an Excel file. We need to do a couple of things to get set up first.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You can install and then load the &lt;em&gt;readxl&lt;/em&gt; package as follows:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;readxl&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://readxl.tidyverse.org&#39;&gt;readxl&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;You can download the excel file as follows:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;url_xls&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://github.com/biodash/biodash.github.io/raw/master/content/codeclub/S05E05/breed_ranks.xlsx&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;url_xls&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;breed_ranks.xlsx&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now, use the &lt;a href=&#34;https://readxl.tidyverse.org/reference/read_excel.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_excel()&lt;/code&gt;&lt;/a&gt; function from the &lt;em&gt;readxl&lt;/em&gt; package to read the &lt;code&gt;breed_ranks.xlsx&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;Bonus&lt;sup&gt;2&lt;/sup&gt;: There are two sheets in the Excel file: &lt;code&gt;Sheet1&lt;/code&gt; and &lt;code&gt;Sheet2&lt;/code&gt;. Can you read both in? And can you combine the resulting dataframes into a single one?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Take a look at the &lt;a href=&#34;https://readxl.tidyverse.org/reference/read_excel.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_excel()&lt;/code&gt;&lt;/a&gt; help page (e.g., type &lt;a href=&#34;https://readxl.tidyverse.org/reference/read_excel.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;?read_excel&lt;/code&gt;&lt;/a&gt; in the R console) to figure out the syntax.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When you don&amp;rsquo;t specify the &lt;code&gt;sheet&lt;/code&gt; argument, it will read in the first one.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can &amp;ldquo;vertically&amp;rdquo; combine dataframes using the &lt;a href=&#34;https://dplyr.tidyverse.org/reference/bind_rows.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;bind_rows()&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;&lt;code&gt;read_excel&lt;/code&gt; will by default read the first sheet of an Excel file, so you can read the first sheet simply with:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;breed_ranks&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readxl.tidyverse.org/reference/read_excel.html&#39;&gt;read_excel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;breed_ranks.xlsx&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Or, equivalently:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#breed_ranks &amp;lt;- read_excel(&#34;breed_ranks.xlsx&#34;, sheet = 1)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can read the second sheet by using the &lt;code&gt;sheet =&lt;/code&gt; argument:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;breed_ranks2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readxl.tidyverse.org/reference/read_excel.html&#39;&gt;read_excel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;breed_ranks.xlsx&#34;&lt;/span&gt;, sheet &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can combine the two dataframes with the &lt;a href=&#34;https://dplyr.tidyverse.org/reference/bind_rows.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;bind_rows()&lt;/code&gt;&lt;/a&gt; function, which will simply &amp;ldquo;row-bind&amp;rdquo; (vertically paste, or &amp;ldquo;concatenate&amp;rdquo;) the two files:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;breed_ranks_all&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/bind_rows.html&#39;&gt;bind_rows&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;breed_ranks&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;breed_ranks2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;(The base R function &lt;a href=&#34;https://rdrr.io/r/base/cbind.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;rbind()&lt;/code&gt;&lt;/a&gt; would also work.)&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s check the numbers of rows to check that our row-binding was successful:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;breed_ranks&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# From sheet 1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 100&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;breed_ranks2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# From sheet 2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 94&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;breed_ranks_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# Both combined&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 194&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s also take a look at the first few rows of the dataframe:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;breed_ranks_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 22&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Breed    2013 …¹ 2014 …² 2015 …³ 2016 …⁴ 2017 …⁵ 2018 …⁶ 2019 …⁷ 2020 …⁸ links&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Retriev… 1       1       1       1       1       1       1             1 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; French … 11      9       6       6       4       4       4             2 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; German … 2       2       2       2       2       2       2             3 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Retriev… 3       3       3       3       3       3       3             4 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Bulldogs 5       4       4       4       5       5       5             5 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Poodles  8       7       8       7       7       7       6             6 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 12 more variables: Image &amp;lt;chr&amp;gt;, `Setters (English)` &amp;lt;chr&amp;gt;, `91` &amp;lt;chr&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   `89` &amp;lt;chr&amp;gt;, `96` &amp;lt;chr&amp;gt;, `102` &amp;lt;chr&amp;gt;, `95` &amp;lt;chr&amp;gt;, `94` &amp;lt;chr&amp;gt;, `100` &amp;lt;chr&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   `101` &amp;lt;dbl&amp;gt;, `https://www.akc.org/dog-breeds/english-setter/` &amp;lt;chr&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   `https://www.akc.org/wp-content/uploads/2017/11/English-Setter-Illo-2.jpg` &amp;lt;chr&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   and abbreviated variable names ¹​`2013 Rank`, ²​`2014 Rank`, ³​`2015 Rank`,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ⁴​`2016 Rank`, ⁵​`2017 Rank`, ⁶​`2018 Rank`, ⁷​`2019 Rank`, ⁸​`2020 Rank`&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>S05E03: R4DS (2e) - Ch. 6 - Tidy Data 2</title>
      <link>https://biodash.github.io/codeclub/s05e03/</link>
      <pubDate>Fri, 10 Feb 2023 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s05e03/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Today we will continue learning about a consistent way to organize your data in R, using a system called &lt;strong&gt;&amp;ldquo;tidy&amp;rdquo; data&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s05e02/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Last week&lt;/a&gt; we went over &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt;, and today we are going to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;refresh on tidy data&lt;/li&gt;
&lt;li&gt;refresh on &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;learn &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_wider.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_wider()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you want to download the R script that goes along with today&amp;rsquo;s code club you can do so with the following code:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# save the url location for today&#39;s script&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;todays_R_script&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;https://github.com/biodash/biodash.github.io/raw/master/content/codeclub/S05E03/r4ds_tidying2.R&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# go get that file! &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;todays_R_script&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;              destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;r4ds_tidying2.R&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The file will be downloaded to your working directory. If you don&amp;rsquo;t know where that is, you can find out by executing &lt;a href=&#34;https://rdrr.io/r/base/getwd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;getwd()&lt;/code&gt;&lt;/a&gt; in your console.&lt;/p&gt;
&lt;p&gt;We will again be using tools embedded within the &lt;code&gt;tidyverse&lt;/code&gt; package, so we need to load it before we can use it. We do that with the &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# you should have the tidyverse installed, but if not, do so using:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;tidyverse&#34;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# load the tidyverse&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;what-is-tidy-data&#34;&gt;What is tidy data?&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s briefly go over again the idea of tidy data.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/tidy_data.jpeg width=&#34;90%&#34; alt=&#34;Stylized text providing an overview of Tidy Data. The top reads “Tidy data is a standard way of mapping the meaning of a dataset to its structure. - Hadley Wickham.” On the left reads “In tidy data: each variable forms a column; each observation forms a row; each cell is a single measurement.” There is an example table on the lower right with columns ‘id’, ‘name’ and ‘color’ with observations for different cats, illustrating tidy data structure.&#34;&gt;
&lt;/p&gt;
&lt;p&gt;&lt;em&gt;(Illustrations from the &lt;a href=&#34;https://www.openscapes.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Openscapes&lt;/a&gt; blog&lt;/em&gt; &lt;em&gt;&lt;a href=&#34;https://www.openscapes.org/blog/2020/10/12/tidy-data/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Tidy Data for reproducibility, efficiency, and collaboration&lt;/a&gt;&lt;/em&gt; &lt;em&gt;by Julia Lowndes and Allison Horst.)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This is easier to &amp;ldquo;see&amp;rdquo; 👀 than to explain. Here is an example of non-tidy data, where there is &lt;em&gt;data embedded in column names&lt;/em&gt;, and one variable (the rank of a song) is spread across many columns:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;billboard&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 317 × 79&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    artist track date.ent…¹   wk1   wk2   wk3   wk4   wk5   wk6   wk7   wk8   wk9&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;date&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; 2 Pac  Baby… 2000-02-26    87    82    72    77    87    94    99    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; 2Ge+h… The … 2000-09-02    91    87    92    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; 3 Doo… Kryp… 2000-04-08    81    70    68    67    66    57    54    53    51&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; 3 Doo… Loser 2000-10-21    76    76    72    69    67    65    55    59    62&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; 504 B… Wobb… 2000-04-15    57    34    25    17    17    31    36    49    53&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; 98^0   Give… 2000-08-19    51    39    34    26    26    19     2     2     3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; A*Tee… Danc… 2000-07-08    97    97    96    95   100    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Aaliy… I Do… 2000-01-29    84    62    51    41    38    35    35    38    38&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Aaliy… Try … 2000-03-18    59    53    38    28    21    18    16    14    12&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Adams… Open… 2000-08-26    76    76    74    69    68    67    61    58    57&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 307 more rows, 67 more variables: wk10 &amp;lt;dbl&amp;gt;, wk11 &amp;lt;dbl&amp;gt;, wk12 &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk13 &amp;lt;dbl&amp;gt;, wk14 &amp;lt;dbl&amp;gt;, wk15 &amp;lt;dbl&amp;gt;, wk16 &amp;lt;dbl&amp;gt;, wk17 &amp;lt;dbl&amp;gt;, wk18 &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk19 &amp;lt;dbl&amp;gt;, wk20 &amp;lt;dbl&amp;gt;, wk21 &amp;lt;dbl&amp;gt;, wk22 &amp;lt;dbl&amp;gt;, wk23 &amp;lt;dbl&amp;gt;, wk24 &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk25 &amp;lt;dbl&amp;gt;, wk26 &amp;lt;dbl&amp;gt;, wk27 &amp;lt;dbl&amp;gt;, wk28 &amp;lt;dbl&amp;gt;, wk29 &amp;lt;dbl&amp;gt;, wk30 &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk31 &amp;lt;dbl&amp;gt;, wk32 &amp;lt;dbl&amp;gt;, wk33 &amp;lt;dbl&amp;gt;, wk34 &amp;lt;dbl&amp;gt;, wk35 &amp;lt;dbl&amp;gt;, wk36 &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk37 &amp;lt;dbl&amp;gt;, wk38 &amp;lt;dbl&amp;gt;, wk39 &amp;lt;dbl&amp;gt;, wk40 &amp;lt;dbl&amp;gt;, wk41 &amp;lt;dbl&amp;gt;, wk42 &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk43 &amp;lt;dbl&amp;gt;, wk44 &amp;lt;dbl&amp;gt;, wk45 &amp;lt;dbl&amp;gt;, wk46 &amp;lt;dbl&amp;gt;, wk47 &amp;lt;dbl&amp;gt;, wk48 &amp;lt;dbl&amp;gt;, …&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here is an example of the same exact data, in a tidy format, where those data that used to be column names, are now &lt;em&gt;values coded for a particular variable&lt;/em&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 24,092 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    artist track                   date.entered week   rank&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;date&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk1      87&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk2      82&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk3      72&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk4      77&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk5      87&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk6      94&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk7      99&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk8      &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk9      &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk10     &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 24,082 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;why-should-you-care&#34;&gt;Why should you care?&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s go through an example where we will learn that we can&amp;rsquo;t make the visualization that we want, because our data is not in tidy format.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# look at world_bank_pop using head&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;world_bank_pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 20&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country indic…¹ `2000`  `2001`  `2002`  `2003`  `2004`  `2005`  `2006`  `2007`&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; ABW     SP.URB… 4.16&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 4.20&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4 4.22&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4 4.23&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4 4.23&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4 4.24&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4 4.26&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4 4.27&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; ABW     SP.URB… 1.66&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;0 9.56&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-1&lt;/span&gt; 4.01&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-1&lt;/span&gt; 1.97&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-1&lt;/span&gt; 9.46&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-2&lt;/span&gt; 1.94&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-1&lt;/span&gt; 3.67&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-1&lt;/span&gt; 4.08&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; ABW     SP.POP… 8.91&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 9.07&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4 9.18&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4 9.27&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4 9.35&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4 9.45&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4 9.56&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4 9.68&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; ABW     SP.POP… 2.54&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;0 1.77&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+0 1.19&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+0 9.97&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-1&lt;/span&gt; 9.01&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-1&lt;/span&gt; 1.00&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+0 1.18&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+0 1.23&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; AFE     SP.URB… 1.16&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;8 1.20&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+8 1.24&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+8 1.29&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+8 1.34&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+8 1.39&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+8 1.44&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+8 1.49&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+8&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; AFE     SP.URB… 3.60&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;0 3.66&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+0 3.72&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+0 3.71&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+0 3.74&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+0 3.81&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+0 3.81&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+0 3.61&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;+0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 10 more variables: `2008` &amp;lt;dbl&amp;gt;, `2009` &amp;lt;dbl&amp;gt;, `2010` &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   `2011` &amp;lt;dbl&amp;gt;, `2012` &amp;lt;dbl&amp;gt;, `2013` &amp;lt;dbl&amp;gt;, `2014` &amp;lt;dbl&amp;gt;, `2015` &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   `2016` &amp;lt;dbl&amp;gt;, `2017` &amp;lt;dbl&amp;gt;, and abbreviated variable name ¹​indicator&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What if we want to make a plot to see how population has changed (y-axis) for a specific country (say, the USA) over the duration for which data is collected (x-axis)? With the data in this format, we cannot make this plot, at least not with &lt;em&gt;ggplot2&lt;/em&gt;. This is because &lt;strong&gt;year&lt;/strong&gt; is not a column in our dataframe. This population information is spread over all of the columns that have a year as their name.&lt;/p&gt;
&lt;p&gt;We can fix this by using &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;world_bank_pop_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;world_bank_pop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/pivot_longer.html&#39;&gt;pivot_longer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;indicator&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# which columns do we want to &#34;pivot&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;               names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# where should the column names go&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;               values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;measure&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# where should the values within each cell go&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# check how this went&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;world_bank_pop_tidy&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country indicator   year  measure&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; ABW     SP.URB.TOTL 2000    &lt;span style=&#39;text-decoration: underline;&#39;&gt;41&lt;/span&gt;625&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; ABW     SP.URB.TOTL 2001    &lt;span style=&#39;text-decoration: underline;&#39;&gt;42&lt;/span&gt;025&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; ABW     SP.URB.TOTL 2002    &lt;span style=&#39;text-decoration: underline;&#39;&gt;42&lt;/span&gt;194&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; ABW     SP.URB.TOTL 2003    &lt;span style=&#39;text-decoration: underline;&#39;&gt;42&lt;/span&gt;277&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; ABW     SP.URB.TOTL 2004    &lt;span style=&#39;text-decoration: underline;&#39;&gt;42&lt;/span&gt;317&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; ABW     SP.URB.TOTL 2005    &lt;span style=&#39;text-decoration: underline;&#39;&gt;42&lt;/span&gt;399&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# convert year from a character to a number so we can plot it &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;world_bank_pop_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;world_bank_pop_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;year &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/numeric.html&#39;&gt;as.numeric&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# check again &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;world_bank_pop_tidy&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country indicator    year measure&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; ABW     SP.URB.TOTL  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000   &lt;span style=&#39;text-decoration: underline;&#39;&gt;41&lt;/span&gt;625&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; ABW     SP.URB.TOTL  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;001   &lt;span style=&#39;text-decoration: underline;&#39;&gt;42&lt;/span&gt;025&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; ABW     SP.URB.TOTL  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;002   &lt;span style=&#39;text-decoration: underline;&#39;&gt;42&lt;/span&gt;194&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; ABW     SP.URB.TOTL  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;003   &lt;span style=&#39;text-decoration: underline;&#39;&gt;42&lt;/span&gt;277&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; ABW     SP.URB.TOTL  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;004   &lt;span style=&#39;text-decoration: underline;&#39;&gt;42&lt;/span&gt;317&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; ABW     SP.URB.TOTL  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;005   &lt;span style=&#39;text-decoration: underline;&#39;&gt;42&lt;/span&gt;399&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now we can make the plot we want. If you&amp;rsquo;re not familiar with ggplot syntax you can learn more in the R4DS section called &lt;a href=&#34;https://r4ds.hadley.nz/visualize.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Visualize&lt;/a&gt; or in past code clubs on:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e06_ggplot2/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ggplot&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e07_ggplot2_part2/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ggplot some more&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://datavisualizing.netlify.app/module2.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;my data viz class&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# a minimal plot&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;world_bank_pop_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;USA&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;indicator&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;SP.POP.TOTL&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;measure&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_path.html&#39;&gt;geom_line&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/world_bank_pop-plot-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;If you want to see a more polished version of this plot &lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# a more polished plot&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;world_bank_pop_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;USA&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;indicator&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;SP.POP.TOTL&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;measure&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_path.html&#39;&gt;geom_line&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/scale_continuous.html&#39;&gt;scale_y_continuous&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;limits &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4e8&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# ylim(c(0, 4e8)) + # also works instead of scale_y_continuous&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggtheme.html&#39;&gt;theme_minimal&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/theme.html&#39;&gt;theme&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/labs.html&#39;&gt;labs&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Year&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Population&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Total population in the United States \nfrom 2000 to 2017&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data from the World Bank&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/world_bank_pop-plot-polished-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;Often it may be easier to collect your data in wide format, but analyze it in tidy (i.e., long) format.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;This does not mean you must now collect your data in tidy format! You simply need to become comfortable with switching between formats.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;two-functions-for-pivoting-data&#34;&gt;Two functions for pivoting data&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt; pulls data that is embedded in column names, and reshapes your dataframe such this information is now embedded within the values. Or put differently, it collects variables that are spread across multiple columns into a single column. This makes your dataframes longer, i.e., increases the number of rows. &lt;em&gt;Typically&lt;/em&gt;, we use &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt; to make an untidy dataset tidy.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_wider.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;&lt;code&gt;pivot_wider()&lt;/code&gt;&lt;/strong&gt;&lt;/a&gt; takes data that is embedded in the values of your dataframe, and puts this information in variable names. Or put differently, it spreads a variable across multiple columns. This makes your dataframe &amp;ldquo;wider&amp;rdquo;, i.e., increases the number of columns. &lt;em&gt;Typically&lt;/em&gt;, &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_wider.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_wider()&lt;/code&gt;&lt;/a&gt; will make a dataset untidy. This can be useful for certain calculations, or if you want to use a for loop to do something iteratively across columns.&lt;/p&gt;
&lt;br&gt;
&lt;h3 id=&#34;pivot_wider&#34;&gt;&lt;code&gt;pivot_wider()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The opposite of &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt; is &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_wider.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_wider()&lt;/code&gt;&lt;/a&gt;. We haven&amp;rsquo;t used &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_wider.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_wider()&lt;/code&gt;&lt;/a&gt; get so let&amp;rsquo;s try it. We are going to use the dataframe &lt;code&gt;population&lt;/code&gt; which is pre-loaded with the tidyverse. This dataframe is currently in tidy format.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# what is in population?&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;population&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country      year population&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;995   17&lt;span style=&#39;text-decoration: underline;&#39;&gt;586&lt;/span&gt;073&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;996   18&lt;span style=&#39;text-decoration: underline;&#39;&gt;415&lt;/span&gt;307&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;997   19&lt;span style=&#39;text-decoration: underline;&#39;&gt;021&lt;/span&gt;226&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;998   19&lt;span style=&#39;text-decoration: underline;&#39;&gt;496&lt;/span&gt;836&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999   19&lt;span style=&#39;text-decoration: underline;&#39;&gt;987&lt;/span&gt;071&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000   20&lt;span style=&#39;text-decoration: underline;&#39;&gt;595&lt;/span&gt;360&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What if we wanted to adjust the data so that instead of having a column called &lt;code&gt;year&lt;/code&gt;, the data for each year is its own column, and have the corresponding &lt;code&gt;population&lt;/code&gt; within each cell ? We can do that with &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_wider.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_wider()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;population_wide&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;population&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/pivot_wider.html&#39;&gt;pivot_wider&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;names_from &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;              values_from &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;population&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;population_wide&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 20&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country  `1995` `1996` `1997` `1998` `1999` `2000` `2001` `2002` `2003` `2004`&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Afghani… 1.76&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 1.84&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 1.90&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 1.95&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 2.00&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 2.06&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 2.13&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 2.22&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 2.31&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 2.40&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Albania  3.36&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;6 3.34&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;6 3.33&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;6 3.33&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;6 3.32&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;6 3.30&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;6 3.29&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;6 3.26&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;6 3.24&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;6 3.22&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;6&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Algeria  2.93&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 2.98&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 3.03&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 3.08&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 3.13&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 3.17&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 3.22&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 3.26&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 3.30&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 3.35&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; America… 5.29&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 5.39&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 5.49&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 5.59&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 5.68&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 5.75&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 5.82&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 5.87&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 5.91&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 5.93&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Andorra  6.39&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 6.43&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 6.41&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 6.38&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 6.41&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 6.54&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 6.8 &lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 7.16&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 7.56&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4 7.91&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Angola   1.21&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 1.25&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 1.28&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 1.31&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 1.35&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 1.39&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 1.44&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 1.49&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 1.54&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7 1.60&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 9 more variables: `2005` &amp;lt;dbl&amp;gt;, `2006` &amp;lt;dbl&amp;gt;, `2007` &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   `2008` &amp;lt;dbl&amp;gt;, `2009` &amp;lt;dbl&amp;gt;, `2010` &amp;lt;dbl&amp;gt;, `2011` &amp;lt;dbl&amp;gt;, `2012` &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   `2013` &amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;pivot_longer&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s practice using &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt; again. We just made a wide dataframe with &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_wider.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_wider()&lt;/code&gt;&lt;/a&gt; &amp;ndash; can we make it long again?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;population_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;population_wide&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/pivot_longer.html&#39;&gt;pivot_longer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# all columns except country&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;               names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;               values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;population&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;population_long&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country     year  population&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Afghanistan 1995    17&lt;span style=&#39;text-decoration: underline;&#39;&gt;586&lt;/span&gt;073&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Afghanistan 1996    18&lt;span style=&#39;text-decoration: underline;&#39;&gt;415&lt;/span&gt;307&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Afghanistan 1997    19&lt;span style=&#39;text-decoration: underline;&#39;&gt;021&lt;/span&gt;226&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Afghanistan 1998    19&lt;span style=&#39;text-decoration: underline;&#39;&gt;496&lt;/span&gt;836&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Afghanistan 1999    19&lt;span style=&#39;text-decoration: underline;&#39;&gt;987&lt;/span&gt;071&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Afghanistan 2000    20&lt;span style=&#39;text-decoration: underline;&#39;&gt;595&lt;/span&gt;360&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;There are many different ways you can code to tell R which columns you want to pivot. I&amp;rsquo;m showing below some other ways to code the same outcome, but you can find a more ocomprehensive list of &lt;a href=&#34;https://tidyr.tidyverse.org/reference/tidyr_tidy_select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;tidy-select helpers&lt;/a&gt; in the &lt;code&gt;tidyr&lt;/code&gt; documentation page.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;population_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;population_wide&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/pivot_longer.html&#39;&gt;pivot_longer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/where.html&#39;&gt;where&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;is.numeric&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# all numeric columns&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;               names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;               values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;population&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;population_long&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country     year  population&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Afghanistan 1995    17&lt;span style=&#39;text-decoration: underline;&#39;&gt;586&lt;/span&gt;073&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Afghanistan 1996    18&lt;span style=&#39;text-decoration: underline;&#39;&gt;415&lt;/span&gt;307&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Afghanistan 1997    19&lt;span style=&#39;text-decoration: underline;&#39;&gt;021&lt;/span&gt;226&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Afghanistan 1998    19&lt;span style=&#39;text-decoration: underline;&#39;&gt;496&lt;/span&gt;836&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Afghanistan 1999    19&lt;span style=&#39;text-decoration: underline;&#39;&gt;987&lt;/span&gt;071&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Afghanistan 2000    20&lt;span style=&#39;text-decoration: underline;&#39;&gt;595&lt;/span&gt;360&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;population_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;population_wide&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/pivot_longer.html&#39;&gt;pivot_longer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# columns 2 through 20&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;               names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;               values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;population&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;population_long&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country     year  population&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Afghanistan 1995    17&lt;span style=&#39;text-decoration: underline;&#39;&gt;586&lt;/span&gt;073&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Afghanistan 1996    18&lt;span style=&#39;text-decoration: underline;&#39;&gt;415&lt;/span&gt;307&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Afghanistan 1997    19&lt;span style=&#39;text-decoration: underline;&#39;&gt;021&lt;/span&gt;226&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Afghanistan 1998    19&lt;span style=&#39;text-decoration: underline;&#39;&gt;496&lt;/span&gt;836&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Afghanistan 1999    19&lt;span style=&#39;text-decoration: underline;&#39;&gt;987&lt;/span&gt;071&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Afghanistan 2000    20&lt;span style=&#39;text-decoration: underline;&#39;&gt;595&lt;/span&gt;360&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout Rooms&lt;/h2&gt;
&lt;p&gt;We are going to use a dataset that is a part of the &lt;code&gt;#TidyTuesday&lt;/code&gt; series of data activities for tidyverse/R learning. I&amp;rsquo;ve picked some &lt;a href=&#34;https://github.com/rfordatascience/tidytuesday/tree/master/data/2022/2022-02-01&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;data&lt;/a&gt; that comes from the American Kennel Club and was compiled by &lt;a href=&#34;https://github.com/kkakey/dog_traits_AKC/blob/main/README.md&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;KKakey&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;This dataset contains the popularity of dog breeds by AKC registration from 2013-2020. You can directly read this data into a dataframe using:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;breed_rank_all&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;readr&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-02-01/breed_rank.csv&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s take a look at the data:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;breed_rank_all&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 195 × 11&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    Breed   2013 …¹ 2014 …² 2015 …³ 2016 …⁴ 2017 …⁵ 2018 …⁶ 2019 …⁷ 2020 …⁸ links&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Retrie…       1       1       1       1       1       1       1       1 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; French…      11       9       6       6       4       4       4       2 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; German…       2       2       2       2       2       2       2       3 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Retrie…       3       3       3       3       3       3       3       4 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Bulldo…       5       4       4       4       5       5       5       5 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Poodles       8       7       8       7       7       7       6       6 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Beagles       4       5       5       5       6       6       7       7 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Rottwe…       9      10       9       8       8       8       8       8 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Pointe…      13      12      11      11      10       9       9       9 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Dachsh…      10      11      13      13      13      12      11      10 http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 185 more rows, 1 more variable: Image &amp;lt;chr&amp;gt;, and abbreviated variable&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   names ¹​`2013 Rank`, ²​`2014 Rank`, ³​`2015 Rank`, ⁴​`2016 Rank`, ⁵​`2017 Rank`,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ⁶​`2018 Rank`, ⁷​`2019 Rank`, ⁸​`2020 Rank`&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;Convert the &lt;code&gt;breed_rank_all&lt;/code&gt; dataframe from its current wide, untidy format, to a tidy, long format.&lt;/p&gt;
&lt;p&gt;Bonus: Make sure the &lt;code&gt;year&lt;/code&gt; column only contains the year number itself.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use the function &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt;. Try setting the arguments &lt;code&gt;cols =&lt;/code&gt;, &lt;code&gt;names_to =&lt;/code&gt; and &lt;code&gt;values_to =&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You&amp;rsquo;ll want to pivot the columns with years in them.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint for bonus &lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Note that the values in your resulting column with years are &amp;ldquo;&amp;lt;year&amp;gt; Rank&amp;rdquo; (e.g., &lt;code&gt;2020 Rank&lt;/code&gt;), and not just &amp;ldquo;&amp;lt;year&amp;gt;&amp;rdquo; (e.g., &lt;code&gt;2020&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;You can fix this using either:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; step after pivoting, similar to the example above &amp;ndash; but using &lt;a href=&#34;https://readr.tidyverse.org/reference/parse_number.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;parse_number()&lt;/code&gt;&lt;/a&gt; instead of &lt;a href=&#34;https://rdrr.io/r/base/numeric.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;as.numeric()&lt;/code&gt;&lt;/a&gt;, since some alphabetic characters have to be removed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Directly within your &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt; call, using the &lt;code&gt;names_transform&lt;/code&gt; argument. (Visit &lt;a href=&#34;https://www.tidyverse.org/blog/2020/05/tidyr-1.1.0/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this link&lt;/a&gt; for some help on that.)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution &lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Initial step:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;breed_rank_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;breed_rank_all&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/pivot_longer.html&#39;&gt;pivot_longer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/starts_with.html&#39;&gt;contains&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Rank&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;               names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;               values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;rank&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;breed_rank_tidy&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Breed                 links                                  Image year   rank&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                 &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                                  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labrad… http… 2013…     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labrad… http… 2014…     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labrad… http… 2015…     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labrad… http… 2016…     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labrad… http… 2017…     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labrad… http… 2018…     1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This leaves us with a suboptimal &lt;code&gt;year&lt;/code&gt; column:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;breed_rank_tidy&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2013 Rank&#34; &#34;2014 Rank&#34; &#34;2015 Rank&#34; &#34;2016 Rank&#34; &#34;2017 Rank&#34; &#34;2018 Rank&#34;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can fix that as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;breed_rank_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;breed_rank_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;year &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/parse_number.html&#39;&gt;parse_number&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Alternatively, it&amp;rsquo;s possible to do this all at once using the &lt;code&gt;names_transform&lt;/code&gt; argument of &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;breed_rank_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;breed_rank_all&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/pivot_longer.html&#39;&gt;pivot_longer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/starts_with.html&#39;&gt;contains&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Rank&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;               names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;               values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;rank&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;               names_transform &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;parse_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# or: &#39;list(year = parse_number)&#39;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;breed_rank_tidy&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1,560 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    Breed                 links                                 Image  year  rank&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                 &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                                 &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labra… http…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labra… http…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;014     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labra… http…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;015     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labra… http…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;016     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labra… http…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;017     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labra… http…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;018     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labra… http…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;019     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Retrievers (Labrador) https://www.akc.org/dog-breeds/labra… http…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;020     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; French Bulldogs       https://www.akc.org/dog-breeds/frenc… http…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    11&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; French Bulldogs       https://www.akc.org/dog-breeds/frenc… http…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;014     9&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1,550 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;p&gt;Take that new dataframe you&amp;rsquo;ve just made using &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt; and make it wide again. No, you can&amp;rsquo;t just use the original dataframe 😀🐶&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints &lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Try using &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt; and make sure you specify &lt;code&gt;names_from =&lt;/code&gt; and &lt;code&gt;values_from =&lt;/code&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution &lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;breed_rank_wide&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;breed_rank_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/pivot_wider.html&#39;&gt;pivot_wider&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;names_from &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;              values_from &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;rank&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;breed_rank_wide&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 11&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Breed      links Image `2013` `2014` `2015` `2016` `2017` `2018` `2019` `2020`&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Retriever… http… http…      1      1      1      1      1      1      1      1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; French Bu… http… http…     11      9      6      6      4      4      4      2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; German Sh… http… http…      2      2      2      2      2      2      2      3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Retriever… http… http…      3      3      3      3      3      3      3      4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Bulldogs   http… http…      5      4      4      4      5      5      5      5&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Poodles    http… http…      8      7      8      7      7      7      6      6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note, that R is adding all your new columns to the end of your dataframe. If you want to reorder your columns, you can do that simply with &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; which both picks and orders columns. Note, you need backticks around a variable name when that variable name is a number (as this is atypical syntax for R).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;breed_rank_wide&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;breed_rank_wide&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Breed&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;`2013`&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;`2020`&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/everything.html&#39;&gt;everything&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;breed_rank_wide&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 11&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Breed      `2013` `2014` `2015` `2016` `2017` `2018` `2019` `2020` links Image&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Retriever…      1      1      1      1      1      1      1      1 http… http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; French Bu…     11      9      6      6      4      4      4      2 http… http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; German Sh…      2      2      2      2      2      2      2      3 http… http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Retriever…      3      3      3      3      3      3      3      4 http… http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Bulldogs        5      4      4      4      5      5      5      5 http… http…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Poodles         8      7      8      7      7      7      6      6 http… http…&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;bonus-exercise&#34;&gt;Bonus exercise&lt;/h3&gt;
&lt;p&gt;Try making a plot that shows the popularity rank of your favorite dog breeds (select up to a handful) over 2013-2020.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints &lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Use your tidy dataframe, &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; to pick the &lt;code&gt;Breed&lt;/code&gt;s you want to keep, and maybe a combined point (&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_point.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_point()&lt;/code&gt;&lt;/a&gt;) and line (&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_path.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_line()&lt;/code&gt;&lt;/a&gt;) plot.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution &lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;fav_breeds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;French Bulldogs&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Poodles&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;breed_rank_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Breed&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/match.html&#39;&gt;%in%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;fav_breeds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# filter(Breed %in% c(&#34;French Bulldogs&#34;, &#34;Poodles&#34;)) |&amp;gt; # also works&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rank&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Breed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_path.html&#39;&gt;geom_line&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/labs.html&#39;&gt;labs&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Year&#34;&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Rank (where 1 is the most popular)&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;AKC Popularity of Jess and Daniel&#39;s Favorite Dog Breeds&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data from AKC/#TidyTuesday&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/bonus-solution-1-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
</description>
    </item>
    
    <item>
      <title>S05E02: R4DS (2e) - Ch. 6 - Tidy Data</title>
      <link>https://biodash.github.io/codeclub/s05e02/</link>
      <pubDate>Thu, 02 Feb 2023 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s05e02/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Today we will learn about a consistent way to organize your data in R, using a system called &lt;strong&gt;&amp;ldquo;tidy&amp;rdquo; data&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Then we will cover the primary tool use for tidying data, &lt;strong&gt;pivoting&lt;/strong&gt;. Pivoting allows you to change the form of your data without changing any of the values.&lt;/p&gt;
&lt;p&gt;We will again be using &lt;em&gt;tidyverse&lt;/em&gt; packages, so we&amp;rsquo;ll need to load it packages for the current R session using the &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# You should have the tidyverse installed, but if not, do so using:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;tidyverse&#34;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;what-is-tidy-data&#34;&gt;What is tidy data?&lt;/h2&gt;
&lt;p&gt;We can represent any dataset in multiple ways. Let us look at the following dataframes, each of which comes is available once you&amp;rsquo;ve loaded the &lt;em&gt;tidyverse&lt;/em&gt;: &lt;code&gt;table1&lt;/code&gt;, &lt;code&gt;table2&lt;/code&gt;, &lt;code&gt;table3&lt;/code&gt;, &lt;code&gt;table4a&lt;/code&gt;, and &lt;code&gt;table4b&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Each dataframe (or &lt;em&gt;tibble&lt;/em&gt;, as &lt;em&gt;tidyverse&lt;/em&gt;-style dataframes are called) shows the same values for four variables: &lt;code&gt;country&lt;/code&gt;, &lt;code&gt;year&lt;/code&gt;, &lt;code&gt;population&lt;/code&gt;, and cases of TB (tuberculosis), but each dataset organizes the values in a different way:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;table1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country      year  cases population&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999    745   19&lt;span style=&#39;text-decoration: underline;&#39;&gt;987&lt;/span&gt;071&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;666   20&lt;span style=&#39;text-decoration: underline;&#39;&gt;595&lt;/span&gt;360&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Brazil       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999  &lt;span style=&#39;text-decoration: underline;&#39;&gt;37&lt;/span&gt;737  172&lt;span style=&#39;text-decoration: underline;&#39;&gt;006&lt;/span&gt;362&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Brazil       &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000  &lt;span style=&#39;text-decoration: underline;&#39;&gt;80&lt;/span&gt;488  174&lt;span style=&#39;text-decoration: underline;&#39;&gt;504&lt;/span&gt;898&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; China        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999 &lt;span style=&#39;text-decoration: underline;&#39;&gt;212&lt;/span&gt;258 &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;272&lt;span style=&#39;text-decoration: underline;&#39;&gt;915&lt;/span&gt;272&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; China        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000 &lt;span style=&#39;text-decoration: underline;&#39;&gt;213&lt;/span&gt;766 &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;280&lt;span style=&#39;text-decoration: underline;&#39;&gt;428&lt;/span&gt;583&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;table2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 12 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    country      year type            count&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999 cases             745&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999 population   19&lt;span style=&#39;text-decoration: underline;&#39;&gt;987&lt;/span&gt;071&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000 cases            &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;666&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000 population   20&lt;span style=&#39;text-decoration: underline;&#39;&gt;595&lt;/span&gt;360&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Brazil       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999 cases           &lt;span style=&#39;text-decoration: underline;&#39;&gt;37&lt;/span&gt;737&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Brazil       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999 population  172&lt;span style=&#39;text-decoration: underline;&#39;&gt;006&lt;/span&gt;362&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Brazil       &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000 cases           &lt;span style=&#39;text-decoration: underline;&#39;&gt;80&lt;/span&gt;488&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Brazil       &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000 population  174&lt;span style=&#39;text-decoration: underline;&#39;&gt;504&lt;/span&gt;898&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; China        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999 cases          &lt;span style=&#39;text-decoration: underline;&#39;&gt;212&lt;/span&gt;258&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; China        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999 population &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;272&lt;span style=&#39;text-decoration: underline;&#39;&gt;915&lt;/span&gt;272&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;11&lt;/span&gt; China        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000 cases          &lt;span style=&#39;text-decoration: underline;&#39;&gt;213&lt;/span&gt;766&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;12&lt;/span&gt; China        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000 population &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;280&lt;span style=&#39;text-decoration: underline;&#39;&gt;428&lt;/span&gt;583&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;table3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country      year rate             &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;*&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999 745/19987071     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000 2666/20595360    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Brazil       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999 37737/172006362  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Brazil       &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000 80488/174504898  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; China        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999 212258/1272915272&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; China        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000 213766/1280428583&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;table4a&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country     `1999` `2000`&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;*&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Afghanistan    745   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;666&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Brazil       &lt;span style=&#39;text-decoration: underline;&#39;&gt;37&lt;/span&gt;737  &lt;span style=&#39;text-decoration: underline;&#39;&gt;80&lt;/span&gt;488&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; China       &lt;span style=&#39;text-decoration: underline;&#39;&gt;212&lt;/span&gt;258 &lt;span style=&#39;text-decoration: underline;&#39;&gt;213&lt;/span&gt;766&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;table4b&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country         `1999`     `2000`&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;*&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Afghanistan   19&lt;span style=&#39;text-decoration: underline;&#39;&gt;987&lt;/span&gt;071   20&lt;span style=&#39;text-decoration: underline;&#39;&gt;595&lt;/span&gt;360&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Brazil       172&lt;span style=&#39;text-decoration: underline;&#39;&gt;006&lt;/span&gt;362  174&lt;span style=&#39;text-decoration: underline;&#39;&gt;504&lt;/span&gt;898&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; China       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;272&lt;span style=&#39;text-decoration: underline;&#39;&gt;915&lt;/span&gt;272 &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;280&lt;span style=&#39;text-decoration: underline;&#39;&gt;428&lt;/span&gt;583&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Among these four formats, the one in &lt;code&gt;table1&lt;/code&gt; is easier to work with, certainly inside the &lt;em&gt;tidyverse&lt;/em&gt;, because it is &amp;ldquo;tidy&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Three rules that make a dataset tidy are:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Each variable is a column; each column is a variable.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Each observation is a row; each row is an observation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Each value is a cell; each cell is a single value.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;an-example-of-a-computation-with-a-tidy-dataframe&#34;&gt;An example of a computation with a tidy dataframe&lt;/h3&gt;
&lt;p&gt;The key advantage of having your data in a tidy format is that it makes it easier to work with: compute summaries, new variables, make plots, etc.&lt;/p&gt;
&lt;p&gt;For instance, &lt;code&gt;table1&lt;/code&gt; makes it straightforward to calculate a rate of cases (cases per 10,000 people) using the &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Compute rate per 10,000&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;table1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    rate &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cases&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;population&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10000&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country      year  cases population  rate&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999    745   19&lt;span style=&#39;text-decoration: underline;&#39;&gt;987&lt;/span&gt;071 0.373&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Afghanistan  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;666   20&lt;span style=&#39;text-decoration: underline;&#39;&gt;595&lt;/span&gt;360 1.29 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Brazil       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999  &lt;span style=&#39;text-decoration: underline;&#39;&gt;37&lt;/span&gt;737  172&lt;span style=&#39;text-decoration: underline;&#39;&gt;006&lt;/span&gt;362 2.19 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Brazil       &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000  &lt;span style=&#39;text-decoration: underline;&#39;&gt;80&lt;/span&gt;488  174&lt;span style=&#39;text-decoration: underline;&#39;&gt;504&lt;/span&gt;898 4.61 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; China        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;999 &lt;span style=&#39;text-decoration: underline;&#39;&gt;212&lt;/span&gt;258 &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;272&lt;span style=&#39;text-decoration: underline;&#39;&gt;915&lt;/span&gt;272 1.67 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; China        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;000 &lt;span style=&#39;text-decoration: underline;&#39;&gt;213&lt;/span&gt;766 &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;280&lt;span style=&#39;text-decoration: underline;&#39;&gt;428&lt;/span&gt;583 1.67&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note that &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; always adds new columns at the end of your dataset &amp;ndash; in this case, &lt;code&gt;rate&lt;/code&gt;. This function is discussed &lt;a href=&#34;https://r4ds.hadley.nz/data-transform.html#sec-mutate&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here in R4DS Chapter 4&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The book also gives two other examples of working with a tidy dataframe, including how to make a plot with &lt;em&gt;ggplot2&lt;/em&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-1&#34;&gt;Breakout Rooms 1&lt;/h2&gt;
&lt;p&gt;(These are the same as Exercises 1 and 2 in &lt;a href=&#34;https://r4ds.hadley.nz/data-tidy.html#exercises&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R4DS 6.2.1&lt;/a&gt;.)&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Using prose, describe how the variables and observations are organised in each of the sample tables (&lt;code&gt;table1&lt;/code&gt;, &lt;code&gt;table2&lt;/code&gt;, etc.).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Sketch out the process you&amp;rsquo;d use to calculate the &lt;code&gt;rate&lt;/code&gt; for &lt;code&gt;table2&lt;/code&gt;, and for &lt;code&gt;table4a&lt;/code&gt; + &lt;code&gt;table4b&lt;/code&gt;. You will need to perform four operations:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;ul&gt;
&lt;li&gt;Extract the number of TB cases per country per year.&lt;/li&gt;
&lt;li&gt;Extract the matching population per country per year.&lt;/li&gt;
&lt;li&gt;Divide cases by population, and multiply by 10000.&lt;/li&gt;
&lt;li&gt;Store back in the appropriate place.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You haven&amp;rsquo;t yet learned all the functions you&amp;rsquo;d need to actually perform these&lt;br&gt;
operations, but you should still be able to think through the transformations you&amp;rsquo;d need.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;pivoting&#34;&gt;Pivoting&lt;/h2&gt;
&lt;p&gt;In the real world, data is often untidy because of two reasons:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Data is often organised to facilitate some goal other than analysis.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Most people aren&amp;rsquo;t familiar with the principles of tidy data.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Therefore, untidy data has to be pivot to pivot your data into a tidy form, with variables in the columns and observations in the rows.&lt;/p&gt;
&lt;h3 id=&#34;two-functions-for-pivoting-data&#34;&gt;Two functions for pivoting data&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; makes datasets longer by increasing the number of rows, and reducing the number of columns. &lt;em&gt;Typically&lt;/em&gt;, we use &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt; to make an untidy dataset tidy, since untidy datasets often have multiple columns for a single variable, and multiple observations in a single row.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_wider.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_wider()&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; makes datasets wider by increasing the number of columns, and reducing the number of rows. &lt;em&gt;Typically&lt;/em&gt;, &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_wider.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_wider()&lt;/code&gt;&lt;/a&gt; will make a dataset untidy &amp;ndash; but that can still be useful, as we&amp;rsquo;ll see next week.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;how-does-pivoting-work&#34;&gt;How does pivoting work?&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s start with a very simple dataset to make it easier to see what&amp;rsquo;s happening:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Row-wise tibble creation with the &#39;tribble()&#39; function&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tibble.tidyverse.org/reference/tribble.html&#39;&gt;tribble&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;var&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;col1&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;col2&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;   &lt;span class=&#39;s&#39;&gt;&#34;A&#34;&lt;/span&gt;,     &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,     &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;   &lt;span class=&#39;s&#39;&gt;&#34;B&#34;&lt;/span&gt;,     &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;,     &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;   &lt;span class=&#39;s&#39;&gt;&#34;C&#34;&lt;/span&gt;,     &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;,     &lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   var    col1  col2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; A         1     2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; B         3     4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; C         5     6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can tidy &lt;code&gt;df&lt;/code&gt; using &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/pivot_longer.html&#39;&gt;pivot_longer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;col1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;col2&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;    names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;names&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;    values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;values&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   var   names values&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; A     col1       1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; A     col2       2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; B     col1       3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; B     col2       4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; C     col1       5&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; C     col2       6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;It&amp;rsquo;s easier to see how pivot_longer works if we take it component by component. Let us look at how it works visually using Figure 6.3, Figure 6.4, and Figure 6.5 in the book.&lt;/p&gt;
&lt;h3 id=&#34;example-with-data-in-column-names&#34;&gt;Example with data in column names&lt;/h3&gt;
&lt;p&gt;This example will work with the &lt;code&gt;billboard&lt;/code&gt; dataframe that is loaded along with the &lt;em&gt;tidyverse&lt;/em&gt;. This dataset records the billboard rank of songs in the year 2000:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;billboard&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 317 × 79&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    artist track date.ent…¹   wk1   wk2   wk3   wk4   wk5   wk6   wk7   wk8   wk9&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;date&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; 2 Pac  Baby… 2000-02-26    87    82    72    77    87    94    99    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; 2Ge+h… The … 2000-09-02    91    87    92    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; 3 Doo… Kryp… 2000-04-08    81    70    68    67    66    57    54    53    51&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; 3 Doo… Loser 2000-10-21    76    76    72    69    67    65    55    59    62&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; 504 B… Wobb… 2000-04-15    57    34    25    17    17    31    36    49    53&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; 98^0   Give… 2000-08-19    51    39    34    26    26    19     2     2     3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; A*Tee… Danc… 2000-07-08    97    97    96    95   100    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Aaliy… I Do… 2000-01-29    84    62    51    41    38    35    35    38    38&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Aaliy… Try … 2000-03-18    59    53    38    28    21    18    16    14    12&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Adams… Open… 2000-08-26    76    76    74    69    68    67    61    58    57&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 307 more rows, 67 more variables: wk10 &amp;lt;dbl&amp;gt;, wk11 &amp;lt;dbl&amp;gt;, wk12 &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk13 &amp;lt;dbl&amp;gt;, wk14 &amp;lt;dbl&amp;gt;, wk15 &amp;lt;dbl&amp;gt;, wk16 &amp;lt;dbl&amp;gt;, wk17 &amp;lt;dbl&amp;gt;, wk18 &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk19 &amp;lt;dbl&amp;gt;, wk20 &amp;lt;dbl&amp;gt;, wk21 &amp;lt;dbl&amp;gt;, wk22 &amp;lt;dbl&amp;gt;, wk23 &amp;lt;dbl&amp;gt;, wk24 &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk25 &amp;lt;dbl&amp;gt;, wk26 &amp;lt;dbl&amp;gt;, wk27 &amp;lt;dbl&amp;gt;, wk28 &amp;lt;dbl&amp;gt;, wk29 &amp;lt;dbl&amp;gt;, wk30 &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk31 &amp;lt;dbl&amp;gt;, wk32 &amp;lt;dbl&amp;gt;, wk33 &amp;lt;dbl&amp;gt;, wk34 &amp;lt;dbl&amp;gt;, wk35 &amp;lt;dbl&amp;gt;, wk36 &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk37 &amp;lt;dbl&amp;gt;, wk38 &amp;lt;dbl&amp;gt;, wk39 &amp;lt;dbl&amp;gt;, wk40 &amp;lt;dbl&amp;gt;, wk41 &amp;lt;dbl&amp;gt;, wk42 &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk43 &amp;lt;dbl&amp;gt;, wk44 &amp;lt;dbl&amp;gt;, wk45 &amp;lt;dbl&amp;gt;, wk46 &amp;lt;dbl&amp;gt;, wk47 &amp;lt;dbl&amp;gt;, wk48 &amp;lt;dbl&amp;gt;, …&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We will use &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt; to tidy this dataframe:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;billboard&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/pivot_longer.html&#39;&gt;pivot_longer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/starts_with.html&#39;&gt;starts_with&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;wk&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;    names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;week&#34;&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;    values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;rank&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 24,092 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    artist track                   date.entered week   rank&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;date&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk1      87&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk2      82&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk3      72&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk4      77&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk5      87&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk6      94&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk7      99&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk8      &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk9      &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk10     &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 24,082 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Pivot longer has the following key arguments:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;cols&lt;/code&gt; &amp;ndash; these are the columns that should be combined into 2 columns, namely:&lt;/li&gt;
&lt;li&gt;&lt;code&gt;names_to&lt;/code&gt; &amp;ndash; the name you would like to give to the new column whose values will hold what were the &lt;em&gt;column names&lt;/em&gt; in the original dataframe&lt;/li&gt;
&lt;li&gt;&lt;code&gt;values_to&lt;/code&gt; &amp;ndash; the name you would like to give to the new column whose values will hold what were the &lt;em&gt;column valies&lt;/em&gt; in the original dataframe.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can see that we get some &lt;code&gt;NA&lt;/code&gt;s after pivoting. In this case, &lt;code&gt;NA&lt;/code&gt;s are forced to exist because of the structure of the dataset: that is, they aren&amp;rsquo;t actual missing values. It would therefore make sense to get rid of them, which we can do with &lt;code&gt;values_drop_na = TRUE&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;billboard&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/pivot_longer.html&#39;&gt;pivot_longer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/starts_with.html&#39;&gt;starts_with&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;wk&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;    names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;week&#34;&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;    values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;rank&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;    values_drop_na &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 5,307 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    artist  track                   date.entered week   rank&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;date&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26   wk1      87&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26   wk2      82&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26   wk3      72&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26   wk4      77&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26   wk5      87&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26   wk6      94&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26   wk7      99&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; 2Ge+her The Hardest Part Of ... 2000-09-02   wk1      91&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; 2Ge+her The Hardest Part Of ... 2000-09-02   wk2      87&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; 2Ge+her The Hardest Part Of ... 2000-09-02   wk3      92&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 5,297 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This data is now tidy, but we could make future computations a bit easier by converting the values in the column &lt;code&gt;week&lt;/code&gt; (&lt;code&gt;wk1&lt;/code&gt;, &lt;code&gt;wk2&lt;/code&gt;, etc.) into a number using &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://readr.tidyverse.org/reference/parse_number.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;readr::parse_number()&lt;/code&gt;&lt;/a&gt;. &lt;a href=&#34;https://readr.tidyverse.org/reference/parse_number.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;parse_number()&lt;/code&gt;&lt;/a&gt; is a handy function that will extract the numbers from a string, removing all other characters:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;billboard_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;billboard&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/pivot_longer.html&#39;&gt;pivot_longer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/starts_with.html&#39;&gt;starts_with&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;wk&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;    names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;week&#34;&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;    values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;rank&#34;&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;    values_drop_na &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    week &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/parse_number.html&#39;&gt;parse_number&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;week&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;billboard_tidy&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 5,307 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    artist  track                   date.entered  week  rank&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;date&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26       1    87&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26       2    82&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26       3    72&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26       4    77&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26       5    87&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26       6    94&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; 2 Pac   Baby Don&#39;t Cry (Keep... 2000-02-26       7    99&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; 2Ge+her The Hardest Part Of ... 2000-09-02       1    91&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; 2Ge+her The Hardest Part Of ... 2000-09-02       2    87&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; 2Ge+her The Hardest Part Of ... 2000-09-02       3    92&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 5,297 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now we&amp;rsquo;re in a good position to look at how song ranks vary over time by drawing a plot. The code is shown below and the result is Figure 6.2.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;billboard_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;week&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rank&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;track&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_path.html&#39;&gt;geom_line&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;/&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/scale_continuous.html&#39;&gt;scale_y_reverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-2&#34;&gt;Breakout Rooms 2&lt;/h2&gt;
&lt;p&gt;In the exercises, you&amp;rsquo;ll work with some metabolite data from mass spectometry experiments on soybeans attacked by aphids. Specifically, there are 10 peaks from 38 metabolites.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s how you can download and read in that dataset:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Download the CSV file&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;file_URL&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/S05E02/Metabolite.csv&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;file_URL&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Metabolite.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Read the CSV file into a dataframe&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;metabolites&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Metabolite.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;Pivot the &lt;code&gt;metabolite&lt;/code&gt; dataframe to a long, tidy format. The resulting dataframe should pivot all the &lt;code&gt;Peak&lt;/code&gt; columns, such that it will have only 3 columns: &lt;code&gt;Soy_Metabolite&lt;/code&gt; as before, and the new columns &lt;code&gt;peak_nr&lt;/code&gt; and &lt;code&gt;count&lt;/code&gt;. Store the result in a new dataframe called &lt;code&gt;metabolites_long&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Bonus: What are the number of rows and columns of &lt;code&gt;metabolites&lt;/code&gt; and &lt;code&gt;metabolites_long&lt;/code&gt;?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Use the &lt;a href=&#34;https://tidyr.tidyverse.org/reference/pivot_longer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pivot_longer()&lt;/code&gt;&lt;/a&gt; function.&lt;/li&gt;
&lt;li&gt;You could use &lt;code&gt;starts_with(&amp;quot;Peak&amp;quot;)&lt;/code&gt; to select all the &amp;ldquo;Peak&amp;rdquo; columns.&lt;/li&gt;
&lt;li&gt;The Peak column names should go into the new column &lt;code&gt;peak_nr&lt;/code&gt;, and the Peak values should go into the new column &lt;code&gt;count&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;metabolites_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;metabolites&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/pivot_longer.html&#39;&gt;pivot_longer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/starts_with.html&#39;&gt;starts_with&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Peak&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;               names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;peak_nr&#34;&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;               values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;count&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;metabolites_long&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 380 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    Soy_Metabolite peak_nr    count&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Alprazolam     Peak1    &lt;span style=&#39;text-decoration: underline;&#39;&gt;373&lt;/span&gt;291.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Alprazolam     Peak2    &lt;span style=&#39;text-decoration: underline;&#39;&gt;207&lt;/span&gt;793.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Alprazolam     Peak3     &lt;span style=&#39;text-decoration: underline;&#39;&gt;96&lt;/span&gt;152.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Alprazolam     Peak4    &lt;span style=&#39;text-decoration: underline;&#39;&gt;462&lt;/span&gt;212.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Alprazolam     Peak5    &lt;span style=&#39;text-decoration: underline;&#39;&gt;468&lt;/span&gt;161.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Alprazolam     Peak6   1&lt;span style=&#39;text-decoration: underline;&#39;&gt;250&lt;/span&gt;863 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Alprazolam     Peak7     &lt;span style=&#39;text-decoration: underline;&#39;&gt;62&lt;/span&gt;486.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Alprazolam     Peak8    &lt;span style=&#39;text-decoration: underline;&#39;&gt;190&lt;/span&gt;680.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Alprazolam     Peak9    &lt;span style=&#39;text-decoration: underline;&#39;&gt;530&lt;/span&gt;639.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Alprazolam     Peak10    &lt;span style=&#39;text-decoration: underline;&#39;&gt;64&lt;/span&gt;183.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 370 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Bonus: &lt;code&gt;metabolites&lt;/code&gt; has 38 rows and 11 columns, whereas &lt;code&gt;metabolites_long&lt;/code&gt; has 380 rows and 3 columns:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;metabolites&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 38 11&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;metabolites_long&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 380   3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;p&gt;Add a column to &lt;code&gt;metabolites_long&lt;/code&gt; with the count in units of 1000s by dividing the count column by 1000, and name the new variable &lt;code&gt;count_k&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Take a moment to realize that this is much easier to compute once the data is in a tidy format, and the same is true for the bonus activities below.&lt;/p&gt;
&lt;p&gt;Bonus:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;ve used &lt;a href=&#34;https://dplyr.tidyverse.org/reference/group_by.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;group_by()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt; before, try to compute the mean count per metabolite.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;ve made &lt;code&gt;ggplot&lt;/code&gt;s before, make a boxplot of metabolite counts, with counts across Peaks along the x-axis, and metabolites along the y-axis.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Use the &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; function similar to the first example with &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; in this session.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;metabolites_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;count_k &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;count&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 380 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    Soy_Metabolite peak_nr    count count_k&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Alprazolam     Peak1    &lt;span style=&#39;text-decoration: underline;&#39;&gt;373&lt;/span&gt;291.   373. &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Alprazolam     Peak2    &lt;span style=&#39;text-decoration: underline;&#39;&gt;207&lt;/span&gt;793.   208. &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Alprazolam     Peak3     &lt;span style=&#39;text-decoration: underline;&#39;&gt;96&lt;/span&gt;152.    96.2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Alprazolam     Peak4    &lt;span style=&#39;text-decoration: underline;&#39;&gt;462&lt;/span&gt;212.   462. &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Alprazolam     Peak5    &lt;span style=&#39;text-decoration: underline;&#39;&gt;468&lt;/span&gt;161.   468. &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Alprazolam     Peak6   1&lt;span style=&#39;text-decoration: underline;&#39;&gt;250&lt;/span&gt;863   &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;251. &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Alprazolam     Peak7     &lt;span style=&#39;text-decoration: underline;&#39;&gt;62&lt;/span&gt;486.    62.5&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Alprazolam     Peak8    &lt;span style=&#39;text-decoration: underline;&#39;&gt;190&lt;/span&gt;680.   191. &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Alprazolam     Peak9    &lt;span style=&#39;text-decoration: underline;&#39;&gt;530&lt;/span&gt;639.   531. &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Alprazolam     Peak10    &lt;span style=&#39;text-decoration: underline;&#39;&gt;64&lt;/span&gt;183.    64.2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 370 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Bonus 1:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;metabolites_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Soy_Metabolite&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_count &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 38 × 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    Soy_Metabolite   mean_count&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                 &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Alprazolam          &lt;span style=&#39;text-decoration: underline;&#39;&gt;370&lt;/span&gt;646.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Bretazenil          &lt;span style=&#39;text-decoration: underline;&#39;&gt;167&lt;/span&gt;582.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Bromazepam          &lt;span style=&#39;text-decoration: underline;&#39;&gt;865&lt;/span&gt;158.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Brotizolam         1&lt;span style=&#39;text-decoration: underline;&#39;&gt;194&lt;/span&gt;049.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Chlordiazepoxide     &lt;span style=&#39;text-decoration: underline;&#39;&gt;87&lt;/span&gt;565.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Cinolazepam         &lt;span style=&#39;text-decoration: underline;&#39;&gt;428&lt;/span&gt;290.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Clonazepam          &lt;span style=&#39;text-decoration: underline;&#39;&gt;889&lt;/span&gt;529.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Clorazepate          &lt;span style=&#39;text-decoration: underline;&#39;&gt;53&lt;/span&gt;912.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Clotiazepam          &lt;span style=&#39;text-decoration: underline;&#39;&gt;57&lt;/span&gt;847.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Cloxazolam          &lt;span style=&#39;text-decoration: underline;&#39;&gt;144&lt;/span&gt;292.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 28 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Bonus 2:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;metabolites_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Soy_Metabolite&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-20-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;br&gt;
</description>
    </item>
    
    <item>
      <title>S05E01: R for Data Science (2e) - Ch. 5 - Pipes</title>
      <link>https://biodash.github.io/codeclub/s05e01_pipes/</link>
      <pubDate>Thu, 26 Jan 2023 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s05e01_pipes/</guid>
      <description>&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/r4ds_cover.png width=&#34;45%&#34;&gt;
&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;intro-to-this-code-club-season&#34;&gt;Intro to this Code Club Season&lt;/h2&gt;
&lt;h4 id=&#34;organizers&#34;&gt;Organizers&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Michael Broe&lt;/em&gt; &amp;ndash; Evolution, Ecology and Organismal Biology (EEOB)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Jessica Cooperstone&lt;/em&gt; &amp;ndash; Horticulture &amp;amp; Crop Science (HCS) / Food Science &amp;amp; Technology (FST)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Stephen Opiyo&lt;/em&gt; &amp;ndash; Molecular &amp;amp; Cellular Imaging Center (MCIC) - Columbus&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Jelmer Poelstra&lt;/em&gt; &amp;ndash; Molecular &amp;amp; Cellular Imaging Center (MCIC) - Wooster&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;code-club-practicalities&#34;&gt;Code Club practicalities&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;In-person (Columbus &amp;amp; Wooster) and Zoom hybrid&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Mix of instruction/discussion with the entire group, and exercises in groups of 3-4 people.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When doing &lt;strong&gt;exercises in breakout groups&lt;/strong&gt;, we encourage you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;To briefly introduce yourselves and to do the exercises as a group&lt;/li&gt;
&lt;li&gt;On Zoom, to turn your cameras on and to have someone share their screen (use the &lt;code&gt;Ask for help&lt;/code&gt; button in Zoom to get help from an organizer)&lt;/li&gt;
&lt;li&gt;To let a &lt;em&gt;less&lt;/em&gt; experienced person do the screen sharing and coding&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can &lt;strong&gt;ask a question&lt;/strong&gt; at any time, by speaking or typing in the Zoom chat.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can come up to 15 minutes early or stay late for &lt;strong&gt;troubleshooting&lt;/strong&gt; and perhaps a question related to your research.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;More general notes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you can, read or skim the relevant (part of the) chapter before each session, especially if you&amp;rsquo;re very new to the material. But we&amp;rsquo;ll always try to present it in such a way that does not assume you&amp;rsquo;ve read it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We try to make each session &lt;strong&gt;as stand-alone as possible&lt;/strong&gt;, and don&amp;rsquo;t require you to know anything. That said, if you missed one or more sessions, you&amp;rsquo;ll get more out of the next ones if you try to catch up with the material.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We &lt;strong&gt;record&lt;/strong&gt; the whole-group parts of the Zoom call, and share the recordings only with Code Club participants.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;new-to-code-club-or-r&#34;&gt;New to Code Club or R?&lt;/h4&gt;
&lt;p&gt;Take a look at these pages on our website:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Computer setup for Code Club&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/&#34;&gt;Resources and tips to get started with R&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub-schedule/#previous-semesters&#34;&gt;List of all previous Code Club session topics&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Before moving on the the chapter on pipes, I will start with a very brief overview of the book, the RStudio interface, and how to load R packages.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;r-for-data-science-r4ds&#34;&gt;R for Data Science (R4DS)&lt;/h2&gt;
&lt;p&gt;This excellent book by Hadley Wickham (also author of many of the R packages used in the book!) and Garret Grolemund is &lt;a href=&#34;https://r4ds.hadley.nz/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;freely available online&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The book focuses on the so-called &lt;strong&gt;&amp;quot;&lt;em&gt;tidyverse&lt;/em&gt;&amp;quot; ecosystem&lt;/strong&gt; in R. The &lt;em&gt;tidyverse&lt;/em&gt; can be seen as a &lt;strong&gt;modern dialect of R&lt;/strong&gt;. Most of its functionality is also contained in &amp;ldquo;base R&amp;rdquo; (that which comes shipped with R by default), but it has an improved and more consistent programming interface or &amp;ldquo;syntax&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Last year in Code Club, we worked through the material of a number of chapters of the &lt;a href=&#34;https://r4ds.had.co.nz/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;first edition of the book&lt;/a&gt;, which was published in 2016.&lt;/p&gt;
&lt;p&gt;Since 2016, quite some R development has taken place. A &lt;strong&gt;second edition&lt;/strong&gt; has been online since a couple of months, with completely updated and also restructured contents &amp;ndash; we thought it has improved a lot!&lt;/p&gt;
&lt;p&gt;This new edition is not &lt;em&gt;completely&lt;/em&gt; finished yet, so you&amp;rsquo;ll find notifications like these at the top of each chapter:&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/work-in-progress-warning.png width=&#34;95%&#34;&gt;
&lt;/p&gt;
&lt;p&gt;We decided &lt;strong&gt;not to restart at the beginning of the book&lt;/strong&gt; for this semester. We hope this won&amp;rsquo;t make it too challenging for beginners to join us. Especially in the first sessions, we&amp;rsquo;ll make sure to explain all code, including things that were covered last semester.&lt;/p&gt;
&lt;h4 id=&#34;whats-in-the-book&#34;&gt;What&amp;rsquo;s in the book&lt;/h4&gt;
&lt;p&gt;The introductory chapter of the book has this figure to show the data science process and what the book will cover:&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/data-science.png width=&#34;80%&#34;&gt;
&lt;/p&gt;
&lt;p&gt;In terms of what the book does &lt;em&gt;not&lt;/em&gt; cover, it may especially be surprising for a book about data science that it contains very little material on &lt;em&gt;statistics&lt;/em&gt; (even less so in the second edition, now that there is a companion book &lt;a href=&#34;https://www.tmwr.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&amp;ldquo;Tidy Modeling with R&amp;rdquo;&lt;/a&gt; on that topic).&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;getting-up-and-running&#34;&gt;Getting Up and Running&lt;/h2&gt;
&lt;h3 id=&#34;rstudio-interface&#34;&gt;RStudio interface&lt;/h3&gt;
&lt;p&gt;R itself simply provides a &amp;ldquo;&lt;em&gt;console&lt;/em&gt;&amp;rdquo; (command-line interface) where you can type your commands. RStudio, on the other hand, allows you to see the R console side-by-side with your scripts, plots, and more.&lt;/p&gt;
&lt;p&gt;Once you have a running instance of RStudio, &lt;strong&gt;create a new R script&lt;/strong&gt; by clicking &lt;code&gt;File&lt;/code&gt; &amp;gt; &lt;code&gt;New File&lt;/code&gt; &amp;gt; &lt;code&gt;R Script&lt;/code&gt;. Now, you should see all 4 &amp;ldquo;panes&amp;rdquo; that the RStudio window is divided into:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Top-left&lt;/em&gt;: The &lt;strong&gt;Editor&lt;/strong&gt; for your scripts and other documents (&lt;em&gt;hidden when no file is open&lt;/em&gt;)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Bottom-left&lt;/em&gt;: The &lt;strong&gt;R Console&lt;/strong&gt; to interactively run your code (+ other tabs)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Top-right&lt;/em&gt;: Your &lt;strong&gt;Environment&lt;/strong&gt; with R objects you have created (+ other tabs)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Bottom-right&lt;/em&gt;: Tabs for &lt;strong&gt;Files&lt;/strong&gt;, &lt;strong&gt;Plots&lt;/strong&gt;, &lt;strong&gt;Help&lt;/strong&gt;, and others&lt;/li&gt;
&lt;/ul&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/rstudio-layout-ed.png width=&#34;95%&#34;&gt;
&lt;/p&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;your-turn-check-your-r-version&#34;&gt;Your turn: Check your R version&lt;/h3&gt;
&lt;p&gt;Take a look at your &lt;em&gt;&lt;strong&gt;version of R&lt;/strong&gt;&lt;/em&gt;: this was printed in the console when you started RStudio (see the RStudio screenshot above).&lt;/p&gt;
&lt;p&gt;The most recent version of R is &lt;code&gt;4.2.2&lt;/code&gt;. To use all current functionality of the &amp;ldquo;base R pipe&amp;rdquo;, you&amp;rsquo;ll need at least version &lt;code&gt;4.2.0&lt;/code&gt;, and &lt;strong&gt;to use the base R pipe at all, you need at least R version &lt;code&gt;4.1&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;If you have a lower version of R, I would recommend that you update at the end or after this session following &lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/#updating-r&#34;&gt;these instructions&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h3 id=&#34;r-packages&#34;&gt;R packages&lt;/h3&gt;
&lt;p&gt;You can think of packages as &amp;ldquo;add-ons&amp;rdquo; / &amp;ldquo;extensions&amp;rdquo; to base R functionality.&lt;/p&gt;
&lt;h4 id=&#34;installation-versus-loading&#34;&gt;Installation versus loading&lt;/h4&gt;
&lt;p&gt;To be able to use them, packages have to be &lt;strong&gt;installed&lt;/strong&gt; (usually &lt;em&gt;from within R&lt;/em&gt;, using R code). Once you have done this, you don&amp;rsquo;t need to redo it until you switch to a different version of R.&lt;/p&gt;
&lt;p&gt;Unlike installation, &lt;strong&gt;loading&lt;/strong&gt; a package is necessary again and again, in every R session that you want to use it.&lt;/p&gt;
&lt;h4 id=&#34;the-tidyverse&#34;&gt;The tidyverse&lt;/h4&gt;
&lt;p&gt;The &lt;em&gt;tidyverse&lt;/em&gt; is unusual in that it is a &lt;em&gt;collection&lt;/em&gt; of packages that can still be installed and loaded with a single command. The individual core &lt;em&gt;tidyverse&lt;/em&gt; packages are the focus of several chapters in the book, for instance:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Package&lt;/th&gt;
&lt;th&gt;Functionality&lt;/th&gt;
&lt;th&gt;Main chapter&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;&lt;strong&gt;ggplot2&lt;/strong&gt;&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Creating plots&lt;/td&gt;
&lt;td&gt;Ch. 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;&lt;strong&gt;tidyr&lt;/strong&gt;&lt;/em&gt; &amp;amp; &lt;em&gt;&lt;strong&gt;dplyr&lt;/strong&gt;&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Manipulating dataframes&lt;/td&gt;
&lt;td&gt;Ch. 4 &amp;amp; 6&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;&lt;strong&gt;readr&lt;/strong&gt;&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Reading in data&lt;/td&gt;
&lt;td&gt;Ch. 8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;&lt;strong&gt;stringr&lt;/strong&gt;&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Working with &amp;ldquo;strings&amp;rdquo; (text)&lt;/td&gt;
&lt;td&gt;Ch. 16&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;&lt;strong&gt;forcats&lt;/strong&gt;&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Working with &amp;ldquo;factors&amp;rdquo; &lt;br&gt; (categorical variables)&lt;/td&gt;
&lt;td&gt;Ch. 18&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;&lt;strong&gt;purrr&lt;/strong&gt;&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Iteration with functions&lt;/td&gt;
&lt;td&gt;Ch. 28&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;your-turn-load-the-tidyverse&#34;&gt;Your turn: Load the tidyverse&lt;/h3&gt;
&lt;p&gt;To check if you can load the &lt;em&gt;tidyverse&lt;/em&gt;, run the following and see if you get similar output as printed below:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/load_tidyverse.png width=&#34;90%&#34;&gt;
&lt;/p&gt;
&lt;p&gt;If instead, you got something like&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error in library(tidyverse) : there is no package called ‘tidyverse’&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&amp;hellip;then you still need to install it (&lt;code&gt;install.packages(&amp;quot;tidyverse&amp;quot;)&lt;/code&gt;).&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;the-diamonds-dataframe&#34;&gt;The &lt;code&gt;diamonds&lt;/code&gt; dataframe&lt;/h3&gt;
&lt;p&gt;In R, we work a lot with &amp;ldquo;dataframes&amp;rdquo;, rectangular data structures like spreadsheets &amp;ndash; and in particular, the R4DS book and the &lt;em&gt;tidyverse&lt;/em&gt; focus on this very heavily.&lt;/p&gt;
&lt;p&gt;Today we&amp;rsquo;ll see some examples of using the pipe with the &lt;code&gt;diamonds&lt;/code&gt; dataframe, which is automatically loaded along with the &lt;em&gt;tidyverse&lt;/em&gt;. It contains information on almost 54,000 diamonds (one diamond per row):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Simply typing the dataframe&#39;s name in the console will print the first rows:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 53,940 × 10&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    carat cut       color clarity depth table price     x     y     z&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  0.23 Ideal     E     SI2      61.5    55   326  3.95  3.98  2.43&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  0.21 Premium   E     SI1      59.8    61   326  3.89  3.84  2.31&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  0.23 Good      E     VS1      56.9    65   327  4.05  4.07  2.31&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  0.29 Premium   I     VS2      62.4    58   334  4.2   4.23  2.63&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  0.31 Good      J     SI2      63.3    58   335  4.34  4.35  2.75&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  0.24 Very Good J     VVS2     62.8    57   336  3.94  3.96  2.48&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  0.24 Very Good I     VVS1     62.3    57   336  3.95  3.98  2.47&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  0.26 Very Good H     SI1      61.9    55   337  4.07  4.11  2.53&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  0.22 Fair      E     VS2      65.1    61   337  3.87  3.78  2.49&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  0.23 Very Good H     VS1      59.4    61   338  4     4.05  2.39&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 53,930 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;em&gt;(If you get &lt;code&gt;Error: object &#39;diamonds&#39; not found&lt;/code&gt;, then the tidyverse isn&amp;rsquo;t loaded.&lt;/em&gt; &lt;em&gt;Use &lt;a href=&#34;https://tidyverse.tidyverse.org&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library(tidyverse)&lt;/code&gt;&lt;/a&gt; to do so.)&lt;/em&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;chapter-5-pipes&#34;&gt;Chapter 5: Pipes&lt;/h2&gt;
&lt;h3 id=&#34;what-is-a-pipe&#34;&gt;What is a pipe?&lt;/h3&gt;
&lt;p&gt;A pipe is a programming tool that takes the &lt;strong&gt;output&lt;/strong&gt; of one command (in R, a &lt;em&gt;function&lt;/em&gt;), and passes it on to be used as the &lt;strong&gt;input&lt;/strong&gt; for another command.&lt;/p&gt;
&lt;p&gt;Pipes prevent you from having to save intermediate output to a file or object. They also make your code shorter and easier to understand.&lt;/p&gt;
&lt;p&gt;To give a very minimal example &amp;ndash; without a pipe, we can print the number of rows in the &lt;code&gt;diamonds&lt;/code&gt; dataframe as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Use the `nrow()` function with `diamonds` as the sole argument:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 53940&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Instead, we could also take the &lt;code&gt;diamonds&lt;/code&gt; dataframe, and then pipe (&lt;code&gt;|&amp;gt;&lt;/code&gt;) it into the &lt;a href=&#34;https://rdrr.io/r/base/nrow.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;nrow()&lt;/code&gt;&lt;/a&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 53940&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice above that we no longer type the input argument to &lt;a href=&#34;https://rdrr.io/r/base/nrow.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;nrow()&lt;/code&gt;&lt;/a&gt; inside the parentheses: &lt;a href=&#34;https://rdrr.io/r/base/nrow.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;nrow()&lt;/code&gt;&lt;/a&gt; recognizes that data came in through the pipe.&lt;/p&gt;
&lt;h3 id=&#34;a-more-practical-example&#34;&gt;A more practical example&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s say we want to subset the &lt;code&gt;diamonds&lt;/code&gt; dataframe to &lt;strong&gt;only show the columns &lt;code&gt;color&lt;/code&gt;, &lt;code&gt;depth&lt;/code&gt;, and &lt;code&gt;price&lt;/code&gt;&lt;/strong&gt; &lt;strong&gt;for diamonds with a depth smaller than 50&lt;/strong&gt;. Without using pipes, we could start by selecting the columns of interest with the &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; function, and saving the output in a new dataframe called &lt;code&gt;diamonds_simple&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# The first argument is the input dataframe, the others are the columns we want&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds_simple&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;color&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;depth&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Next, we can use the &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; function on &lt;code&gt;diamonds_simple&lt;/code&gt; to only return the diamonds (&lt;em&gt;rows&lt;/em&gt;) that we want:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# The first argument is the input dataframe, the next is an expression to filter by&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds_simple&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;depth&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   color depth price&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; G        43  &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;634&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; G        44  &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;032&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; J        43  &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;778&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;But using the pipe, we can do this more elegantly, and without wasting computer memory on an intermediate object:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;                       &lt;span class=&#39;c&#39;&gt;# Take &#39;diamonds&#39; and push it through the pipe&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;color&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;depth&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;# No input is specified, and the output is piped&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;depth&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;              &lt;span class=&#39;c&#39;&gt;# Again, no input is specified&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   color depth price&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; G        43  &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;634&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; G        44  &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;032&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; J        43  &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;778&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We took the &lt;code&gt;diamonds&lt;/code&gt; dataset and piped it into the &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; function, and then we piped the output of &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; into the &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; function. Using the the pipe &lt;em&gt;before&lt;/em&gt; &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; is not necessary and adds a line, but also makes it even easier to see what&amp;rsquo;s being done!&lt;/p&gt;
&lt;p&gt;Like in the earlier example, when we use the pipe, we &lt;em&gt;don&amp;rsquo;t type the corresponding input argument&lt;/em&gt; in the receiving function: it knows to use the piped data. This is not completely &amp;ldquo;automagical&amp;rdquo; and foolproof though: what actually happens is that the piped data becomes the first argument to the receiving function.&lt;/p&gt;
&lt;p&gt;If you ever need to use the pipe with a function where the piped data is not the first argument, see the Bonus section below about using &lt;strong&gt;the &lt;code&gt;_&lt;/code&gt; placeholder&lt;/strong&gt;.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;two-unix--r-examples&#34;&gt;Two Unix &amp;amp; R examples&lt;/h4&gt;
&lt;p&gt;Pipes originate in Unix terminals, and are ubiquitous there. So for those of you that are curious, I&amp;rsquo;ve included two examples of using the Unix pipe, and the corresponding commands in R, in the dropdown box below.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;See the examples&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;&lt;em&gt;(If you&amp;rsquo;re trying to follow along yourself:&lt;/em&gt; &lt;em&gt;the Unix/terminal examples will only work natively on Mac and Linux,&lt;/em&gt; &lt;em&gt;where you can simply click the &lt;code&gt;Terminal&lt;/code&gt; tab in the bottom-left RStudio&lt;/em&gt; &lt;em&gt;panel next to &lt;code&gt;Console&lt;/code&gt;, and issue Unix commands.)&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Counting files&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You might want to &lt;em&gt;count the number of files in a folder&lt;/em&gt;, which involve two distinct processes: obtaining a list of files, and counting them.&lt;/p&gt;
&lt;p&gt;Using Unix commands, We can get a &lt;strong&gt;l&lt;/strong&gt;i&lt;strong&gt;s&lt;/strong&gt;t of files in the current folder with &lt;code&gt;ls&lt;/code&gt;, perform the counting with &lt;code&gt;wc -l&lt;/code&gt; (&lt;strong&gt;w&lt;/strong&gt;ord&lt;strong&gt;c&lt;/strong&gt;ount -&lt;strong&gt;l&lt;/strong&gt;ines), and connect these processes with the pipe &lt;code&gt;|&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;# The output of &#39;ls&#39; is piped (with &#39;|&#39;) to &#39;wc -l&#39;:
ls | wc -l


#&gt; 4&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;So, there happen to be 4 files in the folder this code is run in. We can do the same in R, where the function &lt;a href=&#34;https://rdrr.io/r/base/list.files.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dir()&lt;/code&gt;&lt;/a&gt; lists files, while the function &lt;a href=&#34;https://rdrr.io/r/base/length.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;length()&lt;/code&gt;&lt;/a&gt; counts the number of elements:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.files.html&#39;&gt;dir&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Counting word frequencies&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;As another example, let&amp;rsquo;s say we have a file &lt;code&gt;words.txt&lt;/code&gt; that contains one word per line:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;table
chair
desk
chair
desk
table
chair
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;In a terminal, we can get a list of unique words and their number of occurrences using:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;# &#39;cat&#39; prints the contents of the file
# &#39;sort&#39; sorts alphabetically
# &#39;uniq -c&#39; counts the number of occurrences for each entry 
cat words.txt | sort | uniq -c


#&gt;       3 chair
#&gt;       2 desk
#&gt;       2 table&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And to do the same thing in R:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# &#39;readLines()&#39; reads the contents of a file into R&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# &#39;table()&#39; counts the number of occurrences for each entry&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/readLines.html&#39;&gt;readLines&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;words.txt&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/table.html&#39;&gt;table&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; chair  desk table &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     3     2     2&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;the--pipe-and-a-keyboard-shortcut&#34;&gt;The &lt;code&gt;%&amp;gt;%&lt;/code&gt; pipe and a keyboard shortcut&lt;/h3&gt;
&lt;p&gt;Those of you who&amp;rsquo;ve worked with R for a bit are likely familiar with &lt;strong&gt;another pipe operator: &lt;code&gt;%&amp;gt;%&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;This pipe is loaded as part of the &lt;em&gt;tidyverse&lt;/em&gt;, and until recently was very widely used, including in the previous edition of R4DS. There has been a gradual switch to the base R pipe since that was introduced in May 2021, mainly because it does not rely on a package. In addition, it&amp;rsquo;s convenient that the base R pipe &lt;code&gt;|&amp;gt;&lt;/code&gt; is more similar to the Unix pipe &lt;code&gt;|&lt;/code&gt;, and is one fewer character to type than &lt;code&gt;%&amp;gt;%&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The number of characters shouldn&amp;rsquo;t make much of a difference, though, because it remains even quicker to use the &lt;strong&gt;RStudio keyboard shortcut for the pipe,&lt;/strong&gt; &lt;strong&gt;which is &lt;kbd&gt;Ctrl&lt;/kbd&gt;+&lt;kbd&gt;Shift&lt;/kbd&gt;+&lt;kbd&gt;M&lt;/kbd&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;There are some differences in the behavior of the &lt;code&gt;|&amp;gt;&lt;/code&gt; and &lt;code&gt;%&amp;gt;%&lt;/code&gt; pipes in more advanced use cases, which the book chapter goes into (check that out if you have used &lt;code&gt;%&amp;gt;%&lt;/code&gt; a lot).&lt;/p&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;your-turn-set-the--pipe-as-default&#34;&gt;Your turn: Set the &lt;code&gt;|&amp;gt;&lt;/code&gt; pipe as default&lt;/h3&gt;
&lt;p&gt;To make that keyboard shortcut &lt;em&gt;map to the base R pipe&lt;/em&gt; (instead of to &lt;code&gt;%&amp;gt;%&lt;/code&gt;), go to &lt;code&gt;Tools&lt;/code&gt; in the top menu bar, click &lt;code&gt;Global Options&lt;/code&gt;, click &lt;code&gt;Code&lt;/code&gt; in the left menu, and check the box &lt;code&gt;Use native pipe operator, |&amp;gt; (requires R 4.1+)&lt;/code&gt;:&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/rstudio-pipe-options.png width=&#34;85%&#34;&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;your-turn-use-the-pipe&#34;&gt;Your turn: Use the pipe&lt;/h3&gt;
&lt;p&gt;With one single &amp;ldquo;pipeline&amp;rdquo; (operations connected by a pipe &lt;code&gt;|&amp;gt;&lt;/code&gt;), manipulate the &lt;code&gt;diamonds&lt;/code&gt; dataframe such that you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Print only the columns &lt;code&gt;carat&lt;/code&gt;, &lt;code&gt;cut&lt;/code&gt;, &lt;code&gt;depth&lt;/code&gt;, and &lt;code&gt;price&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&amp;hellip; for diamonds (rows) with a &lt;code&gt;price&lt;/code&gt; of more than $1,000.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Bonus: &lt;em&gt;How many&lt;/em&gt; diamonds cost more than $1,000? And could you get this number directly, by expanding your &amp;ldquo;pipeline&amp;rdquo;?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;This is quite similar to the example given above: use the &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; function to select certain columns, and the &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; function to select certain rows.&lt;/p&gt;
&lt;p&gt;To answer the bonus question: each diamond is on one row, so you are counting rows. And to answer it by expanding your pipeline, recall from the very first pipe example that the &lt;a href=&#34;https://rdrr.io/r/base/nrow.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;nrow()&lt;/code&gt;&lt;/a&gt; function will print the number of rows.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt;(click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;depth&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 39,416 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    carat cut       depth price&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  0.7  Ideal      62.5  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;757&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  0.86 Fair       55.1  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;757&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  0.7  Ideal      61.6  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;757&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  0.71 Very Good  62.4  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;759&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  0.78 Very Good  63.8  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;759&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  0.7  Good       57.5  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;759&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  0.7  Good       59.4  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;759&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  0.96 Fair       66.3  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;759&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  0.73 Very Good  61.6  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;760&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  0.8  Premium    61.5  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;760&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 39,406 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;10 rows are printed to screen, and it says &lt;code&gt;… with 39,406 more rows&lt;/code&gt; at the bottom: therefore, there are 39,416 diamonds that cost more than $1,000.&lt;/p&gt;
&lt;p&gt;You can also get this number with code &amp;ndash; for instance by adding the &lt;a href=&#34;https://rdrr.io/r/base/nrow.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;nrow()&lt;/code&gt;&lt;/a&gt; function to the pipeline, which will count the number of rows (excluding the header line) in a dataframe:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;depth&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 39416&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-using-the-_-placeholder&#34;&gt;Bonus: Using the &lt;code&gt;_&lt;/code&gt; placeholder&lt;/h3&gt;
&lt;p&gt;By default, the R pipe passes its contents to the &lt;em&gt;first argument&lt;/em&gt; of a function. What if we need our piped data to go to another argument than the function&amp;rsquo;s first one?&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s see an example with the &lt;a href=&#34;https://rdrr.io/r/base/grep.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;gsub()&lt;/code&gt;&lt;/a&gt; function, which can be used to replace characters in text strings as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# This will replace &#39;N&#39;s with &#39;-&#39; in the string &#39;ACCGNNT&#39;: &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/grep.html&#39;&gt;gsub&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;pattern &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;N&#34;&lt;/span&gt;, replacement &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;-&#34;&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ACCGNNT&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;ACCG--T&#34;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;em&gt;(For clarity, I named &lt;a href=&#34;https://rdrr.io/r/base/grep.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;gsub()&lt;/code&gt;&lt;/a&gt;&amp;rsquo;s arguments above.&lt;/em&gt; &lt;em&gt;Without naming the arguments, it would be: &lt;code&gt;gsub(&amp;quot;N&amp;quot;, &amp;quot;-&amp;quot;, &amp;quot;ACCGNNT&amp;quot;)&lt;/code&gt;).&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;As you could see above, what we would usually think of as the input data, the string passed to the argument &lt;code&gt;x&lt;/code&gt;, is not the first but the third argument to &lt;a href=&#34;https://rdrr.io/r/base/grep.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;gsub()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To make the pipe work with &lt;a href=&#34;https://rdrr.io/r/base/grep.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;gsub()&lt;/code&gt;&lt;/a&gt;, &lt;strong&gt;use an underscore (&lt;code&gt;_&lt;/code&gt;) as a placeholder&lt;/strong&gt; that indicates where the piped data goes:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;s&#39;&gt;&#34;ACCGNNT&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/grep.html&#39;&gt;gsub&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;pattern &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;N&#34;&lt;/span&gt;, replacement &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;-&#34;&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;_&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;ACCG--T&#34;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As an aside, if you&amp;rsquo;re wondering how you&amp;rsquo;d know a function&amp;rsquo;s argument order, watch the pop-up box when you type a function&amp;rsquo;s name and the opening parenthesis (see the screenshot below), or check the help e.g. by typing &lt;a href=&#34;https://rdrr.io/r/base/grep.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;?gsub&lt;/code&gt;&lt;/a&gt; in the Console.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/gsub.png width=&#34;45%&#34;&gt;
&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Above, I mentioned that the pipe passes its contents to the &lt;em&gt;first argument&lt;/em&gt; of a function. But to be more precise, the pipe passes the object to &lt;em&gt;the first argument that you didn&amp;rsquo;t mention by name&lt;/em&gt;. Therefore, the following also works:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# The piped data is being passed to the 3rd argument, &#39;x&#39;,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# which is the first of the function&#39;s arguments that we don&#39;t refer to below: &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;s&#39;&gt;&#34;ACCGNNT&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&amp;gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/grep.html&#39;&gt;gsub&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;pattern &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;N&#34;&lt;/span&gt;, replacement &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;-&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;ACCG--T&#34;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Additionally, when you do use the &lt;code&gt;_&lt;/code&gt; placeholder, make sure you &lt;strong&gt;always &lt;em&gt;name&lt;/em&gt; the argument that you pass it to&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;# Using &#39;_&#39; without the argument name (&#39;x=&#39;) doesn&#39;t work:
&#34;ACCGNNT&#34; |&gt; gsub(pattern = &#34;N&#34;, replacement = &#34;-&#34;, _)

&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error: pipe placeholder can only be used as a named argument&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;br&gt;
</description>
    </item>
    
    <item>
      <title>S04E16: R for Data Science - Exploratory Data Analysis II</title>
      <link>https://biodash.github.io/codeclub/s04e16/</link>
      <pubDate>Thu, 01 Dec 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s04e16/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;setting-up&#34;&gt;Setting up&lt;/h2&gt;
&lt;p&gt;Like last time, we&amp;rsquo;ll mostly use &lt;em&gt;tidyverse&lt;/em&gt; tools to explore the &lt;code&gt;diamonds&lt;/code&gt; dataset, which is also part of the &lt;em&gt;tidyverse&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll also have one look at the &lt;code&gt;flights&lt;/code&gt; dataset, for which we&amp;rsquo;ll need to load the &lt;em&gt;nycflights13&lt;/em&gt; package:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;## You only need to install packages if you haven&#39;t previously done so&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;nycflights13&#34;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;tidyverse&#34;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;## But you&#39;ll have to load packages for every R session:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/hadley/nycflights13&#39;&gt;nycflights13&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching packages&lt;/span&gt; ─────────────────────────────────────── tidyverse 1.3.2 ──&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2&lt;/span&gt; 3.3.6      &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;purrr  &lt;/span&gt; 0.3.5 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tibble &lt;/span&gt; 3.1.8      &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr  &lt;/span&gt; 1.0.10&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr  &lt;/span&gt; 1.2.1      &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;stringr&lt;/span&gt; 1.4.1 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;readr  &lt;/span&gt; 2.1.3      &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;forcats&lt;/span&gt; 0.5.2 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt; masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::filter()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;    masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::lag()&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s again take a quick look at the &lt;code&gt;diamonds&lt;/code&gt; dataset before we begin:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 53,940 × 10&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    carat cut       color clarity depth table price     x     y     z&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  0.23 Ideal     E     SI2      61.5    55   326  3.95  3.98  2.43&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  0.21 Premium   E     SI1      59.8    61   326  3.89  3.84  2.31&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  0.23 Good      E     VS1      56.9    65   327  4.05  4.07  2.31&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  0.29 Premium   I     VS2      62.4    58   334  4.2   4.23  2.63&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  0.31 Good      J     SI2      63.3    58   335  4.34  4.35  2.75&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  0.24 Very Good J     VVS2     62.8    57   336  3.94  3.96  2.48&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  0.24 Very Good I     VVS1     62.3    57   336  3.95  3.98  2.47&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  0.26 Very Good H     SI1      61.9    55   337  4.07  4.11  2.53&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  0.22 Fair      E     VS2      65.1    61   337  3.87  3.78  2.49&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  0.23 Very Good H     VS1      59.4    61   338  4     4.05  2.39&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 53,930 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;On each row, we have information about one individual diamond, such as its &lt;code&gt;carat&lt;/code&gt; and &lt;code&gt;price&lt;/code&gt; (&lt;code&gt;x&lt;/code&gt;, &lt;code&gt;y&lt;/code&gt;, and &lt;code&gt;z&lt;/code&gt; represent the diamond&amp;rsquo;s length, width, and depth, respectively).&lt;/p&gt;
&lt;p&gt;Finally, we&amp;rsquo;ll again set a &lt;em&gt;ggplot2&lt;/em&gt; &amp;ldquo;theme&amp;rdquo; that is a little better-looking than the default one (this setting will apply until you restart R/RStudio):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# This changes two things:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# - theme_minimal() gives an overall different look, with a white background&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# - base_size = 14 will make the text relatively bigger&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/theme_get.html&#39;&gt;theme_set&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggtheme.html&#39;&gt;theme_minimal&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;base_size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;chapter-74-missing-values&#34;&gt;Chapter 7.4: Missing values&lt;/h2&gt;
&lt;h3 id=&#34;removing-outliers&#34;&gt;Removing outliers&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s assume you have established that certain outlier values in your data are untrustworthy. For instance, see the plot below for the &lt;code&gt;diamonds&lt;/code&gt; data, a scatterplot of diamond width (&lt;code&gt;y&lt;/code&gt;) versus depth (&lt;code&gt;z&lt;/code&gt;):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;z&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-4-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Three rather extreme outliers deviate not just in their absolute values, but also in their relative values: overall, depth and width are strongly correlated, yet the extremely large &lt;code&gt;z&lt;/code&gt; value does not correspond to a large &lt;code&gt;y&lt;/code&gt; value at all (and so on for the other outliers).&lt;/p&gt;
&lt;p&gt;To get rid of outliers in your dataset, you have two main options. First, you could &lt;strong&gt;completely remove rows that contain outliers&lt;/strong&gt;, for example with &lt;em&gt;dplyr&lt;/em&gt;&amp;rsquo;s &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Remove rows for which column y is smaller than 3 or larger than 20: &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds_no_outliers&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;But you may not want throw out entire rows, because the values for the &lt;em&gt;other variables&lt;/em&gt; (columns) in these rows might be valid and valuable. Therefore, an alternative is to &lt;strong&gt;convert outliers to &lt;code&gt;NA&lt;/code&gt;s (missing values)&lt;/strong&gt;, and a convenient way to do that is with the &lt;a href=&#34;https://rdrr.io/r/base/ifelse.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ifelse()&lt;/code&gt;&lt;/a&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds_NA_outliers&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/ifelse.html&#39;&gt;ifelse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;test &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;, yes &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;, no &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;more-on-ifelse&#34;&gt;More on &lt;code&gt;ifelse()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;To better understand &lt;a href=&#34;https://rdrr.io/r/base/ifelse.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ifelse()&lt;/code&gt;&lt;/a&gt;, a simple example may help. First, we create a vector with integers from 1 to 10:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  1  2  3  4  5  6  7  8  9 10&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The following expression will return a logical vector that indicates, for each value of &lt;code&gt;x&lt;/code&gt;, whether it is smaller than 5:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  TRUE  TRUE  TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can use that expression as the &lt;code&gt;test&lt;/code&gt; in &lt;a href=&#34;https://rdrr.io/r/base/ifelse.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ifelse()&lt;/code&gt;&lt;/a&gt;, and turn values smaller than 5 into &lt;code&gt;NA&lt;/code&gt; (&lt;code&gt;yes = NA&lt;/code&gt;), while leaving the other values unchanged (&lt;code&gt;no = x&lt;/code&gt;):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/ifelse.html&#39;&gt;ifelse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;test &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;, yes &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;, no &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] NA NA NA NA  5  6  7  8  9 10&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;comparing-observations-with-and-without-missing-data&#34;&gt;Comparing observations with and without missing data&lt;/h3&gt;
&lt;p&gt;It can be useful to compare distributions among rows with and without missing values. To do that, we can first create a new column that indicates whether a value for a variable of interest is missing or not. Then, we can map an aesthetic like &lt;code&gt;color&lt;/code&gt; to this missing-or-not column to show the two groups separately.&lt;/p&gt;
&lt;p&gt;Below, we&amp;rsquo;ll compare flights with and without missing values for departure time (&lt;code&gt;dep_time&lt;/code&gt;), i.e. cancelled and not-cancelled flights, using the geom &lt;code&gt;geom_freqpoly&lt;/code&gt; that we also saw last time:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cancelled &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sched_dep_time&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cancelled&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_freqpoly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;binwidth &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# (100 = 1 hour, so we plot by hour)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-10-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;However, the large difference in the absolute counts of cancelled versus not-cancelled flights makes it hard to see relative differences along the x-axis.&lt;/p&gt;
&lt;p&gt;We can use &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_density.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_density()&lt;/code&gt;&lt;/a&gt; to produce a &lt;strong&gt;density plot&lt;/strong&gt;, where the height of the lines is only determined by the relative counts, allowing us to see if cancelled flights have a different distribution:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cancelled &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sched_dep_time&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cancelled&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_density.html&#39;&gt;geom_density&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-11-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;It looks like flights at the end of the day are much more commonly cancelled than those early on, which is what we might have expected.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;chapter-75-covariation&#34;&gt;Chapter 7.5: Covariation&lt;/h2&gt;
&lt;p&gt;This section of the book covers the exploration of covariation among two variables. For example, is there a relationship between the cut and the price of a diamond (a categorical and continuous variable)? Or an association between the cut and color of a diamond (two categorical variables)? Or between the carat and the price of a diamond (two continuous variables)?&lt;/p&gt;
&lt;h3 id=&#34;751-a-categorical-and-continuous-variable&#34;&gt;7.5.1: A categorical and continuous variable&lt;/h3&gt;
&lt;p&gt;In out last plot above, we already explored the relationship between a categorical variable (cancelled &amp;amp; not-cancelled flights) and a continuous one (departure time), and we did so with so with a frequency polygon (&lt;code&gt;geom_freqpoly&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s see another example, this time for the &lt;code&gt;diamonds&lt;/code&gt; dataset, to examine whether prices differ among diamond cuts:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_density.html&#39;&gt;geom_density&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;A &lt;strong&gt;boxplot&lt;/strong&gt; is another classic way to show the relationship between a categorical and a continuous variable. &lt;a href=&#34;https://r4ds.had.co.nz/exploratory-data-analysis.html#cat-cont&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;The book&lt;/a&gt; has a good explanation of what the components of a boxplot (box, median line, whiskers, outliers) represent. Let&amp;rsquo;s make a boxplot of diamond &lt;code&gt;price&lt;/code&gt; by &lt;code&gt;cut&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# To make the plot better-looking, and to see the same colors as above,&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# we&#39;ll also map the fill aesthetic to cut:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/guides.html&#39;&gt;guides&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# Just to turn the legend for fill off&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;A less formal, but sometimes more informative variant of this type of plot is a &lt;strong&gt;violin plot&lt;/strong&gt;, where the width represents the number of data points:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_violin.html&#39;&gt;geom_violin&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/guides.html&#39;&gt;guides&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# Just to turn the legend for fill off&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h3 id=&#34;752-two-categorical-variables&#34;&gt;7.5.2: Two categorical variables&lt;/h3&gt;
&lt;p&gt;As the books says,&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;To visualise the covariation between categorical variables, you&amp;rsquo;ll need to count the number of observations for each combination.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;A quick way to do that is with &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_count.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_count()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;color&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_count.html&#39;&gt;geom_count&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-15-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;A &lt;strong&gt;heatmap&lt;/strong&gt; is a slightly more visually appealing way to plot this. We can create one using &lt;strong&gt;&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_tile.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_tile()&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; by first calculating the counts ourselves, and then mapping these counts to the &lt;code&gt;fill&lt;/code&gt; color of the tiles:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/count.html&#39;&gt;count&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;color&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;# This will create a column &#39;n&#39; with the counts&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;color&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_tile.html&#39;&gt;geom_tile&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-16-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h3 id=&#34;753-two-continuous-variables&#34;&gt;7.5.3: Two continuous variables&lt;/h3&gt;
&lt;p&gt;Visualizing the relationship between two continuous variables is perhaps the most intuitive of the variable type combinations. It can be done with simple scatterplots (&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_point.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_point()&lt;/code&gt;&lt;/a&gt;), of which we have already seen a couple of examples.&lt;/p&gt;
&lt;p&gt;The books covers a few strategies that can be useful when dealing with large datasets, when relationships may be hidden due to overplotting. Consider the relationship between the &lt;code&gt;carat&lt;/code&gt; (weight) and &lt;code&gt;price&lt;/code&gt; of diamonds:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-17-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;There is clearly some overplotting going on here, with areas of solid black &amp;ndash; though this type of thing can get a lot worse. Here, the overall pattern is still apparent.&lt;/p&gt;
&lt;p&gt;Making points transparent is one strategy to more clearly see patterns in the data in the face of overplotting:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# An alpha of 1 (the default) is opaque and an alpha of 1 is transparent &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.01&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-18-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Two other strategies covered in the book are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use a geom that does 2-dimensional binning for you (e.g. &lt;code&gt;geom_bin2d&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Bin &lt;em&gt;one&lt;/em&gt; of the continuous variables, effectively turning it into a categorical variable, so that we can use plot types like boxplots. You&amp;rsquo;ll try that in the exercises.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout Rooms&lt;/h2&gt;
&lt;p&gt;All the exercises use the &lt;code&gt;diamonds&lt;/code&gt; dataset. After loading the &lt;em&gt;tidyverse&lt;/em&gt;, this dataset should be available to you.&lt;/p&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;Use the function &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/cut_interval.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;cut_number()&lt;/code&gt;&lt;/a&gt; to divide the &lt;code&gt;carat&lt;/code&gt; values into 10 bins, and create a boxplot of diamond prices for each of these bins.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Tip: If you can&amp;rsquo;t read the x-axis labels (bin names) in the resulting plot&lt;/em&gt; &lt;em&gt;because they overlap, consider flipping the plot:&lt;/em&gt; &lt;em&gt;simply swap the &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; aesthetic assignments&lt;/em&gt; &lt;em&gt;(alternatively, use the stand-alone function &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/coord_flip.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;coord_flip()&lt;/code&gt;&lt;/a&gt;).&lt;/em&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Run &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/cut_interval.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;?cut_number&lt;/code&gt;&lt;/a&gt; to see the documentation for this function.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can start by creating a binned column with &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;cut_number(carat, n = 10)&lt;/code&gt;, &lt;em&gt;or&lt;/em&gt; you can create the bins &amp;ldquo;on the fly&amp;rdquo;, by simply using &lt;code&gt;cut_number(carat, n = 10)&lt;/code&gt; as the &lt;code&gt;x&lt;/code&gt; or &lt;code&gt;y&lt;/code&gt; aesthetic.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;To be able to read the axis labels, I moved &lt;code&gt;carat&lt;/code&gt; to the y axis (and I also added a y-axis label):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/cut_interval.html&#39;&gt;cut_number&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/labs.html&#39;&gt;labs&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;carat (binned)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-19-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The book has a different way of doing this, using the &lt;code&gt;group&lt;/code&gt; aesthetic. This is less intuitive but has the advantage of keeping the carat axis labels as if it still were a regular continuous variable. It also makes the width of the boxes represent the width of the bins, which you may or may not like:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/cut_interval.html&#39;&gt;cut_number&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-20-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Alternatively, if you want to have control over the ranges that the bins cover (but not over the number of points in each bin), you can use the &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/cut_interval.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;cut_width()&lt;/code&gt;&lt;/a&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/cut_interval.html&#39;&gt;cut_width&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/labs.html&#39;&gt;labs&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;carat (binned)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-21-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In that case, consider using &lt;code&gt;varwidth = TRUE&lt;/code&gt; to make the width of the boxes to reflect the number of data points:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/cut_interval.html&#39;&gt;cut_width&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;varwidth &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/labs.html&#39;&gt;labs&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;carat (binned)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-22-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Create a heatmap (&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_tile.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_tile()&lt;/code&gt;&lt;/a&gt;) that shows the &lt;em&gt;mean diamond price&lt;/em&gt; for each diamond color and cut combination (you&amp;rsquo;ll have to compute the mean price first).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;From your heatmap, would you say that going from color &lt;code&gt;D&lt;/code&gt; =&amp;gt; &lt;code&gt;J&lt;/code&gt; is associated with an &lt;em&gt;increase&lt;/em&gt; or a &lt;em&gt;decrease&lt;/em&gt; in the mean price?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Tip: add &lt;code&gt;+ scale_fill_viridis_c()&lt;/code&gt; to your code for a much nicer color scale.&lt;/em&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;In the heatmap, you&amp;rsquo;ll want &lt;code&gt;color&lt;/code&gt; along the &lt;code&gt;x&lt;/code&gt; axis and &lt;code&gt;cut&lt;/code&gt; along the &lt;code&gt;y&lt;/code&gt; axis (or vice versa), and you&amp;rsquo;ll want to &lt;code&gt;fill&lt;/code&gt; the tiles by the mean price.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You&amp;rsquo;ll first have to compute the mean diamond price for each of the &lt;code&gt;color&lt;/code&gt;-&lt;code&gt;cut&lt;/code&gt; combinations: use &lt;a href=&#34;https://dplyr.tidyverse.org/reference/group_by.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;group_by()&lt;/code&gt;&lt;/a&gt; and then &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution just for getting the mean price&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;color&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;price &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` has grouped output by &#39;color&#39;. You can override using the&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `.groups` argument.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 35 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# Groups:   color [7]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    color cut       price&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; D     Fair      &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;291.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; D     Good      &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;405.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; D     Very Good &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;470.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; D     Premium   &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;631.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; D     Ideal     &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;629.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; E     Fair      &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;682.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; E     Good      &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;424.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; E     Very Good &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;215.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; E     Premium   &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;539.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; E     Ideal     &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;598.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 25 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Full solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;color&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;price &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;color&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_tile.html&#39;&gt;geom_tile&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/scale_viridis.html&#39;&gt;scale_fill_viridis_c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` has grouped output by &#39;color&#39;. You can override using the&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `.groups` argument.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-24-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;It looks like going from color &lt;code&gt;D&lt;/code&gt; to &lt;code&gt;J&lt;/code&gt; is associated with an overall &lt;em&gt;increase&lt;/em&gt; in the mean price of diamonds.&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Make a plot to visualize the relationship between &lt;code&gt;color&lt;/code&gt; and &lt;code&gt;carat&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Seeing this relationship, and knowing that &lt;code&gt;carat&lt;/code&gt; and &lt;code&gt;price&lt;/code&gt; are strongly related (see the scatterplots above), do you think this might have influenced (confounded) the apparent relationship between &lt;code&gt;color&lt;/code&gt; and &lt;code&gt;price&lt;/code&gt;?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;How could you quickly create a price index that controls for &lt;code&gt;carat&lt;/code&gt;? Make a heatmap with that price index instead of the raw price.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use a boxplot, violin plot and/or a density plot to visualize the relationship between &lt;code&gt;color&lt;/code&gt; and &lt;code&gt;carat&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If higher carats are causally associated with higher prices, and certain colors have higher mean carats than others, it is not fair to look at the effect of color on price without somehow taking carat into account.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A simple way of taking carat into account is by using &amp;ldquo;price per carat&amp;rdquo; (price divided by carat) rather than the raw price in your heatmap.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;To visualize the relationship between &lt;code&gt;color&lt;/code&gt; and &lt;code&gt;carat&lt;/code&gt;, you could for example use a boxplot and/or a density plot:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;color&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-25-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;color&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_density.html&#39;&gt;geom_density&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-26-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;It looks like going from &lt;code&gt;D&lt;/code&gt; =&amp;gt; &lt;code&gt;J&lt;/code&gt;, &lt;code&gt;carat&lt;/code&gt; is typically higher.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Since &lt;code&gt;carat&lt;/code&gt; is strongly positively associated with &lt;code&gt;price&lt;/code&gt;, it is not fair to compare prices among colors without controlling for &lt;code&gt;carat&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A simple way to do so is dividing &lt;code&gt;price&lt;/code&gt; by &lt;code&gt;carat&lt;/code&gt; to create an index that represents the &amp;ldquo;price per carat&amp;rdquo;. Then, you can use that index instead of the raw price in your heatmap:&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;color&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;price_per_carat &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;price_per_carat &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;price_per_carat&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;color&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price_per_carat&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_tile.html&#39;&gt;geom_tile&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/scale_viridis.html&#39;&gt;scale_fill_viridis_c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` has grouped output by &#39;color&#39;. You can override using the&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `.groups` argument.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-27-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Now, it looks like going from &lt;code&gt;D&lt;/code&gt; =&amp;gt; &lt;code&gt;J&lt;/code&gt; is associated with a &lt;strong&gt;decrease&lt;/strong&gt; rather than an increase in the mean price!&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-4-bonus&#34;&gt;Exercise 4 (bonus)&lt;/h3&gt;
&lt;p&gt;To get another perspecective on the relationship between &lt;code&gt;color&lt;/code&gt;, &lt;code&gt;carat&lt;/code&gt;, and &lt;code&gt;price&lt;/code&gt; (see the previous exercise), modify the earlier scatterplot of &lt;code&gt;carat&lt;/code&gt; and &lt;code&gt;price&lt;/code&gt; simply by mapping diamond &lt;code&gt;color&lt;/code&gt; to the color aesthetic.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;A scatterplot of &lt;code&gt;carat&lt;/code&gt; and &lt;code&gt;price&lt;/code&gt; that includes diamond color confirms that &lt;code&gt;D&lt;/code&gt; diamonds are more expensive than &lt;code&gt;J&lt;/code&gt; diamonds (and so on) once you take &lt;code&gt;carat&lt;/code&gt; into account:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;color&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-28-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;bonus-reordering-factor-levels&#34;&gt;Bonus: (re)ordering factor levels&lt;/h2&gt;
&lt;p&gt;In the plots with diamond &lt;code&gt;cut&lt;/code&gt;, you might have noticed that the cuts are ordered in a custom, sensible way rather than alphabetically. This is possible because the &lt;code&gt;cut&lt;/code&gt; column has the data type &lt;code&gt;factor&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If we convert &lt;code&gt;cut&lt;/code&gt; to a regular character data type, the custom order disappears (it is now ordered alphabetically):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cut &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/character.html&#39;&gt;as.character&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-29-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;We could set a different custom order using the &lt;code&gt;levels&lt;/code&gt; argument of the &lt;code&gt;factor&lt;/code&gt; function (the same code would work if &lt;code&gt;cut&lt;/code&gt; would not yet have been a factor at all):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;cut_order&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Very Good&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Fair&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Good&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Ideal&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Premium&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cut &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/factor.html&#39;&gt;factor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;, levels &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut_order&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-30-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Or, you could make the order of the factor levels depend on the data (!):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cut &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/reorder.factor.html&#39;&gt;reorder&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;, FUN &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;median&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-31-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
</description>
    </item>
    
    <item>
      <title>S04E15: R for Data Science - Exploratory Data Analysis</title>
      <link>https://biodash.github.io/codeclub/s04e15/</link>
      <pubDate>Tue, 15 Nov 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s04e15/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;setting-up&#34;&gt;Setting up&lt;/h2&gt;
&lt;p&gt;To start with, we&amp;rsquo;ll only need to load the &lt;em&gt;tidyverse&lt;/em&gt;, as we&amp;rsquo;ll explore a dataset that is automatically loaded along with it.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;## You only need to install if you haven&#39;t previously done so&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;tidyverse&#34;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching packages&lt;/span&gt; ─────────────────────────────────────── tidyverse 1.3.2 ──&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2&lt;/span&gt; 3.3.6      &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;purrr  &lt;/span&gt; 0.3.5 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tibble &lt;/span&gt; 3.1.8      &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr  &lt;/span&gt; 1.0.10&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr  &lt;/span&gt; 1.2.1      &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;stringr&lt;/span&gt; 1.4.1 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;readr  &lt;/span&gt; 2.1.3      &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;forcats&lt;/span&gt; 0.5.2 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt; masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::filter()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;    masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::lag()&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We&amp;rsquo;ll be working with the &lt;code&gt;diamonds&lt;/code&gt; dataset today, so let&amp;rsquo;s take a quick look at it before we begin:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 53,940 × 10&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    carat cut       color clarity depth table price     x     y     z&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  0.23 Ideal     E     SI2      61.5    55   326  3.95  3.98  2.43&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  0.21 Premium   E     SI1      59.8    61   326  3.89  3.84  2.31&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  0.23 Good      E     VS1      56.9    65   327  4.05  4.07  2.31&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  0.29 Premium   I     VS2      62.4    58   334  4.2   4.23  2.63&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  0.31 Good      J     SI2      63.3    58   335  4.34  4.35  2.75&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  0.24 Very Good J     VVS2     62.8    57   336  3.94  3.96  2.48&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  0.24 Very Good I     VVS1     62.3    57   336  3.95  3.98  2.47&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  0.26 Very Good H     SI1      61.9    55   337  4.07  4.11  2.53&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  0.22 Fair      E     VS2      65.1    61   337  3.87  3.78  2.49&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  0.23 Very Good H     VS1      59.4    61   338  4     4.05  2.39&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 53,930 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;On each row, we have information about one individual diamond, such as its &lt;code&gt;carat&lt;/code&gt; and &lt;code&gt;price&lt;/code&gt;. (&lt;code&gt;x&lt;/code&gt;, &lt;code&gt;y&lt;/code&gt;, and &lt;code&gt;z&lt;/code&gt; represent the diamond&amp;rsquo;s length, width, and depth, respectively.)&lt;/p&gt;
&lt;p&gt;Since we&amp;rsquo;ll be making a bunch of plots with &lt;em&gt;ggplot2&lt;/em&gt;, let&amp;rsquo;s use the following trick to set an overarching &amp;ldquo;theme&amp;rdquo; for all plots that is a little better-looking than the default one:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# This changes two things:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# - theme_minimal() gives an overall different look, with a white background&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# - base_size = 14 will make the text relatively bigger&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/theme_get.html&#39;&gt;theme_set&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggtheme.html&#39;&gt;theme_minimal&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;base_size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;chapter-73-variation&#34;&gt;Chapter 7.3: Variation&lt;/h2&gt;
&lt;h3 id=&#34;exploring-variation-in-a-categorical-variable&#34;&gt;Exploring variation in a categorical variable&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s say we want to see how many diamonds there are for each value of &lt;code&gt;cut&lt;/code&gt;. When we printed the first lines of the dataframe above, we could see that &lt;code&gt;cut&lt;/code&gt; has values like &lt;code&gt;Ideal&lt;/code&gt;, &lt;code&gt;Premium&lt;/code&gt;, and &lt;code&gt;Good&lt;/code&gt;: this is therefore a &amp;ldquo;categorical&amp;rdquo; and not a &amp;ldquo;continuous&amp;rdquo; variable.&lt;/p&gt;
&lt;p&gt;We could also see that the data type indication for &lt;code&gt;cut&lt;/code&gt; was &lt;code&gt;&amp;lt;ord&amp;gt;&lt;/code&gt;, which is short for &lt;em&gt;ordered factor&lt;/em&gt;. In R, categorical variables can be represented not just as character strings or integers, but also as &lt;strong&gt;factors&lt;/strong&gt;. Factors have a defined set of &lt;em&gt;levels&lt;/em&gt; which can be assigned a custom order. That is handy when plotting or when you need to set a reference level in a statistical model. (For more, see &lt;a href=&#34;https://biodash.github.io/codeclub/06_factors/&#34;&gt;the page for this previous Code Club session on factors&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;To quickly see which values the variable &lt;code&gt;cut&lt;/code&gt; contains, and what their frequencies are, we can use &lt;a href=&#34;https://dplyr.tidyverse.org/reference/count.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;count()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/count.html&#39;&gt;count&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 5 × 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   cut           n&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Fair       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;610&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Good       &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;906&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Very Good &lt;span style=&#39;text-decoration: underline;&#39;&gt;12&lt;/span&gt;082&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Premium   &lt;span style=&#39;text-decoration: underline;&#39;&gt;13&lt;/span&gt;791&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Ideal     &lt;span style=&#39;text-decoration: underline;&#39;&gt;21&lt;/span&gt;551&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To get a feel for the distribution of a categorical variable, making a barplot can also be useful. Recall that when making a plot with &lt;em&gt;ggplot2&lt;/em&gt;, we at least need the following components:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/ggplot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplot()&lt;/code&gt;&lt;/a&gt; function, in which we supply the dataframe that we want to use.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A &lt;em&gt;geom&lt;/em&gt; function, which is basically the type of plot we want to make, such as &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_point.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_point()&lt;/code&gt;&lt;/a&gt; for a scatterplot and &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_bar.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_bar()&lt;/code&gt;&lt;/a&gt; for a barplot.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;An &amp;ldquo;aesthetic mapping&amp;rdquo; that defines which variables to plot along the axes.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For a barplot showing &lt;code&gt;cut&lt;/code&gt;, our &lt;em&gt;ggplot2&lt;/em&gt; code would look as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_bar.html&#39;&gt;geom_bar&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-5-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;When making plots, we typically specify which variable should go along the y-axis, too. But that is not the case for barplots, where the default is to automatically plot a &lt;em&gt;count which is &lt;strong&gt;computed&lt;/strong&gt; from the data&lt;/em&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;h3 id=&#34;exploring-variation-in-a-continuous-variable&#34;&gt;Exploring variation in a continuous variable&lt;/h3&gt;
&lt;p&gt;We&amp;rsquo;ll take another look at the &lt;code&gt;diamonds&lt;/code&gt; dataframe and pick a &lt;em&gt;continuous&lt;/em&gt; variable:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 53,940 × 10&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    carat cut       color clarity depth table price     x     y     z&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  0.23 Ideal     E     SI2      61.5    55   326  3.95  3.98  2.43&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  0.21 Premium   E     SI1      59.8    61   326  3.89  3.84  2.31&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  0.23 Good      E     VS1      56.9    65   327  4.05  4.07  2.31&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  0.29 Premium   I     VS2      62.4    58   334  4.2   4.23  2.63&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  0.31 Good      J     SI2      63.3    58   335  4.34  4.35  2.75&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  0.24 Very Good J     VVS2     62.8    57   336  3.94  3.96  2.48&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  0.24 Very Good I     VVS1     62.3    57   336  3.95  3.98  2.47&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  0.26 Very Good H     SI1      61.9    55   337  4.07  4.11  2.53&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  0.22 Fair      E     VS2      65.1    61   337  3.87  3.78  2.49&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  0.23 Very Good H     VS1      59.4    61   338  4     4.05  2.39&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 53,930 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s explore the variation in the continuous variable &lt;code&gt;carat&lt;/code&gt;, and do so by making a histogram using &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_histogram()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-7-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Under the hood, a histogram discretizes the continuous data into bins, and then shows the counts (here: number of diamonds) in each bin. We may want to play around with the width of the bins to see more fine-grained or coarse-grained patterns, and can do so using the &lt;code&gt;binwidth&lt;/code&gt; argument:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, binwidth &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-8-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;If we wanted to see this kind of representation in table-form, using &lt;a href=&#34;https://dplyr.tidyverse.org/reference/count.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;count()&lt;/code&gt;&lt;/a&gt; directly wouldn&amp;rsquo;t work: we don&amp;rsquo;t have a column with bins for &lt;code&gt;carat&lt;/code&gt;, only the raw, numeric values.&lt;/p&gt;
&lt;p&gt;To create bins, we can use the &lt;em&gt;ggplot2&lt;/em&gt; function &lt;code&gt;cut_width&lt;/code&gt;, whose &lt;code&gt;width&lt;/code&gt; argument is equivalent to &lt;code&gt;geom_histogram&lt;/code&gt;&amp;rsquo;s &lt;code&gt;binwidth&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;carat_discrete &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/cut_interval.html&#39;&gt;cut_width&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/count.html&#39;&gt;count&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carat_discrete&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 11 × 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    carat_discrete     n&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; [-0.25,0.25]     785&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; (0.25,0.75]    &lt;span style=&#39;text-decoration: underline;&#39;&gt;29&lt;/span&gt;498&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; (0.75,1.25]    &lt;span style=&#39;text-decoration: underline;&#39;&gt;15&lt;/span&gt;977&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; (1.25,1.75]     &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;313&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; (1.75,2.25]     &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;002&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; (2.25,2.75]      322&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; (2.75,3.25]       32&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; (3.25,3.75]        5&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; (3.75,4.25]        4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; (4.25,4.75]        1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;11&lt;/span&gt; (4.75,5.25]        1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;multiple-variables&#34;&gt;Multiple variables&lt;/h3&gt;
&lt;p&gt;If we want to show the variation in &lt;code&gt;carat&lt;/code&gt; &lt;em&gt;separately for each level of &lt;code&gt;cut&lt;/code&gt;&lt;/em&gt;, we can map &lt;code&gt;carate&lt;/code&gt; &lt;em&gt;also&lt;/em&gt; to &lt;code&gt;fill&lt;/code&gt;, which is the fill color of the bars:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# First, let&#39;s subset the data to only keep relatively small diamonds: &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;smaller&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Then, we make the plot:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;smaller&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;binwidth &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.1&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;grey20&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-10-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Above, note that:&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# - The mapping is now inside &#39;ggplot()&#39;, and we used &#39;cut&#39; twice&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# - In geom_histogram(), color is _not_ a mapping and is for the color of the border&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Though in a case like this, a linegraph with &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_freqpoly()&lt;/code&gt;&lt;/a&gt; might be easier to interpret:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;smaller&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, colour &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cut&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_freqpoly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;binwidth &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.1&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# (Making thicker lines with &#39;size&#39;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-11-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h3 id=&#34;unusual-values-outliers&#34;&gt;Unusual values (outliers)&lt;/h3&gt;
&lt;p&gt;Sometimes, plots like histograms have very wide axis limits yet no visible bars on the sides:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, binwidth &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The x-axis limits are automatically picked based on the data, so there really &lt;em&gt;should&lt;/em&gt; be some values all the way up to about 60. We just can&amp;rsquo;t see them, since the y-axis scale goes all the way up to 12,000.&lt;/p&gt;
&lt;p&gt;If we want to see these counts in the graph, we can &lt;em&gt;zoom in&lt;/em&gt; on the y-axis with &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/coord_cartesian.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;coord_cartesian()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, binwidth &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/coord_cartesian.html&#39;&gt;coord_cartesian&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;ylim &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# c(&amp;lt;lower-limit&amp;gt;, &amp;lt;upper-limit&amp;gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Note that in &lt;em&gt;ggplot2&lt;/em&gt;, zooming in on a graph and setting axis limits isn&amp;rsquo;t the same thing: you&amp;rsquo;ll learn more about that in the exercises.&lt;/p&gt;
&lt;p&gt;Of course we could also try to find these values in the dataframe itself, which might be more useful than a graph in cases like this. To do so, we can use the &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; function we learned about in the previous chapter:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 9 × 10&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   carat cut       color clarity depth table price     x     y     z&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;ord&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;  1    Very Good H     VS2      63.3    53  &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;139  0      0    0   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;  1.14 Fair      G     VS1      57.5    67  &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;381  0      0    0   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;  2    Premium   H     SI2      58.9    57 &lt;span style=&#39;text-decoration: underline;&#39;&gt;12&lt;/span&gt;210  8.09  58.9  8.06&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;  1.56 Ideal     G     VS2      62.2    54 &lt;span style=&#39;text-decoration: underline;&#39;&gt;12&lt;/span&gt;800  0      0    0   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;  1.2  Premium   D     VVS1     62.1    59 &lt;span style=&#39;text-decoration: underline;&#39;&gt;15&lt;/span&gt;686  0      0    0   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;  2.25 Premium   H     SI2      62.8    59 &lt;span style=&#39;text-decoration: underline;&#39;&gt;18&lt;/span&gt;034  0      0    0   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;7&lt;/span&gt;  0.51 Ideal     E     VS1      61.8    55  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;075  5.15  31.8  5.12&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;8&lt;/span&gt;  0.71 Good      F     SI2      64.1    60  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;130  0      0    0   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;9&lt;/span&gt;  0.71 Good      F     SI2      64.1    60  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;130  0      0    0&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout Rooms&lt;/h2&gt;
&lt;p&gt;These exercises will continue to use the &lt;code&gt;diamonds&lt;/code&gt; data, which is automatically loaded when you load the &lt;em&gt;tidyverse&lt;/em&gt;.&lt;/p&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;In the &lt;code&gt;diamonds&lt;/code&gt; data, explore the distribution of &lt;code&gt;price&lt;/code&gt;, which is the price of a diamond in USD. Do you discover anything unusual or surprising?&lt;/p&gt;
&lt;p&gt;Make sure to try different values for the &lt;code&gt;binwidth&lt;/code&gt; argument!&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;This is a continuous variable, so use &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_histogram()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A more fine-grained plot (smaller bins with &lt;code&gt;binwidth&lt;/code&gt;) than the default should reveal something odd.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You might want to use &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/coord_cartesian.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;coord_cartesian()&lt;/code&gt;&lt;/a&gt; to see the area with the odd pattern in more detail. (Alternatively, you could try &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt;ing the data before plotting.)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_histogram()&lt;/code&gt;&lt;/a&gt; with default settings doesn&amp;rsquo;t reveal anything too weird:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-15-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;But with a binwidth of e.g. 100, we start to see something odd: a gap in the distribution.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;binwidth &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-16-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Let&amp;rsquo;s take a closer look by zooming in on prices of $2,500 or less:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;binwidth &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;25&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/coord_cartesian.html&#39;&gt;coord_cartesian&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;xlim &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2500&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-17-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;(An alternative approach would be to filter the data before plotting:)&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2500&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;binwidth &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;25&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I have no idea why there are no diamonds with a price of around $1,500 &amp;ndash; anybody?&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;p&gt;Compare &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/coord_cartesian.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;coord_cartesian()&lt;/code&gt;&lt;/a&gt; with the similar function &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/lims.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lims()&lt;/code&gt;&lt;/a&gt; to see a narrower range along the y-axis for a histogram. Specifically, make two histograms of &lt;code&gt;price&lt;/code&gt; with a y-axis that only goes up to 3,000: one with &lt;code&gt;coord_cartesian(ylim = ...)&lt;/code&gt; and one with &lt;code&gt;lims(y = ...)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;What is happening in the graph made with &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/lims.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lims()&lt;/code&gt;&lt;/a&gt;?&lt;/p&gt;
&lt;p&gt;(See the hint for example usage of &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/lims.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lims()&lt;/code&gt;&lt;/a&gt;, a function we haven&amp;rsquo;t seen yet.)&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;You can use &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/lims.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lims()&lt;/code&gt;&lt;/a&gt; to set arbitrary axis limits:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/lims.html&#39;&gt;lims&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,   &lt;span class=&#39;c&#39;&gt;# c(&amp;lt;lower-limit&amp;gt;, &amp;lt;upper-limit&amp;gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# c(&amp;lt;lower-limit&amp;gt;, &amp;lt;upper-limit&amp;gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 17593 rows containing missing values (geom_point).&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-19-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;You could also use the very similar &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/lims.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ylim()&lt;/code&gt;&lt;/a&gt; / &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/lims.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;xlim()&lt;/code&gt;&lt;/a&gt; pair of functions, though note the slightly simplified syntax:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/lims.html&#39;&gt;xlim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Note: you don&#39;t pass a vector inside &#39;c()&#39; here&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/lims.html&#39;&gt;ylim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 17593 rows containing missing values (geom_point).&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-20-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Whereas the graph produced with &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/coord_cartesian.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;coord_cartesian()&lt;/code&gt;&lt;/a&gt; is simply &amp;ldquo;cut off&amp;rdquo; at the specified limit, the graph produced with &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/lims.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lims()&lt;/code&gt;&lt;/a&gt; is missing bars!&lt;/p&gt;
&lt;p&gt;It turns out that &lt;em&gt;ggplot2&lt;/em&gt; removes the bars that can&amp;rsquo;t be shown given our y-limit. Notice that it warns us about doing so: &lt;code&gt;#&amp;gt; Warning: Removed 5 rows containing missing values (geom_bar).&lt;/code&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/coord_cartesian.html&#39;&gt;coord_cartesian&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;ylim &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-21-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/lims.html&#39;&gt;lims&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 5 rows containing missing values (geom_bar).&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-22-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;p&gt;Using scatterplots, explore the relationship between the width &lt;code&gt;y&lt;/code&gt; and the depth &lt;code&gt;z&lt;/code&gt; of the diamonds.&lt;/p&gt;
&lt;p&gt;What do you think about the outliers? Are they more likely to be unusual diamonds or data entry errors?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Make a scatterplot with &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_point.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_point()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Zoom in on the area with most points, to get a better feel for the overall relationship between &lt;code&gt;y&lt;/code&gt; and &lt;code&gt;z&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Could a diamond with a value of &lt;code&gt;y&lt;/code&gt; larger than 20 just be a very large diamond? Or does the corresponding value for &lt;code&gt;z&lt;/code&gt;, and the overall relationship between &lt;code&gt;y&lt;/code&gt; and &lt;code&gt;z&lt;/code&gt; make it more likely that they are outliers?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Let&amp;rsquo;s start with a simple scatterplot with all data and default axis limits:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;z&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-23-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Phew! There are definitely some striking outliers. Let&amp;rsquo;s zoom in on the main cloud of points:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;z&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_point.html&#39;&gt;geom_point&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/coord_cartesian.html&#39;&gt;coord_cartesian&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;xlim &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, ylim &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;15&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-24-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;That looks like an overall very tight correlation between width (&lt;code&gt;y&lt;/code&gt;) and depth (&lt;code&gt;z&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Therefore, the outliers of &lt;code&gt;y&lt;/code&gt; and &lt;code&gt;z&lt;/code&gt; don&amp;rsquo;t just seem to represent very large or very small diamonds, and are likely data entry errors or something along those lines.&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-4-bonus&#34;&gt;Exercise 4 (bonus)&lt;/h3&gt;
&lt;p&gt;Explore the distribution of &lt;code&gt;carat&lt;/code&gt;. Specifically, compare the number of diamonds of 0.99 (and a little less) carat and those of 1 (and a little more) carat? What do you think is the cause of the difference?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Make a histogram (&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_histogram()&lt;/code&gt;&lt;/a&gt;) for &lt;code&gt;carat&lt;/code&gt;, and optionally zoom in to the area around 1.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://dplyr.tidyverse.org/reference/count.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;count()&lt;/code&gt;&lt;/a&gt; to specifically check out the diamond counts with a carat of around 1.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;We can start by simply making a histogram for &lt;code&gt;carat&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;binwidth &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.01&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-25-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;That&amp;rsquo;s a weird pattern, with a bunch of peaks and valleys! Let&amp;rsquo;s just show the area around a carat of &lt;code&gt;1&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.9&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1.1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;binwidth &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.01&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-26-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;There&amp;rsquo;s clearly a big uptick around &lt;code&gt;1&lt;/code&gt;, but checking out the raw counts would make it easier to answer the original question:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.9&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1.1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/count.html&#39;&gt;count&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 19 × 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    carat     n&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  0.91   570&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  0.92   226&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  0.93   142&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  0.94    59&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  0.95    65&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  0.96   103&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  0.97    59&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  0.98    31&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  0.99    23&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;558&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;11&lt;/span&gt;  1.01  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;242&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;12&lt;/span&gt;  1.02   883&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;13&lt;/span&gt;  1.03   523&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;14&lt;/span&gt;  1.04   475&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;15&lt;/span&gt;  1.05   361&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;16&lt;/span&gt;  1.06   373&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;17&lt;/span&gt;  1.07   342&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;18&lt;/span&gt;  1.08   246&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;19&lt;/span&gt;  1.09   287&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;There are suspiciously few diamonds with a carat of 0.99 (and, to a lesser extent, with a carat anywhere above 0.9): could there be some rounding-up going on?&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
</description>
    </item>
    
    <item>
      <title>S04E14: R for Data Science - Chapter 5.6: summarize, some more</title>
      <link>https://biodash.github.io/codeclub/s04e14_r4ds-ch5-5-again/</link>
      <pubDate>Thu, 10 Nov 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s04e14_r4ds-ch5-5-again/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;get-data-and-package&#34;&gt;Get data and package&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# only if you haven&#39;t done so before, install the packages&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;nycflights13&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Load libraries&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for everything&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for penguins data&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/hadley/nycflights13&#39;&gt;nycflights13&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for flights data&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;preview-the-dataset&#34;&gt;Preview the Dataset&lt;/h3&gt;
&lt;p&gt;We are going to start with the penguins.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://pillar.r-lib.org/reference/glimpse.html&#39;&gt;glimpse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 344&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 8&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ island            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Torgersen, Torgersen, Torgersen, Torgersen, Torgerse…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_length_mm    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_depth_mm     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ flipper_length_mm &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ body_mass_g       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sex               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; male, female, female, NA, female, male, female, male…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;review-of-summarize&#34;&gt;Review of &lt;code&gt;summarize()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Different from &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; (which picks columns but retains all rows) and &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; (which picks observations but retains all columns), &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt; creates a wholly new dataframe by making calculations or pulling parts of your original dataframe.&lt;/p&gt;
&lt;p&gt;For example, if we want to know the mean &lt;code&gt;body_mass_g&lt;/code&gt; across all penguins in the dataset, we can calculate that like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_body_mass &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# calculate mean body mass&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;                                  na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# remove the NAs&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   mean_body_mass&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;          &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;202.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;But we may actually be interested in the different mean &lt;code&gt;body_mass_g&lt;/code&gt; calculated separately for the different &lt;code&gt;species&lt;/code&gt; of penguins. We can do that by adding the function &lt;a href=&#34;https://dplyr.tidyverse.org/reference/group_by.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;group_by()&lt;/code&gt;&lt;/a&gt; like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# group by species&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_body_mass &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# calculate mean body mass by species&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;                                  na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# remove the NAs&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   mean_body_mass&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie             &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;701.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap          &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;733.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo             &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;076.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And, you can also add more than one &lt;a href=&#34;https://dplyr.tidyverse.org/reference/group_by.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;group_by()&lt;/code&gt;&lt;/a&gt; factor, for example, by the full combination &lt;code&gt;species&lt;/code&gt; and &lt;code&gt;sex&lt;/code&gt; variables.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# group by species and sex combos&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_body_mass &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# calculate mean body mass by species&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;                                  na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# remove the NAs&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 8 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# Groups:   species [3]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   sex    mean_body_mass&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie    female          &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;369.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Adelie    male            &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;043.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Adelie    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;              &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;540 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Chinstrap female          &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;527.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Chinstrap male            &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;939.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Gentoo    female          &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;680.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;7&lt;/span&gt; Gentoo    male            &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;485.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;8&lt;/span&gt; Gentoo    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;              &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;588.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;using-more-functions-in-summarize&#34;&gt;Using more functions in &lt;code&gt;summarize()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Last week we went over using a few different functions within &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/mean.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mean()&lt;/code&gt;&lt;/a&gt;: calculates the mean (set &lt;code&gt;na.rm = TRUE&lt;/code&gt; if you was the NAs to be removed before calculating)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/context.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;n()&lt;/code&gt;&lt;/a&gt;: counts the number of observations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;But, there are lots more functions you might be interested to add into &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt;, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/stats/median.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;median()&lt;/code&gt;&lt;/a&gt;: when you want to calculate the median instead of the mean&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/stats/sd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sd()&lt;/code&gt;&lt;/a&gt;: calculates the standard deviation&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/stats/IQR.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;IQR()&lt;/code&gt;&lt;/a&gt;: calculates the interquartile range&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/sum.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sum()&lt;/code&gt;&lt;/a&gt;: calculates the sum&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/Extremes.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;min()&lt;/code&gt;&lt;/a&gt;: calculates the minimum&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/Extremes.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;max()&lt;/code&gt;&lt;/a&gt;: calculates the maximum&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/n_distinct.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;n_distinct()&lt;/code&gt;&lt;/a&gt;: calculates the number of distinct or unique occurences&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can always combine functions or write your own functions to use within &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt; as well. For example, let&amp;rsquo;s say you wanted the standard error of the mean, but there isn&amp;rsquo;t a function built into tidyverse or base R that does that. You can still get your standard error but using a combination of other functions!&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# dropping observations with missing values&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_body_mass &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# mean body mass&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;            n_observations &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# how many observations are there&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;            std_error_body_mass &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/sd.html&#39;&gt;sd&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;/&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/MathFun.html&#39;&gt;sqrt&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# sd/sqrt(n)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   mean_body_mass n_observations std_error_body_mass&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie             &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;701.            151                37.3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap          &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;733.             68                46.6&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo             &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;076.            123                45.5&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-exercises-1&#34;&gt;Breakout Exercises 1&lt;/h2&gt;
&lt;p&gt;Back to the &lt;code&gt;flights&lt;/code&gt; tibble for each of the following exercises.&lt;/p&gt;
&lt;h3 id=&#34;exercise-11&#34;&gt;Exercise 1.1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Determine the mean, standard deviation, min, and max departure delay for each airport of origin. Also determine how many observations you have for each airport of origin.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Group the tibble by &lt;code&gt;origin&lt;/code&gt;. Summarize for each summary you want to calculate. Make sure you exclude missing data.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;origin&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_dep_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;            sd_dep_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/sd.html&#39;&gt;sd&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;            min_dep_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;            max_dep_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;            n_dep_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 6&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   origin mean_dep_delay sd_dep_delay min_dep_delay max_dep_delay n_dep_delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; EWR              15.1         41.3           -&lt;span style=&#39;color: #BB0000;&#39;&gt;25&lt;/span&gt;          &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;126      &lt;span style=&#39;text-decoration: underline;&#39;&gt;117&lt;/span&gt;596&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; JFK              12.1         39.0           -&lt;span style=&#39;color: #BB0000;&#39;&gt;43&lt;/span&gt;          &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;301      &lt;span style=&#39;text-decoration: underline;&#39;&gt;109&lt;/span&gt;416&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; LGA              10.3         40.0           -&lt;span style=&#39;color: #BB0000;&#39;&gt;33&lt;/span&gt;           911      &lt;span style=&#39;text-decoration: underline;&#39;&gt;101&lt;/span&gt;509&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-12&#34;&gt;Exercise 1.2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;How many distinct destinations are there to fly from for each EWR, JFK, and LGA?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Think about what you want to &lt;a href=&#34;https://dplyr.tidyverse.org/reference/group_by.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;group_by()&lt;/code&gt;&lt;/a&gt; and what of the new functions we talked about today you could use in &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;origin&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;n_distinct_dest &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/n_distinct.html&#39;&gt;n_distinct&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   origin n_distinct_dest&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; EWR                 86&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; JFK                 70&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; LGA                 68&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;using-slice_&#34;&gt;Using &lt;code&gt;slice_()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Using &lt;a href=&#34;https://dplyr.tidyverse.org/reference/slice.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;slice_()&lt;/code&gt;&lt;/a&gt; you can subset rows based on their position.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# dropping observations with missing values&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_body_mass &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/slice.html&#39;&gt;slice_min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mean_body_mass&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# min based on mean_body_mass, just give me 1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species mean_body_mass&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie           &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;701.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/slice.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;slice()&lt;/code&gt;&lt;/a&gt; allows you to pick rows by the position (i.e., indexing, e.g., &lt;code&gt;slice(4)&lt;/code&gt; will give you the 4th row of that df)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/slice.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;slice_head()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://dplyr.tidyverse.org/reference/slice.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;slice_tail()&lt;/code&gt;&lt;/a&gt; select the first or last rows.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/slice.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;slice_sample()&lt;/code&gt;&lt;/a&gt; randomly selects rows.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/slice.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;slice_min()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://dplyr.tidyverse.org/reference/slice.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;slice_max()&lt;/code&gt;&lt;/a&gt; select rows with highest or lowest values of a variable.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can use &lt;a href=&#34;https://dplyr.tidyverse.org/reference/se-deprecated.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;slice_()&lt;/code&gt;&lt;/a&gt; functions on dataframes themselves (not just on summarized data).&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# dropping observations with missing values&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/slice.html&#39;&gt;slice_max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# the 10 heaviest penguins&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 11 × 8&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species island bill_length_mm bill_depth_mm flipper_len…¹ body_…² sex    year&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Gentoo  Biscoe           49.2          15.2           221    &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;300 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Gentoo  Biscoe           59.6          17             230    &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;050 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Gentoo  Biscoe           51.1          16.3           220    &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;000 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Gentoo  Biscoe           48.8          16.2           222    &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;000 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;009&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Gentoo  Biscoe           45.2          16.4           223    &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;950 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Gentoo  Biscoe           49.8          15.9           229    &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;950 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;009&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Gentoo  Biscoe           48.4          14.6           213    &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;850 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Gentoo  Biscoe           49.3          15.7           217    &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;850 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Gentoo  Biscoe           55.1          16             230    &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;850 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;009&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Gentoo  Biscoe           49.5          16.2           229    &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;800 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;11&lt;/span&gt; Gentoo  Biscoe           48.6          16             230    &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;800 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with abbreviated variable names ¹​flipper_length_mm, ²​body_mass_g&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note, we actually got 11, that is because in 10th place there is a tie. Ties are kept by default, but can be turned off by setting &lt;code&gt;with_ties = FALSE&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can also set the proportion of results to return using &lt;code&gt;prop =&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# dropping observations with missing values&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/slice.html&#39;&gt;slice_max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, prop &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# the top 10% heaviest penguins&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 34 × 8&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species island bill_length_mm bill_depth_mm flipper_len…¹ body_…² sex    year&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Gentoo  Biscoe           49.2          15.2           221    &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;300 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Gentoo  Biscoe           59.6          17             230    &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;050 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Gentoo  Biscoe           51.1          16.3           220    &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;000 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Gentoo  Biscoe           48.8          16.2           222    &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;000 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;009&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Gentoo  Biscoe           45.2          16.4           223    &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;950 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Gentoo  Biscoe           49.8          15.9           229    &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;950 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;009&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Gentoo  Biscoe           48.4          14.6           213    &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;850 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Gentoo  Biscoe           49.3          15.7           217    &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;850 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Gentoo  Biscoe           55.1          16             230    &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;850 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;009&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Gentoo  Biscoe           49.5          16.2           229    &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;800 male   &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 24 more rows, and abbreviated variable names ¹​flipper_length_mm,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ²​body_mass_g&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If data are grouped, the operation will be performed group wise, like we see below.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# dropping observations with missing values&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/slice.html&#39;&gt;slice_min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 4 × 8&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# Groups:   species [3]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   island bill_length_mm bill_depth_mm flipper_le…¹ body_…² sex    year&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie    Biscoe           36.5          16.6          181    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;850 fema…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Adelie    Biscoe           36.4          17.1          184    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;850 fema…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Chinstrap Dream            46.9          16.6          192    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;700 fema…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Gentoo    Biscoe           42.7          13.7          208    &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;950 fema…  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with abbreviated variable names ¹​flipper_length_mm, ²​body_mass_g&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We get the minimum &lt;code&gt;body_mass_g&lt;/code&gt; for each &lt;code&gt;species&lt;/code&gt;, and in this case we get 2 for Adelie penguins because there is a tie.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;using-summarize-with-across&#34;&gt;Using &lt;code&gt;summarize()&lt;/code&gt; with &lt;code&gt;across()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;There are also ways that you can combine &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt; to function &lt;a href=&#34;https://dplyr.tidyverse.org/reference/across.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;across()&lt;/code&gt;&lt;/a&gt; your different variables. The function &lt;a href=&#34;https://tidyselect.r-lib.org/reference/where.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;where()&lt;/code&gt;&lt;/a&gt; allows you to pick variables where the function is &lt;code&gt;TRUE&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/across.html&#39;&gt;across&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;where&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;is.numeric&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 6&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   bill_length_mm bill_depth_mm flipper_length_mm body_mass_g  year&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie              38.8          18.3              190.       &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;706. &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap           48.8          18.4              196.       &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;733. &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo              47.6          15.0              217.       &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;092. &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# from column bill_length_mm to column flipper_length_mm&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/across.html&#39;&gt;across&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   bill_length_mm bill_depth_mm flipper_length_mm&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie              38.8          18.3              190.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap           48.8          18.4              196.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo              47.6          15.0              217.&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# using the helper contains()&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/across.html&#39;&gt;across&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/starts_with.html&#39;&gt;contains&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;mm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   bill_length_mm bill_depth_mm flipper_length_mm&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie              38.8          18.3              190.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap           48.8          18.4              196.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo              47.6          15.0              217.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;All of these &lt;a href=&#34;https://tidyselect.r-lib.org/reference/language.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;helper functions&lt;/a&gt; can be used outside of &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt; too.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-exercises-2&#34;&gt;Breakout Exercises 2&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s practice using &lt;a href=&#34;https://dplyr.tidyverse.org/reference/slice.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;slice()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt; with &lt;a href=&#34;https://dplyr.tidyverse.org/reference/across.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;across()&lt;/code&gt;&lt;/a&gt;, still using the &lt;code&gt;flights&lt;/code&gt; data.&lt;/p&gt;
&lt;h3 id=&#34;exercise-21&#34;&gt;Exercise 2.1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;What is the tail number (&lt;code&gt;tailnum&lt;/code&gt;) for the plane that has, on average, the least arrival delay?? What about the most arrival delay? How many flights did this plane take in this dataset? How would your answer change if you required that a plane take at least 50 flights?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Group the tibble by the &lt;code&gt;tailnum&lt;/code&gt; variable, and summarize to get mean &lt;code&gt;arr_delay&lt;/code&gt; and also &lt;a href=&#34;https://dplyr.tidyverse.org/reference/context.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;n()&lt;/code&gt;&lt;/a&gt;. Then pick the right &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; parameters if necessary, and the appropriate &lt;a href=&#34;https://dplyr.tidyverse.org/reference/se-deprecated.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;slice_()&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Least delayed flights&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# any number of flights&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tailnum&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_arr_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;            n_flights &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/slice.html&#39;&gt;slice_min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mean_arr_delay&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   tailnum mean_arr_delay n_flights&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; N560AS             -&lt;span style=&#39;color: #BB0000;&#39;&gt;53&lt;/span&gt;         1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# at least 50 flights&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tailnum&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_arr_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;            n_flights &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n_flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/slice.html&#39;&gt;slice_min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mean_arr_delay&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   tailnum mean_arr_delay n_flights&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; N548UW           -&lt;span style=&#39;color: #BB0000;&#39;&gt;13.0&lt;/span&gt;        52&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Most delayed flights&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# any number of flights&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tailnum&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_arr_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;            n_flights &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/slice.html&#39;&gt;slice_max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mean_arr_delay&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   tailnum mean_arr_delay n_flights&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; N844MH             320         1&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# at least 50 flights&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tailnum&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_arr_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;            n_flights &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n_flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/slice.html&#39;&gt;slice_max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mean_arr_delay&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   tailnum mean_arr_delay n_flights&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; N8698A            27.5        57&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-22&#34;&gt;Exercise 2.2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Calculate the median for &lt;code&gt;air_time&lt;/code&gt;, &lt;code&gt;arr_delay&lt;/code&gt; and &lt;code&gt;dep_delay&lt;/code&gt; by &lt;code&gt;origin&lt;/code&gt;. Try to not do each manually.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Group the tibble by the &lt;code&gt;origin&lt;/code&gt; variable, and combine &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://dplyr.tidyverse.org/reference/across.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;across()&lt;/code&gt;&lt;/a&gt; to get the median for each variable. Try listing them together using &lt;a href=&#34;https://rdrr.io/r/base/c.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;c()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;air_time&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;origin&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;origin&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/across.html&#39;&gt;across&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;air_time&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;median&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;                   .names &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;&amp;#123;col&amp;#125;_median&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# extra fun thing to rename columns&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   origin air_time_median arr_delay_median dep_delay_median&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; EWR                130               -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;               -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; JFK                149               -&lt;span style=&#39;color: #BB0000;&#39;&gt;6&lt;/span&gt;               -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; LGA                115               -&lt;span style=&#39;color: #BB0000;&#39;&gt;5&lt;/span&gt;               -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-23&#34;&gt;Exercise 2.3&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Which destinations have the longest maximum arrival delay? Which destinations have the shortest? Pull data for the top 10 for both the longest and shortest maximum arrival delay. Keep track of how many flights there are to each location in case that might be useful information.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Group the tibble by the &lt;code&gt;dest&lt;/code&gt; variable, and summarize to get max &lt;code&gt;arr_delay&lt;/code&gt; and also &lt;a href=&#34;https://dplyr.tidyverse.org/reference/context.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;n()&lt;/code&gt;&lt;/a&gt;. Then pick the right &lt;a href=&#34;https://dplyr.tidyverse.org/reference/se-deprecated.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;slice_()&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
Least delayed
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;max_arr_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;            n_flights &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/slice.html&#39;&gt;slice_min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;max_arr_delay&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 10 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dest  max_arr_delay n_flights&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; LEX             -&lt;span style=&#39;color: #BB0000;&#39;&gt;22&lt;/span&gt;         1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; PSP              17        18&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; ANC              39         8&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; HDN              43        14&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; EYW              45        17&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; SBN              53        10&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; MTJ             101        14&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; ILM             143       107&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; ABQ             153       254&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; BZN             154        35&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Most delayed&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;max_arr_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;            n_flights &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/slice.html&#39;&gt;slice_max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;max_arr_delay&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 10 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dest  max_arr_delay n_flights&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; HNL            &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;272       701&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; CMH            &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;127      &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;326&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; ORD            &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;109     &lt;span style=&#39;text-decoration: underline;&#39;&gt;16&lt;/span&gt;566&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; SFO            &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;007     &lt;span style=&#39;text-decoration: underline;&#39;&gt;13&lt;/span&gt;173&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; CVG             989      &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;725&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; TPA             931      &lt;span style=&#39;text-decoration: underline;&#39;&gt;7&lt;/span&gt;390&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; MSP             915      &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;929&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; ATL             895     &lt;span style=&#39;text-decoration: underline;&#39;&gt;16&lt;/span&gt;837&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; MIA             878     &lt;span style=&#39;text-decoration: underline;&#39;&gt;11&lt;/span&gt;593&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; LAS             852      &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;952&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>S04E13: R for Data Science - Chapter 5.6: summarize</title>
      <link>https://biodash.github.io/codeclub/s04e13/</link>
      <pubDate>Thu, 03 Nov 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s04e13/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;get-the-dataset-and-packages&#34;&gt;Get the Dataset and Packages&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Only if you haven&#39;t done so before, install the packages&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;nycflights13&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# Load the flights dataset and tidyverse&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/hadley/nycflights13&#39;&gt;nycflights13&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;preview-the-dataset&#34;&gt;Preview the Dataset&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://pillar.r-lib.org/reference/glimpse.html&#39;&gt;glimpse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 336,776&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 19&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ month          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ day            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ dep_time       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 517, 533, 542, 544, 554, 554, 555, 557, 557, 558, 558, …&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sched_dep_time &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 515, 529, 540, 545, 600, 558, 600, 600, 600, 600, 600, …&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ dep_delay      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 2, 4, 2, -1, -6, -4, -5, -3, -3, -2, -2, -2, -2, -2, -1…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ arr_time       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 830, 850, 923, 1004, 812, 740, 913, 709, 838, 753, 849,…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sched_arr_time &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 819, 830, 850, 1022, 837, 728, 854, 723, 846, 745, 851,…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ arr_delay      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 11, 20, 33, -18, -25, 12, 19, -14, -8, 8, -2, -3, 7, -1…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ carrier        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;UA&#34;, &#34;UA&#34;, &#34;AA&#34;, &#34;B6&#34;, &#34;DL&#34;, &#34;UA&#34;, &#34;B6&#34;, &#34;EV&#34;, &#34;B6&#34;, &#34;…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ flight         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 1545, 1714, 1141, 725, 461, 1696, 507, 5708, 79, 301, 4…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ tailnum        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;N14228&#34;, &#34;N24211&#34;, &#34;N619AA&#34;, &#34;N804JB&#34;, &#34;N668DN&#34;, &#34;N394…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ origin         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;EWR&#34;, &#34;LGA&#34;, &#34;JFK&#34;, &#34;JFK&#34;, &#34;LGA&#34;, &#34;EWR&#34;, &#34;EWR&#34;, &#34;LGA&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ dest           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;IAH&#34;, &#34;IAH&#34;, &#34;MIA&#34;, &#34;BQN&#34;, &#34;ATL&#34;, &#34;ORD&#34;, &#34;FLL&#34;, &#34;IAD&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ air_time       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 227, 227, 160, 183, 116, 150, 158, 53, 140, 138, 149, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ distance       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 1400, 1416, 1089, 1576, 762, 719, 1065, 229, 944, 733, …&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ hour           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 5, 5, 5, 5, 6, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 6, 6…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ minute         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 15, 29, 40, 45, 0, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 59, 0…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ time_hour      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt; 2013-01-01 05:00:00, 2013-01-01 05:00:00, 2013-01-01 0…&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;review-of-select-filter-mutate&#34;&gt;Review of &lt;code&gt;select()&lt;/code&gt;, &lt;code&gt;filter()&lt;/code&gt;, &lt;code&gt;mutate()&lt;/code&gt;&lt;/h2&gt;
&lt;h3 id=&#34;select&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The flights tibble has 19 variables &amp;ndash; to keep things simple, we&amp;rsquo;ll focus on just a few of these for now. Let&amp;rsquo;s choose the variables (columns) &lt;code&gt;carrier&lt;/code&gt;, &lt;code&gt;flight&lt;/code&gt;, &lt;code&gt;air_time&lt;/code&gt;, and &lt;code&gt;dep_delay&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights_exp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;carrier&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;flight&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;air_time&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights_exp&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    carrier flight air_time dep_delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; UA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;545      227         2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; UA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;714      227         4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; AA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;141      160         2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; B6         725      183        -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; DL         461      116        -&lt;span style=&#39;color: #BB0000;&#39;&gt;6&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; UA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;696      150        -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; B6         507      158        -&lt;span style=&#39;color: #BB0000;&#39;&gt;5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; EV        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;708       53        -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; B6          79      140        -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; AA         301      138        -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;filter&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;There are &amp;gt;336,000 observations (flights) in this dataset. Let&amp;rsquo;s reduce it to just American Airlines flights:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights_exp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights_exp&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;carrier&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;AA&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights_exp&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 32,729 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    carrier flight air_time dep_delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; AA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;141      160         2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; AA         301      138        -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; AA         707      257        -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; AA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;895      152        -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; AA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;837      153        13&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; AA         413      192        -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; AA         303      140        -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; AA         711      248         0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; AA         305      143        -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; AA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;815      142        -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 32,719 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;mutate&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The column &lt;code&gt;air_time&lt;/code&gt; is measured in minutes. What if we wanted a new column &lt;code&gt;air_time_hrs&lt;/code&gt; that reports the air time in hours?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights_exp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights_exp&lt;/span&gt;, air_time_hrs &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;air_time&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;/&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;60&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights_exp&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 32,729 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    carrier flight air_time dep_delay air_time_hrs&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; AA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;141      160         2         2.67&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; AA         301      138        -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;         2.3 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; AA         707      257        -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;         4.28&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; AA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;895      152        -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;         2.53&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; AA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;837      153        13         2.55&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; AA         413      192        -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;         3.2 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; AA         303      140        -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;         2.33&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; AA         711      248         0         4.13&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; AA         305      143        -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;         2.38&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; AA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;815      142        -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;         2.37&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 32,719 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;section-56-summarise&#34;&gt;Section 5.6: &lt;code&gt;summarise()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Here&amp;rsquo;s an example of how to use &lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarise()&lt;/code&gt;&lt;/a&gt; in the simplest way. Notice the similarity in syntax with &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarise&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;  12.6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarise()&lt;/code&gt;&lt;/a&gt; is typically combined with &lt;a href=&#34;https://dplyr.tidyverse.org/reference/group_by.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;group_by()&lt;/code&gt;&lt;/a&gt;, calculating the new summarized variable separately for each set of grouped observations in the dataset:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;by_day&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;month&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;day&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarise&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;by_day&lt;/span&gt;, delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 365 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# Groups:   year, month [12]&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     year month   day delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1 11.5 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     2 13.9 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     3 11.0 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     4  8.95&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     5  5.73&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     6  7.15&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     7  5.42&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     8  2.55&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     9  2.28&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1    10  2.84&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 355 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And more than one new summarized variable can be calculated - here, there are 3:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;by_dest&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;delay&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarise&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;by_dest&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  count &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  dist &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;distance&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 105 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dest  count  dist delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; ABQ     254 &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;826   4.38&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; ACK     265  199   4.85&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; ALB     439  143  14.4 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; ANC       8 &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;370  -&lt;span style=&#39;color: #BB0000;&#39;&gt;2.5&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; ATL   &lt;span style=&#39;text-decoration: underline;&#39;&gt;17&lt;/span&gt;215  757. 11.3 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; AUS    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;439 &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;514.  6.02&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; AVL     275  584.  8.00&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; BDL     443  116   7.05&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; BGR     375  378   8.03&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; BHM     297  866. 16.9 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 95 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s look a bit closer at what this is doing (note, this is not in the book):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights_sub&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;distance&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights_sub&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dest  distance arr_delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; IAH       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;400        11&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; IAH       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;416        20&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; MIA       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;089        33&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; BQN       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;576       -&lt;span style=&#39;color: #BB0000;&#39;&gt;18&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; ATL        762       -&lt;span style=&#39;color: #BB0000;&#39;&gt;25&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; ORD        719        12&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; FLL       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;065        19&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; IAD        229       -&lt;span style=&#39;color: #BB0000;&#39;&gt;14&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; MCO        944        -&lt;span style=&#39;color: #BB0000;&#39;&gt;8&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; ORD        733         8&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;albuquerque_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights_sub&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ABQ&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;albuquerque_data&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 254 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dest  distance arr_delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; ABQ       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;826       -&lt;span style=&#39;color: #BB0000;&#39;&gt;35&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; ABQ       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;826       -&lt;span style=&#39;color: #BB0000;&#39;&gt;18&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; ABQ       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;826       -&lt;span style=&#39;color: #BB0000;&#39;&gt;16&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; ABQ       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;826        16&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; ABQ       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;826       -&lt;span style=&#39;color: #BB0000;&#39;&gt;20&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; ABQ       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;826       -&lt;span style=&#39;color: #BB0000;&#39;&gt;14&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; ABQ       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;826       -&lt;span style=&#39;color: #BB0000;&#39;&gt;15&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; ABQ       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;826       -&lt;span style=&#39;color: #BB0000;&#39;&gt;32&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; ABQ       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;826       -&lt;span style=&#39;color: #BB0000;&#39;&gt;28&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; ABQ       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;826       -&lt;span style=&#39;color: #BB0000;&#39;&gt;13&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 244 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;mean_albuquerque_delay&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;albuquerque_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;mean_albuquerque_delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.38189&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Compare the value &lt;code&gt;mean_albuquerque_delay&lt;/code&gt; to that in the summarized &lt;code&gt;delay&lt;/code&gt; tibble created above:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;mean_albuquerque_delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.38189&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 105 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dest  count  dist delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; ABQ     254 &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;826   4.38&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; ACK     265  199   4.85&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; ALB     439  143  14.4 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; ANC       8 &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;370  -&lt;span style=&#39;color: #BB0000;&#39;&gt;2.5&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; ATL   &lt;span style=&#39;text-decoration: underline;&#39;&gt;17&lt;/span&gt;215  757. 11.3 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; AUS    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;439 &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;514.  6.02&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; AVL     275  584.  8.00&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; BDL     443  116   7.05&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; BGR     375  378   8.03&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; BHM     297  866. 16.9 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 95 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-exercises-1&#34;&gt;Breakout Exercises 1&lt;/h2&gt;
&lt;p&gt;Start with the original &lt;code&gt;flights&lt;/code&gt; tibble for each of the following exercises.&lt;/p&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Overall, which carrier had the longest mean arrival delay (&lt;em&gt;arr_delay&lt;/em&gt;) in 2013? (Note, all these data are from 2013.)&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Group the tibble by the &lt;em&gt;carrier&lt;/em&gt; variable, then summarise to calculate the mean &lt;em&gt;arr_delay&lt;/em&gt; for each group. Remember to ignore missing values by setting &lt;code&gt;na.rm = TRUE&lt;/code&gt; within the &lt;a href=&#34;https://rdrr.io/r/base/mean.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mean()&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;carrier_grp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;carrier&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarise&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carrier_grp&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  mean_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 16 × 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    carrier mean_delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; 9E           7.38 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; AA           0.364&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; AS          -&lt;span style=&#39;color: #BB0000;&#39;&gt;9.93&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; B6           9.46 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; DL           1.64 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; EV          15.8  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; F9          21.9  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; FL          20.1  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; HA          -&lt;span style=&#39;color: #BB0000;&#39;&gt;6.92&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; MQ          10.8  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;11&lt;/span&gt; OO          11.9  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;12&lt;/span&gt; UA           3.56 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;13&lt;/span&gt; US           2.13 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;14&lt;/span&gt; VX           1.76 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;15&lt;/span&gt; WN           9.65 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;16&lt;/span&gt; YV          15.6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Evaluate arrival delay by carrier again, but this time, evaluate only for carriers who made at least 10,000 flights.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Include a second variable in the summarized data from above to reflect the number of observations that went in to calculating the mean value for each group, then filter on this sample size variable. Consider using the function &lt;a href=&#34;https://dplyr.tidyverse.org/reference/context.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;n()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;carrier_delays&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarise&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carrier_grp&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  mean_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carrier_delays&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 9 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   carrier mean_delay     n&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; 9E           7.38  &lt;span style=&#39;text-decoration: underline;&#39;&gt;18&lt;/span&gt;460&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; AA           0.364 &lt;span style=&#39;text-decoration: underline;&#39;&gt;32&lt;/span&gt;729&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; B6           9.46  &lt;span style=&#39;text-decoration: underline;&#39;&gt;54&lt;/span&gt;635&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; DL           1.64  &lt;span style=&#39;text-decoration: underline;&#39;&gt;48&lt;/span&gt;110&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; EV          15.8   &lt;span style=&#39;text-decoration: underline;&#39;&gt;54&lt;/span&gt;173&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; MQ          10.8   &lt;span style=&#39;text-decoration: underline;&#39;&gt;26&lt;/span&gt;397&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;7&lt;/span&gt; UA           3.56  &lt;span style=&#39;text-decoration: underline;&#39;&gt;58&lt;/span&gt;665&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;8&lt;/span&gt; US           2.13  &lt;span style=&#39;text-decoration: underline;&#39;&gt;20&lt;/span&gt;536&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;9&lt;/span&gt; WN           9.65  &lt;span style=&#39;text-decoration: underline;&#39;&gt;12&lt;/span&gt;275&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Based on these data, what airport is the worst to fly in to with regards to arriving on time? In other words, which airport (&lt;code&gt;dest&lt;/code&gt;) is associated with the highest average arrival delays?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Group the tibble by the &lt;code&gt;dest&lt;/code&gt; variable, summarise with the mean &lt;code&gt;arr_delay&lt;/code&gt; for each group, then use &lt;a href=&#34;https://dplyr.tidyverse.org/reference/arrange.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;arrange()&lt;/code&gt;&lt;/a&gt; to sort the new variable in descending order, which can be done with &lt;a href=&#34;https://dplyr.tidyverse.org/reference/desc.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;desc()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;dest_grp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;dest_delays&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarise&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dest_grp&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  mean_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/arrange.html&#39;&gt;arrange&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dest_delays&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/desc.html&#39;&gt;desc&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mean_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 105 × 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dest  mean_delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; CAE         41.8&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; TUL         33.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; OKC         30.6&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; JAC         28.1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; TYS         24.1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; MSN         20.2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; RIC         20.1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; CAK         19.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; DSM         19.0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; GRR         18.2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 95 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;using-pipes&#34;&gt;Using Pipes&lt;/h2&gt;
&lt;p&gt;We did this above&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;by_dest&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;delay&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarise&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;by_dest&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  count &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  dist &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;distance&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;That code can be rewritten with the pipe as follows&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;delays&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarise&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    count &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;    dist &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;distance&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;    delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice here we didn&amp;rsquo;t have to create intermediate/temporary tibbles.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-exercises-2&#34;&gt;Breakout Exercises 2&lt;/h2&gt;
&lt;p&gt;Here we&amp;rsquo;ll redo the same analyses as in the first breakout session, but this time using the pipe.&lt;/p&gt;
&lt;h3 id=&#34;exercise-1-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Overall, which carrier had the longest mean arrival delay (&lt;em&gt;arr_delay&lt;/em&gt;) in 2013? (Note, all these data are from 2013.)&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carrier&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarise&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 16 × 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    carrier mean_delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; 9E           7.38 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; AA           0.364&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; AS          -&lt;span style=&#39;color: #BB0000;&#39;&gt;9.93&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; B6           9.46 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; DL           1.64 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; EV          15.8  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; F9          21.9  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; FL          20.1  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; HA          -&lt;span style=&#39;color: #BB0000;&#39;&gt;6.92&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; MQ          10.8  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;11&lt;/span&gt; OO          11.9  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;12&lt;/span&gt; UA           3.56 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;13&lt;/span&gt; US           2.13 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;14&lt;/span&gt; VX           1.76 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;15&lt;/span&gt; WN           9.65 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;16&lt;/span&gt; YV          15.6&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2-1&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Evaluate arrival delay by carrier again, but this time, evaluate only for carriers who made at least 10,000 flights.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carrier&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarise&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    mean_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;    n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/context.html&#39;&gt;n&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 9 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   carrier mean_delay     n&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; 9E           7.38  &lt;span style=&#39;text-decoration: underline;&#39;&gt;18&lt;/span&gt;460&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; AA           0.364 &lt;span style=&#39;text-decoration: underline;&#39;&gt;32&lt;/span&gt;729&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; B6           9.46  &lt;span style=&#39;text-decoration: underline;&#39;&gt;54&lt;/span&gt;635&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; DL           1.64  &lt;span style=&#39;text-decoration: underline;&#39;&gt;48&lt;/span&gt;110&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; EV          15.8   &lt;span style=&#39;text-decoration: underline;&#39;&gt;54&lt;/span&gt;173&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; MQ          10.8   &lt;span style=&#39;text-decoration: underline;&#39;&gt;26&lt;/span&gt;397&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;7&lt;/span&gt; UA           3.56  &lt;span style=&#39;text-decoration: underline;&#39;&gt;58&lt;/span&gt;665&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;8&lt;/span&gt; US           2.13  &lt;span style=&#39;text-decoration: underline;&#39;&gt;20&lt;/span&gt;536&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;9&lt;/span&gt; WN           9.65  &lt;span style=&#39;text-decoration: underline;&#39;&gt;12&lt;/span&gt;275&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3-1&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Based on these data, what airport is the worst to fly in to with regards to arriving on time? In other words, which airport (&lt;code&gt;dest&lt;/code&gt;) is associated with the highest average arrival delays?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarise&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_delay &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/arrange.html&#39;&gt;arrange&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/desc.html&#39;&gt;desc&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mean_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 105 × 2&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dest  mean_delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; CAE         41.8&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; TUL         33.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; OKC         30.6&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; JAC         28.1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; TYS         24.1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; MSN         20.2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; RIC         20.1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; CAK         19.7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; DSM         19.0&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; GRR         18.2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 95 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>S04E12: R for Data Science - Chapter 5.5: mutate</title>
      <link>https://biodash.github.io/codeclub/s04e12_r4ds-ch5-5/</link>
      <pubDate>Thu, 27 Oct 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s04e12_r4ds-ch5-5/</guid>
      <description>&lt;figure&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/mutate.jpeg width=&#34;70%&#34;&gt;
&lt;figcaption&gt;
Artwork by Allison Horst
&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Today we are going to cover the dplyr function &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt;. You can today&amp;rsquo;s topic in the R 4 Data Science book at: &lt;a href=&#34;https://r4ds.had.co.nz/transform.html#add-new-variables-with-mutate&#34;&gt;https://r4ds.had.co.nz/transform.html#add-new-variables-with-mutate&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We will again be using the &lt;code&gt;nycflights13&lt;/code&gt; and &lt;code&gt;tidyverse&lt;/code&gt; packages, so we first need make sure these packages are installed, and then load them for the current session by doing &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; commands:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;## Only if you haven&#39;t done so before, install the packages&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;nycflights13&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;## Load the packages&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/hadley/nycflights13&#39;&gt;nycflights13&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;the-mutate-function&#34;&gt;The &lt;code&gt;mutate()&lt;/code&gt; function&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; function always &lt;em&gt;adds&lt;/em&gt; new columns at the end of your dataset. Let us create a small dataset so we can see the new variables:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights_sml&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;day&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/starts_with.html&#39;&gt;ends_with&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;delay&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nv&#39;&gt;distance&lt;/span&gt;, &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nv&#39;&gt;air_time&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As a first example, let&amp;rsquo;s add columns &lt;code&gt;gain&lt;/code&gt; (delay made up) and &lt;code&gt;speed&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 9&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     year month   day dep_delay arr_delay distance air_time  gain speed&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1         2        11     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;400      227    -&lt;span style=&#39;color: #BB0000;&#39;&gt;9&lt;/span&gt;  370.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1         4        20     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;416      227   -&lt;span style=&#39;color: #BB0000;&#39;&gt;16&lt;/span&gt;  374.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1         2        33     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;089      160   -&lt;span style=&#39;color: #BB0000;&#39;&gt;31&lt;/span&gt;  408.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1        -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;       -&lt;span style=&#39;color: #BB0000;&#39;&gt;18&lt;/span&gt;     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;576      183    17  517.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1        -&lt;span style=&#39;color: #BB0000;&#39;&gt;6&lt;/span&gt;       -&lt;span style=&#39;color: #BB0000;&#39;&gt;25&lt;/span&gt;      762      116    19  394.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1        -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;        12      719      150   -&lt;span style=&#39;color: #BB0000;&#39;&gt;16&lt;/span&gt;  288.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1        -&lt;span style=&#39;color: #BB0000;&#39;&gt;5&lt;/span&gt;        19     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;065      158   -&lt;span style=&#39;color: #BB0000;&#39;&gt;24&lt;/span&gt;  404.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1        -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;       -&lt;span style=&#39;color: #BB0000;&#39;&gt;14&lt;/span&gt;      229       53    11  259.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1        -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;        -&lt;span style=&#39;color: #BB0000;&#39;&gt;8&lt;/span&gt;      944      140     5  405.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1        -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;         8      733      138   -&lt;span style=&#39;color: #BB0000;&#39;&gt;10&lt;/span&gt;  319.&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights_sml&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  gain &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  speed &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;distance&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;air_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;60&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;transmute()&lt;/code&gt;&lt;/a&gt; is very similar to &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt;, except the returned dataframe only contains the new variables that were created:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;transmute&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  gain &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  hours &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;air_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;60&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  gain_per_hour &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gain&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;hours&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     gain hours gain_per_hour&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;    -&lt;span style=&#39;color: #BB0000;&#39;&gt;9&lt;/span&gt; 3.78          -&lt;span style=&#39;color: #BB0000;&#39;&gt;2.38&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000;&#39;&gt;16&lt;/span&gt; 3.78          -&lt;span style=&#39;color: #BB0000;&#39;&gt;4.23&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000;&#39;&gt;31&lt;/span&gt; 2.67         -&lt;span style=&#39;color: #BB0000;&#39;&gt;11.6&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;    17 3.05           5.57&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;    19 1.93           9.83&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000;&#39;&gt;16&lt;/span&gt; 2.5           -&lt;span style=&#39;color: #BB0000;&#39;&gt;6.4&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000;&#39;&gt;24&lt;/span&gt; 2.63          -&lt;span style=&#39;color: #BB0000;&#39;&gt;9.11&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;    11 0.883         12.5 &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;     5 2.33           2.14&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000;&#39;&gt;10&lt;/span&gt; 2.3           -&lt;span style=&#39;color: #BB0000;&#39;&gt;4.35&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;useful-creation-functions-to-use-with-mutate&#34;&gt;Useful creation functions to use with mutate&lt;/h2&gt;
&lt;p&gt;Note that functions must be vectorised before use with &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Arithmetic operators:&lt;/strong&gt; &lt;code&gt;+&lt;/code&gt; (addition), &lt;code&gt;-&lt;/code&gt; (subtraction), &lt;code&gt;*&lt;/code&gt; (multiplication), &lt;code&gt;/&lt;/code&gt; (division), &lt;code&gt;^&lt;/code&gt; (to the power)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Modular arithmetic:&lt;/strong&gt; &lt;code&gt;%/%&lt;/code&gt; (integer division) and &lt;code&gt;%%&lt;/code&gt; (remainder). Modular arithmetic is a handy tool because it allows you to break integers up into pieces. For example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;transmute&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  hour &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%/%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;  minute &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dep_time  hour minute&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;      517     5     17&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;      533     5     33&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;      542     5     42&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;      544     5     44&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;      554     5     54&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;      554     5     54&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;      555     5     55&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;      557     5     57&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;      557     5     57&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;      558     5     58&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Logs:&lt;/strong&gt; &lt;a href=&#34;https://rdrr.io/r/base/Log.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;log ()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://rdrr.io/r/base/Log.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;log2()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://rdrr.io/r/base/Log.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;log10()&lt;/code&gt;&lt;/a&gt;. Logarithms are useful transformation for dealing with data that ranges across multiple orders of magnitude.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Offsets:&lt;/strong&gt; &lt;a href=&#34;https://dplyr.tidyverse.org/reference/lead-lag.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lead()&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;lag()&lt;/code&gt;. These allow you to refer to leading or lagging values:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  1  2  3  4  5  6  7  8  9 10&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;lag&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] NA  1  2  3  4  5  6  7  8  9&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/lead-lag.html&#39;&gt;lead&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  2  3  4  5  6  7  8  9 10 NA&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Cumulative and rolling aggregates:&lt;/strong&gt; R provides functions for sums &lt;a href=&#34;https://rdrr.io/r/base/cumsum.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;cumsum()&lt;/code&gt;&lt;/a&gt;, products &lt;a href=&#34;https://rdrr.io/r/base/cumsum.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;cumprod()&lt;/code&gt;&lt;/a&gt;, mins &lt;a href=&#34;https://rdrr.io/r/base/cumsum.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;cummin()&lt;/code&gt;&lt;/a&gt;, and maxes &lt;a href=&#34;https://rdrr.io/r/base/cumsum.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;cummax()&lt;/code&gt;&lt;/a&gt;; and dplyr provides function for mean &lt;a href=&#34;https://dplyr.tidyverse.org/reference/cumall.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;cummean()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  1  2  3  4  5  6  7  8  9 10&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/cumsum.html&#39;&gt;cumsum&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  1  3  6 10 15 21 28 36 45 55&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/cumall.html&#39;&gt;cummean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0 5.5&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Logical comparisons:&lt;/strong&gt; &lt;code&gt;&amp;lt;&lt;/code&gt; (less than), &lt;code&gt;&amp;lt;=&lt;/code&gt; (equal to or less than), &lt;code&gt;&amp;gt;&lt;/code&gt; (greater than), &lt;code&gt;&amp;gt;=&lt;/code&gt; (equal to or greater than), &lt;code&gt;!=&lt;/code&gt; (not equal to), and &lt;code&gt;==&lt;/code&gt; (equal to).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Ranking:&lt;/strong&gt; &lt;a href=&#34;https://dplyr.tidyverse.org/reference/ranking.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;min_rank()&lt;/code&gt;&lt;/a&gt; gives the smallest values the small rank, and &lt;code&gt;desc(x)&lt;/code&gt; to give the largest values the smallest ranks.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/ranking.html&#39;&gt;min_rank&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  1  2  2 NA  4  5&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/ranking.html&#39;&gt;min_rank&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/desc.html&#39;&gt;desc&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  5  3  3 NA  2  1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;There are other ranks functions, too, e.g., &lt;a href=&#34;https://dplyr.tidyverse.org/reference/ranking.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;row_number()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://dplyr.tidyverse.org/reference/ranking.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dense_rank()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://dplyr.tidyverse.org/reference/ranking.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;percent_rank()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://dplyr.tidyverse.org/reference/ranking.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;cume_dist()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://dplyr.tidyverse.org/reference/ranking.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ntile()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/ranking.html&#39;&gt;row_number&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  1  2  3 NA  4  5&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/ranking.html&#39;&gt;dense_rank&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  1  2  2 NA  3  4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/ranking.html&#39;&gt;percent_rank&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.00 0.25 0.25   NA 0.75 1.00&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-room-exercises&#34;&gt;Breakout room exercises&lt;/h2&gt;
&lt;p&gt;These correspond to the &lt;a href=&#34;https://r4ds.had.co.nz/transform.html#exercises-11&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;exercises in the R4DS book&lt;/a&gt;, but we&amp;rsquo;re skipping exercises 2 and 6.&lt;/p&gt;
&lt;h3 id=&#34;r4ds-exercise-1&#34;&gt;R4DS Exercise 1&lt;/h3&gt;
&lt;p&gt;Currently &lt;code&gt;dep_time&lt;/code&gt; and &lt;code&gt;sched_dep_time&lt;/code&gt; are convenient to look at, but hard to compute with because they&amp;rsquo;re not really continuous numbers. Convert them to a more convenient representation of number of minutes since midnight.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;You can use the following code structure (we first select only relevant columns to more easily check the results):&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;sched_dep_time&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    &lt;span class=&#39;nv&#39;&gt;flights_times&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;    dep_time_mins &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;YOUR_CODE_HERE&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;    sched_dep_time_mins &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;YOUR_CODE_HERE&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Get the number of &lt;em&gt;hours&lt;/em&gt; since midnight using &lt;code&gt;%/%&lt;/code&gt; (as in the example in the book) and then convert this number to minutes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Then, get the number of &lt;em&gt;minutes&lt;/em&gt; past the hour using &lt;code&gt;%%&lt;/code&gt; (again as in the example in the book), and add this number to the previous one to get the total number of minutes past midnight.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now, you might think you&amp;rsquo;re all done, but there is one remaining problem: midnight was originally represented as &lt;code&gt;2400&lt;/code&gt;, which the code described above would convert to &lt;code&gt;1440&lt;/code&gt; (&lt;code&gt;24 * 60&lt;/code&gt;). But it should be &lt;code&gt;0&lt;/code&gt; instead. This is a tricky one, but you can handle it using an additional &lt;code&gt;%%&lt;/code&gt; calculation.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;To handle the midnight case, use &lt;code&gt;%% 1440&lt;/code&gt;: this would simply return the original value for all values below 1440, and would return &lt;code&gt;0&lt;/code&gt; only for &lt;code&gt;1440&lt;/code&gt; (midnight):&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;sched_dep_time&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    dep_time_mins &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%/%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;60&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1440&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;    sched_dep_time_mins &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sched_dep_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%/%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;60&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sched_dep_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1440&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dep_time sched_dep_time dep_time_mins sched_dep_time_mins&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;      517            515           317                 315&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;      533            529           333                 329&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;      542            540           342                 340&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;      544            545           344                 345&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;      554            600           354                 360&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;      554            558           354                 358&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;      555            600           355                 360&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;      557            600           357                 360&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;      557            600           357                 360&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;      558            600           358                 360&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;r4ds-exercise-3&#34;&gt;R4DS Exercise 3&lt;/h3&gt;
&lt;p&gt;Compare &lt;code&gt;dep_time&lt;/code&gt;, &lt;code&gt;sched_dep_time&lt;/code&gt;, and &lt;code&gt;dep_delay&lt;/code&gt;. How would you expect those three numbers to be related? Test if this is indeed the case.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;We should expect &lt;code&gt;dep_delay&lt;/code&gt; to equal the difference between &lt;code&gt;sched_dep_time&lt;/code&gt; and &lt;code&gt;dep_time&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To check this, the first step is to use your code from exercise 1 to create columns with the &lt;code&gt;sched_dep_time&lt;/code&gt; and the &lt;code&gt;dep_time&lt;/code&gt; in minutes past midnight.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Then, create a column with the difference in minutes between &lt;code&gt;sched_dep_time&lt;/code&gt; and &lt;code&gt;dep_time&lt;/code&gt; (e.g. called &lt;code&gt;our_delay_calc&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Next, create a column with the difference between &lt;code&gt;our_delay_calc&lt;/code&gt; and &lt;code&gt;dep_delay&lt;/code&gt; (e.g. called &lt;code&gt;delay_diff&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Finally, use &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; to see if there are any rows where the &lt;code&gt;delay_diff&lt;/code&gt; does not equal 0. Recall that we would expect no differences at all, if all is well. So what is going on with those rows?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;sched_dep_time&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;    dep_time_min &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%/%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;60&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1440&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;    sched_dep_time_min &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sched_dep_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%/%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;60&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sched_dep_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Arithmetic.html&#39;&gt;%%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1440&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;    our_delay_calc &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dep_time_min&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sched_dep_time_min&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;    dep_delay_diff &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;our_delay_calc&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_delay_diff&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;!=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1,236 × 7&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dep_time sched_dep_time dep_delay dep_time_min sched_dep_ti…¹ our_d…² dep_d…³&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;      848           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;835       853          528           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;115    -&lt;span style=&#39;color: #BB0000;&#39;&gt;587&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;440&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;       42           &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;359        43           42           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;439   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;397&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;440&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;      126           &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;250       156           86           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;370   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;284&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;440&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;       32           &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;359        33           32           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;439   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;407&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;440&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;       50           &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;145       185           50           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;305   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;255&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;440&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;      235           &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;359       156          155           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;439   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;284&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;440&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;       25           &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;359        26           25           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;439   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;414&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;440&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;      106           &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;245       141           66           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;365   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;299&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;440&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;       14           &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;359        15           14           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;439   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;425&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;440&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;       37           &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;230       127           37           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;350   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;313&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;440&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1,226 more rows, and abbreviated variable names ¹​sched_dep_time_min,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ²​our_delay_calc, ³​dep_delay_diff&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;These &lt;code&gt;dep_delay_diff&lt;/code&gt; values are all 1440 minutes (= 24 hours), and as you can see, these are flights that were scheduled to depart one day but left only the next day (past midnight).&lt;/p&gt;
&lt;p&gt;So, for our &lt;code&gt;dep_time_min&lt;/code&gt; and &lt;code&gt;sched_dep_time_min&lt;/code&gt; to always work for calculations, they should also take dates into account &amp;ndash; and should e.g. be minutes past some date in the past.&lt;/p&gt;
&lt;/details&gt;
&lt;h3 id=&#34;r4ds-exercise-4&#34;&gt;R4DS Exercise 4&lt;/h3&gt;
&lt;p&gt;Find the 10 most delayed flights using a ranking function. How do you want to handle ties? Carefully read the documentation for &lt;a href=&#34;https://dplyr.tidyverse.org/reference/ranking.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;min_rank()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; to create a new column with the ranks, then arrange by this column and/or filter only top ranks to get the most delayed flights.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To see the differences in the handling of ties between &lt;a href=&#34;https://dplyr.tidyverse.org/reference/ranking.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;row_number()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://dplyr.tidyverse.org/reference/ranking.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;min_rank()&lt;/code&gt;&lt;/a&gt;, and &lt;a href=&#34;https://dplyr.tidyverse.org/reference/ranking.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dense_rank()&lt;/code&gt;&lt;/a&gt;, take a look this:&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tibble.tidyverse.org/reference/tibble.html&#39;&gt;tibble&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;delays &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;130&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;276&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       rank_rownr &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/ranking.html&#39;&gt;row_number&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;delays&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       rank_min &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/ranking.html&#39;&gt;min_rank&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;delays&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       rank_dense &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/ranking.html&#39;&gt;dense_rank&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;delays&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   delays rank_rownr rank_min rank_dense&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;      3          1        1          1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;      5          2        2          2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;      5          3        2          2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;      5          4        2          2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;    130          5        5          3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;    276          6        6          4&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;sched_dep_time&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;dep_delay_rank &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/ranking.html&#39;&gt;min_rank&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/desc.html&#39;&gt;desc&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_delay_rank&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/arrange.html&#39;&gt;arrange&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_delay_rank&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 10 × 4&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dep_time sched_dep_time dep_delay dep_delay_rank&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;      641            900      &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;301              1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;432           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;935      &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;137              2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;121           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;635      &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;126              3&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;139           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;845      &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;014              4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;      845           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;600      &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;005              5&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;100           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;900       960              6&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;     &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;321            810       911              7&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;      959           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;900       899              8&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;     &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;257            759       898              9&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;      756           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;700       896             10&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;h3 id=&#34;r4ds-exercise-5&#34;&gt;R4DS Exercise 5&lt;/h3&gt;
&lt;p&gt;What does &lt;code&gt;1:3 + 1:10&lt;/code&gt; return? Why?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, you should realize that &lt;code&gt;1:3&lt;/code&gt; expands to a vector with the values &lt;code&gt;1&lt;/code&gt;, &lt;code&gt;2&lt;/code&gt;, and &lt;code&gt;3&lt;/code&gt;, and similarly for &lt;code&gt;1:10&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Many R operations are &lt;em&gt;vectorized&lt;/em&gt;, which means that when pairing two vectors (including the case where one of those vectors is just a single value), the shorter vector will be recycled. In the example below, &lt;code&gt;3&lt;/code&gt; is recycled and added to every single value in the vector &lt;code&gt;1:5&lt;/code&gt;:&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4 5 6 7 8&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning in 1:3 + 1:10: longer object length is not a multiple of shorter object length&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  2  4  6  5  7  9  8 10 12 11&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;R gives a warning because the length of the longer vector isn&amp;rsquo;t a multiple of the length of the shorter vector: it recycles &lt;code&gt;1:3&lt;/code&gt; three times and is then left over with a single value from &lt;code&gt;1:3&lt;/code&gt; to be paired with &lt;code&gt;10&lt;/code&gt;. This kind of thing is usually not intended.&lt;/p&gt;
&lt;/details&gt;
&lt;h3 id=&#34;bonus-exercise&#34;&gt;Bonus exercise&lt;/h3&gt;
&lt;p&gt;You can use the &lt;a href=&#34;https://rdrr.io/r/base/paste.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;paste0()&lt;/code&gt;&lt;/a&gt; function to combine strings of text, for instance:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;carrier&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;UA&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flight&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1545&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/paste.html&#39;&gt;paste0&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;The full flight number is: &#34;&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;carrier&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;flight&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;The full flight number is: UA1545&#34;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Use &lt;a href=&#34;https://rdrr.io/r/base/paste.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;paste0()&lt;/code&gt;&lt;/a&gt; inside &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; to create a new column &lt;code&gt;flight_no&lt;/code&gt; which has the full flight number (carrier followed by flight, like above) for each flight.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carrier&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;flight&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;flight_no &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/paste.html&#39;&gt;paste0&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carrier&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;flight&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    carrier flight flight_no&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; UA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;545 UA1545   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; UA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;714 UA1714   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; AA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;141 AA1141   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; B6         725 B6725    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; DL         461 DL461    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; UA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;696 UA1696   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; B6         507 B6507    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; EV        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;708 EV5708   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; B6          79 B679     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; AA         301 AA301    &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;acknowledgements&#34;&gt;Acknowledgements&lt;/h2&gt;
&lt;p&gt;We used &lt;a href=&#34;https://jrnold.github.io/r4ds-exercise-solutions&#34;&gt;https://jrnold.github.io/r4ds-exercise-solutions&lt;/a&gt; to provide hints and solutions for the exercises.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>S04E10 and S04E11: R for Data Science - Chapters 5.3 and 5.4</title>
      <link>https://biodash.github.io/codeclub/s04e10-11_r4ds-ch5-4/</link>
      <pubDate>Thu, 13 Oct 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s04e10-11_r4ds-ch5-4/</guid>
      <description>&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Use this to download the R Markdown:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;rmd_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/scripts/Arrange%2C%20Select.Rmd&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rmd_file&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;arrange_select.Rmd&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Today we are going to finish off the material on the dplyr function &lt;a href=&#34;https://dplyr.tidyverse.org/reference/arrange.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;arrange()&lt;/code&gt;&lt;/a&gt; that we didn&amp;rsquo;t get to last week, and introduce a new dplyr function &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The way I am presenting this is through an RMarkdown document, to interactively explore the material in these two sections of Chapter 5, Data transformation&lt;/p&gt;
&lt;p&gt;Recall that for all dplyr data manipulation functions there is a common template:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;the first argument of the function is the input data frame&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;the next arguments say what you want to do with that data frame, using variable names (no quotes)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;the result is a new dataframe&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The fact that all these functions have a common template makes it possible to chain steps together, to make complex code chunks out of simple steps, one step at a time, as we will see below.&lt;/p&gt;
&lt;p&gt;We will again be using the &lt;code&gt;nycflights13&lt;/code&gt; and &lt;code&gt;tidyverse&lt;/code&gt; packages, so we first need make sure these packages are installed, and then load them for the current session by doing &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; commands:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/hadley/nycflights13&#39;&gt;nycflights13&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;arrange&#34;&gt;&lt;code&gt;arrange()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Refer to the biodash page to see where we left off:&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s04e09_r4ds-ch5-1/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;S04E08: R for Data Science - Chapter 5.1 - 5.3&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/arrange.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;arrange()&lt;/code&gt;&lt;/a&gt; is the equivalent of the Excel &lt;code&gt;sort&lt;/code&gt; command.&lt;/p&gt;
&lt;p&gt;So what happens if just &amp;lsquo;arrange&amp;rsquo; flights (the data frame) with no other arguments?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/arrange.html&#39;&gt;arrange&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 19&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     year month   day dep_time sched_de…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      517        515       2     830     819      11 UA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      533        529       4     850     830      20 UA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      542        540       2     923     850      33 AA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      544        545      -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;004    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;022     -&lt;span style=&#39;color: #BB0000;&#39;&gt;18&lt;/span&gt; B6     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      554        600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;6&lt;/span&gt;     812     837     -&lt;span style=&#39;color: #BB0000;&#39;&gt;25&lt;/span&gt; DL     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      554        558      -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;     740     728      12 UA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      555        600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;5&lt;/span&gt;     913     854      19 B6     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      557        600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;     709     723     -&lt;span style=&#39;color: #BB0000;&#39;&gt;14&lt;/span&gt; EV     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      557        600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;     838     846      -&lt;span style=&#39;color: #BB0000;&#39;&gt;8&lt;/span&gt; B6     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      558        600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;     753     745       8 AA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows, 9 more variables: flight &amp;lt;int&amp;gt;, tailnum &amp;lt;chr&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   origin &amp;lt;chr&amp;gt;, dest &amp;lt;chr&amp;gt;, air_time &amp;lt;dbl&amp;gt;, distance &amp;lt;dbl&amp;gt;, hour &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   minute &amp;lt;dbl&amp;gt;, time_hour &amp;lt;dttm&amp;gt;, and abbreviated variable names&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ¹​sched_dep_time, ²​dep_delay, ³​arr_time, ⁴​sched_arr_time, ⁵​arr_delay&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Nothing changes. This is identical to the original data frame:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 19&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    year month   day dep_time sched_dep…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      517         515       2     830     819      11 UA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      533         529       4     850     830      20 UA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      542         540       2     923     850      33 AA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      544         545      -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;004    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;022     -&lt;span style=&#39;color: #BB0000;&#39;&gt;18&lt;/span&gt; B6     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      554         600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;6&lt;/span&gt;     812     837     -&lt;span style=&#39;color: #BB0000;&#39;&gt;25&lt;/span&gt; DL     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      554         558      -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;     740     728      12 UA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 9 more variables: flight &amp;lt;int&amp;gt;, tailnum &amp;lt;chr&amp;gt;, origin &amp;lt;chr&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   dest &amp;lt;chr&amp;gt;, air_time &amp;lt;dbl&amp;gt;, distance &amp;lt;dbl&amp;gt;, hour &amp;lt;dbl&amp;gt;, minute &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   time_hour &amp;lt;dttm&amp;gt;, and abbreviated variable names ¹​sched_dep_time,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ²​dep_delay, ³​arr_time, ⁴​sched_arr_time, ⁵​arr_delay&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;But there a whole bunch of variables we can sort by. An easy way to see them is using the &lt;a href=&#34;https://pillar.r-lib.org/reference/glimpse.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;glimpse()&lt;/code&gt;&lt;/a&gt; function, which basically puts the &amp;lsquo;columns into rows&amp;rsquo;, so you can see them more easily, without scrolling off the screen. This is a great way to see just what the columns are in a complex data frame that you inherit from someone or other.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://pillar.r-lib.org/reference/glimpse.html&#39;&gt;glimpse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 336,776&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 19&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ month          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ day            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ dep_time       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 517, 533, 542, 544, 554, 554, 555, 557, 557, 558, 558, …&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sched_dep_time &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 515, 529, 540, 545, 600, 558, 600, 600, 600, 600, 600, …&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ dep_delay      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 2, 4, 2, -1, -6, -4, -5, -3, -3, -2, -2, -2, -2, -2, -1…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ arr_time       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 830, 850, 923, 1004, 812, 740, 913, 709, 838, 753, 849,…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sched_arr_time &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 819, 830, 850, 1022, 837, 728, 854, 723, 846, 745, 851,…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ arr_delay      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 11, 20, 33, -18, -25, 12, 19, -14, -8, 8, -2, -3, 7, -1…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ carrier        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;UA&#34;, &#34;UA&#34;, &#34;AA&#34;, &#34;B6&#34;, &#34;DL&#34;, &#34;UA&#34;, &#34;B6&#34;, &#34;EV&#34;, &#34;B6&#34;, &#34;…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ flight         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 1545, 1714, 1141, 725, 461, 1696, 507, 5708, 79, 301, 4…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ tailnum        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;N14228&#34;, &#34;N24211&#34;, &#34;N619AA&#34;, &#34;N804JB&#34;, &#34;N668DN&#34;, &#34;N394…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ origin         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;EWR&#34;, &#34;LGA&#34;, &#34;JFK&#34;, &#34;JFK&#34;, &#34;LGA&#34;, &#34;EWR&#34;, &#34;EWR&#34;, &#34;LGA&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ dest           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;IAH&#34;, &#34;IAH&#34;, &#34;MIA&#34;, &#34;BQN&#34;, &#34;ATL&#34;, &#34;ORD&#34;, &#34;FLL&#34;, &#34;IAD&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ air_time       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 227, 227, 160, 183, 116, 150, 158, 53, 140, 138, 149, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ distance       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 1400, 1416, 1089, 1576, 762, 719, 1065, 229, 944, 733, …&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ hour           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 5, 5, 5, 5, 6, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 6, 6…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ minute         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 15, 29, 40, 45, 0, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 59, 0…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ time_hour      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt; 2013-01-01 05:00:00, 2013-01-01 05:00:00, 2013-01-01 0…&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;(Notice there are 19 columns).&lt;/p&gt;
&lt;p&gt;Say we wanted to sort by month, and pull all the &amp;lsquo;Christmassy&amp;rsquo; flights to the top. We can arrange by month, &lt;em&gt;and&lt;/em&gt; sort descending:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/arrange.html&#39;&gt;arrange&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/desc.html&#39;&gt;desc&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;month&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 19&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     year month   day dep_time sched_de…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1       13       &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;359      14     446     445       1 B6     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1       17       &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;359      18     443     437       6 B6     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1      453        500      -&lt;span style=&#39;color: #BB0000;&#39;&gt;7&lt;/span&gt;     636     651     -&lt;span style=&#39;color: #BB0000;&#39;&gt;15&lt;/span&gt; US     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1      520        515       5     749     808     -&lt;span style=&#39;color: #BB0000;&#39;&gt;19&lt;/span&gt; UA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1      536        540      -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;     845     850      -&lt;span style=&#39;color: #BB0000;&#39;&gt;5&lt;/span&gt; AA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1      540        550     -&lt;span style=&#39;color: #BB0000;&#39;&gt;10&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;005    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;027     -&lt;span style=&#39;color: #BB0000;&#39;&gt;22&lt;/span&gt; B6     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1      541        545      -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;     734     755     -&lt;span style=&#39;color: #BB0000;&#39;&gt;21&lt;/span&gt; EV     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1      546        545       1     826     835      -&lt;span style=&#39;color: #BB0000;&#39;&gt;9&lt;/span&gt; UA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1      549        600     -&lt;span style=&#39;color: #BB0000;&#39;&gt;11&lt;/span&gt;     648     659     -&lt;span style=&#39;color: #BB0000;&#39;&gt;11&lt;/span&gt; US     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1      550        600     -&lt;span style=&#39;color: #BB0000;&#39;&gt;10&lt;/span&gt;     825     854     -&lt;span style=&#39;color: #BB0000;&#39;&gt;29&lt;/span&gt; B6     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows, 9 more variables: flight &amp;lt;int&amp;gt;, tailnum &amp;lt;chr&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   origin &amp;lt;chr&amp;gt;, dest &amp;lt;chr&amp;gt;, air_time &amp;lt;dbl&amp;gt;, distance &amp;lt;dbl&amp;gt;, hour &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   minute &amp;lt;dbl&amp;gt;, time_hour &amp;lt;dttm&amp;gt;, and abbreviated variable names&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ¹​sched_dep_time, ²​dep_delay, ³​arr_time, ⁴​sched_arr_time, ⁵​arr_delay&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And now say we want to just order the Christmas flights coming into Columbus. We can first &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; on &lt;code&gt;CMH&lt;/code&gt;, and then chain (pipe) that filter statement into arrange, using the &lt;strong&gt;pipe&lt;/strong&gt; notation.&lt;/p&gt;
&lt;p&gt;First filter on destination &lt;code&gt;CMH&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;CMH&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3,524 × 19&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     year month   day dep_time sched_de…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      805        815     -&lt;span style=&#39;color: #BB0000;&#39;&gt;10&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;006    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;010      -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;107       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;115      -&lt;span style=&#39;color: #BB0000;&#39;&gt;8&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;305    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;310      -&lt;span style=&#39;color: #BB0000;&#39;&gt;5&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;153       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;159      -&lt;span style=&#39;color: #BB0000;&#39;&gt;6&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;350    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;341       9 EV     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;257       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;300      -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;454    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;450       4 MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;458       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;500      -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;658    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;655       3 MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;459       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;501      -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;651    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;651       0 EV     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;522       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;530      -&lt;span style=&#39;color: #BB0000;&#39;&gt;8&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;731    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;725       6 MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;759       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;759       0    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;957    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;949       8 EV     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;816       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;805      11    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;955      18 MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;008       &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;015      -&lt;span style=&#39;color: #BB0000;&#39;&gt;7&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;206    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;210      -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 3,514 more rows, 9 more variables: flight &amp;lt;int&amp;gt;, tailnum &amp;lt;chr&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   origin &amp;lt;chr&amp;gt;, dest &amp;lt;chr&amp;gt;, air_time &amp;lt;dbl&amp;gt;, distance &amp;lt;dbl&amp;gt;, hour &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   minute &amp;lt;dbl&amp;gt;, time_hour &amp;lt;dttm&amp;gt;, and abbreviated variable names&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ¹​sched_dep_time, ²​dep_delay, ³​arr_time, ⁴​sched_arr_time, ⁵​arr_delay&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;(Notice we now have only 3,524 rows, as opposed to 336,776 in the full data frame).&lt;/p&gt;
&lt;p&gt;We can pass that output data frame on to &lt;a href=&#34;https://dplyr.tidyverse.org/reference/arrange.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;arrange()&lt;/code&gt;&lt;/a&gt; using the &amp;lsquo;pipe symbol&amp;rsquo; &lt;code&gt;%&amp;gt;%&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;CMH&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/arrange.html&#39;&gt;arrange&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/desc.html&#39;&gt;desc&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;month&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3,524 × 19&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     year month   day dep_time sched_de…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1      644        614      30     836     805      31 EV     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;129       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;135      -&lt;span style=&#39;color: #BB0000;&#39;&gt;6&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;316    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;330     -&lt;span style=&#39;color: #BB0000;&#39;&gt;14&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;253       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;259      -&lt;span style=&#39;color: #BB0000;&#39;&gt;6&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;435    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;454     -&lt;span style=&#39;color: #BB0000;&#39;&gt;19&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;328       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;326       2    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;507    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;524     -&lt;span style=&#39;color: #BB0000;&#39;&gt;17&lt;/span&gt; EV     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;513       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;515      -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;709    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;720     -&lt;span style=&#39;color: #BB0000;&#39;&gt;11&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;629       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;455      94    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;822    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;650      92 MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;728       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;730      -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;918    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;925      -&lt;span style=&#39;color: #BB0000;&#39;&gt;7&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;922       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;930      -&lt;span style=&#39;color: #BB0000;&#39;&gt;8&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;102    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;130     -&lt;span style=&#39;color: #BB0000;&#39;&gt;28&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     1     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;951       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;930      21    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;121    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;115       6 MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     2      622        610      12     759     801      -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt; EV     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 3,514 more rows, 9 more variables: flight &amp;lt;int&amp;gt;, tailnum &amp;lt;chr&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   origin &amp;lt;chr&amp;gt;, dest &amp;lt;chr&amp;gt;, air_time &amp;lt;dbl&amp;gt;, distance &amp;lt;dbl&amp;gt;, hour &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   minute &amp;lt;dbl&amp;gt;, time_hour &amp;lt;dttm&amp;gt;, and abbreviated variable names&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ¹​sched_dep_time, ²​dep_delay, ³​arr_time, ⁴​sched_arr_time, ⁵​arr_delay&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;So this is a first example of chaining together simple steps, to get a more complex result.&lt;/p&gt;
&lt;p&gt;Finally, with arrange, you can add other variables to &amp;lsquo;break ties&amp;rsquo;. In the following example, we first sort on &lt;code&gt;month&lt;/code&gt; (descending), and &lt;em&gt;then&lt;/em&gt; sort on &lt;code&gt;dep_delay&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;CMH&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/arrange.html&#39;&gt;arrange&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/desc.html&#39;&gt;desc&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;month&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3,524 × 19&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     year month   day dep_time sched_de…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     4     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;910       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;930     -&lt;span style=&#39;color: #BB0000;&#39;&gt;20&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;101    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;130     -&lt;span style=&#39;color: #BB0000;&#39;&gt;29&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12     7     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;243       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;259     -&lt;span style=&#39;color: #BB0000;&#39;&gt;16&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;434    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;454     -&lt;span style=&#39;color: #BB0000;&#39;&gt;20&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12    18     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;715       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;730     -&lt;span style=&#39;color: #BB0000;&#39;&gt;15&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;919    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;925      -&lt;span style=&#39;color: #BB0000;&#39;&gt;6&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12    26     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;918       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;930     -&lt;span style=&#39;color: #BB0000;&#39;&gt;12&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;116    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;130     -&lt;span style=&#39;color: #BB0000;&#39;&gt;14&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12    27     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;918       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;930     -&lt;span style=&#39;color: #BB0000;&#39;&gt;12&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;057    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;130     -&lt;span style=&#39;color: #BB0000;&#39;&gt;33&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12    10     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;504       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;515     -&lt;span style=&#39;color: #BB0000;&#39;&gt;11&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;731    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;720      11 MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12    12     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;719       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;730     -&lt;span style=&#39;color: #BB0000;&#39;&gt;11&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;937    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;925      12 MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12    16     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;919       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;930     -&lt;span style=&#39;color: #BB0000;&#39;&gt;11&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;108    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;130     -&lt;span style=&#39;color: #BB0000;&#39;&gt;22&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12    31     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;444       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;455     -&lt;span style=&#39;color: #BB0000;&#39;&gt;11&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;637    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;650     -&lt;span style=&#39;color: #BB0000;&#39;&gt;13&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013    12    12     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;125       &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;135     -&lt;span style=&#39;color: #BB0000;&#39;&gt;10&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;321    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;330      -&lt;span style=&#39;color: #BB0000;&#39;&gt;9&lt;/span&gt; MQ     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 3,514 more rows, 9 more variables: flight &amp;lt;int&amp;gt;, tailnum &amp;lt;chr&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   origin &amp;lt;chr&amp;gt;, dest &amp;lt;chr&amp;gt;, air_time &amp;lt;dbl&amp;gt;, distance &amp;lt;dbl&amp;gt;, hour &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   minute &amp;lt;dbl&amp;gt;, time_hour &amp;lt;dttm&amp;gt;, and abbreviated variable names&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ¹​sched_dep_time, ²​dep_delay, ³​arr_time, ⁴​sched_arr_time, ⁵​arr_delay&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;break-out-exercises&#34;&gt;Break out exercises:&lt;/h2&gt;
&lt;p&gt;Again, see here: &lt;a href=&#34;https://biodash.github.io/codeclub/s04e09_r4ds-ch5-1/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;S04E08: R for Data Science - Chapter 5.1 - 5.3&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;at the bottom of the page, under &lt;strong&gt;III &amp;ndash; Chapter 5.3: arrange()&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&#34;select&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;The previous data manipulation functions we&amp;rsquo;ve looked at, &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://dplyr.tidyverse.org/reference/arrange.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;arrange()&lt;/code&gt;&lt;/a&gt;, work on observations (i.e. rows).&lt;/p&gt;
&lt;p&gt;The next function we&amp;rsquo;ll look at, &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt;, works on directly on variables (i.e. columns).&lt;/p&gt;
&lt;p&gt;If you have hundreds of columns in a data frame (many of which you may not be interested in for the current analysis) you can &lt;strong&gt;subset&lt;/strong&gt; the columns. We saw above that &lt;code&gt;flights&lt;/code&gt; has 19 columns. This is a serious example in terms of rows (336,776), but pretty trivial in terms of columns. But it&amp;rsquo;s still a good toy example.&lt;/p&gt;
&lt;p&gt;It will be useful to import this example data frame into our local Environment so we can visualize it in RStudio (at the moment it is just &amp;lsquo;floating&amp;rsquo; out there in the system: we can access it, but we can&amp;rsquo;t see it).&lt;/p&gt;
&lt;p&gt;So after:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/hadley/nycflights13&#39;&gt;nycflights13&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We want to do:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;my_flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;(We&amp;rsquo;ve just created a personal &amp;lsquo;local object&amp;rsquo; data frame in our current session, pulling in data from the &lt;code&gt;nycflights13&lt;/code&gt; package). And it should appear in the Environment tab in RStudio.&lt;/p&gt;
&lt;p&gt;So, how can we focus on a subset of variables in the flights data frame? One way is to explicitly name the columns you want to &lt;strong&gt;keep&lt;/strong&gt; using the &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; function (remember, the first argument is the data frame; the following arguments are the column names):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;month&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;day&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     year month   day&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Often this is fine, but as you move on to larger data sets, you might want to use various &lt;em&gt;selection features&lt;/em&gt; instead of just explictly listing want you want to keep.&lt;/p&gt;
&lt;p&gt;These are listed if you do:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;o&#39;&gt;?&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;select&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;These use the same syntax and semantics as &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; for rows, using the same logical combinations.&lt;/p&gt;
&lt;h4 id=&#34;selection-features&#34;&gt;Selection features&lt;/h4&gt;
&lt;h5 id=&#34;-range&#34;&gt;&lt;code&gt;:&lt;/code&gt; &amp;lsquo;range&amp;rsquo;&lt;/h5&gt;
&lt;p&gt;You can select a &lt;strong&gt;range&lt;/strong&gt; of columns using the &lt;code&gt;:&lt;/code&gt; range operator. This is really only efficient if the original data frame is organized in a way that is useful for your purposes. The good news is that don&amp;rsquo;t have to select all varibles explicitly, one by one. The range operator selects &lt;em&gt;consecutive&lt;/em&gt; variables in the data frame.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;day&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     year month   day&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice that the &lt;code&gt;month&lt;/code&gt; variable is automatically included, even though it&amp;rsquo;s not mentioned in the select statement.&lt;/p&gt;
&lt;p&gt;But there is more organization in this data frame. Say we wanted to drill down just into the departure and arrival times:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 6&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dep_time sched_dep_time dep_delay arr_time sched_arr_time arr_delay&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;      517            515         2      830            819        11&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;      533            529         4      850            830        20&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;      542            540         2      923            850        33&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;      544            545        -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;004           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;022       -&lt;span style=&#39;color: #BB0000;&#39;&gt;18&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;      554            600        -&lt;span style=&#39;color: #BB0000;&#39;&gt;6&lt;/span&gt;      812            837       -&lt;span style=&#39;color: #BB0000;&#39;&gt;25&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;      554            558        -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;      740            728        12&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;      555            600        -&lt;span style=&#39;color: #BB0000;&#39;&gt;5&lt;/span&gt;      913            854        19&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;      557            600        -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;      709            723       -&lt;span style=&#39;color: #BB0000;&#39;&gt;14&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;      557            600        -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;      838            846        -&lt;span style=&#39;color: #BB0000;&#39;&gt;8&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;      558            600        -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;      753            745         8&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h5 id=&#34;-complement&#34;&gt;&lt;code&gt;!&lt;/code&gt; &amp;lsquo;complement&amp;rsquo;&lt;/h5&gt;
&lt;p&gt;You can also drop columns (and ranges of columns) using the logical &lt;code&gt;complement&lt;/code&gt; sign:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;day&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 16&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dep_t…¹ sched…² dep_d…³ arr_t…⁴ sched…⁵ arr_d…⁶ carrier flight tailnum origin&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;     517     515       2     830     819      11 UA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;545 N14228  EWR   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;     533     529       4     850     830      20 UA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;714 N24211  LGA   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;     542     540       2     923     850      33 AA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;141 N619AA  JFK   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;     544     545      -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;004    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;022     -&lt;span style=&#39;color: #BB0000;&#39;&gt;18&lt;/span&gt; B6         725 N804JB  JFK   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;     554     600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;6&lt;/span&gt;     812     837     -&lt;span style=&#39;color: #BB0000;&#39;&gt;25&lt;/span&gt; DL         461 N668DN  LGA   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;     554     558      -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;     740     728      12 UA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;696 N39463  EWR   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;     555     600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;5&lt;/span&gt;     913     854      19 B6         507 N516JB  EWR   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;     557     600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;     709     723     -&lt;span style=&#39;color: #BB0000;&#39;&gt;14&lt;/span&gt; EV        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;708 N829AS  LGA   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;     557     600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;     838     846      -&lt;span style=&#39;color: #BB0000;&#39;&gt;8&lt;/span&gt; B6          79 N593JB  JFK   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;     558     600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;     753     745       8 AA         301 N3ALAA  LGA   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows, 6 more variables: dest &amp;lt;chr&amp;gt;, air_time &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   distance &amp;lt;dbl&amp;gt;, hour &amp;lt;dbl&amp;gt;, minute &amp;lt;dbl&amp;gt;, time_hour &amp;lt;dttm&amp;gt;, and abbreviated&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   variable names ¹​dep_time, ²​sched_dep_time, ³​dep_delay, ⁴​arr_time,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ⁵​sched_arr_time, ⁶​arr_delay&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now we just have 16 columns, as opposed to the original 19.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Just a note&lt;/strong&gt;. In the text we are using, the syntax is:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;select&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;flights&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;year&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;day&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But based on this:&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;select.R&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I get the sense that &lt;code&gt;!&lt;/code&gt; is the current recommendation for taking the complement in &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; statements and that &lt;code&gt;-&lt;/code&gt; is deprecated. And FYI: documentation &lt;em&gt;always&lt;/em&gt; lags behind implementation.&lt;/p&gt;
&lt;p&gt;We can do exactly the same thing by explicitly listing the columns we want to drop, &lt;em&gt;but&lt;/em&gt;, there is a gotcha here.&lt;/p&gt;
&lt;p&gt;This (which was my first guess) does not work:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;select&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;flights&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;!&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;year&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;month&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;day&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Instead, we need to wrap the dropped columns in a &lt;a href=&#34;https://rdrr.io/r/base/c.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;c()&lt;/code&gt;&lt;/a&gt; vector:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;month&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;day&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 16&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dep_t…¹ sched…² dep_d…³ arr_t…⁴ sched…⁵ arr_d…⁶ carrier flight tailnum origin&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;     517     515       2     830     819      11 UA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;545 N14228  EWR   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;     533     529       4     850     830      20 UA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;714 N24211  LGA   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;     542     540       2     923     850      33 AA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;141 N619AA  JFK   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;     544     545      -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;004    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;022     -&lt;span style=&#39;color: #BB0000;&#39;&gt;18&lt;/span&gt; B6         725 N804JB  JFK   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;     554     600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;6&lt;/span&gt;     812     837     -&lt;span style=&#39;color: #BB0000;&#39;&gt;25&lt;/span&gt; DL         461 N668DN  LGA   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;     554     558      -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;     740     728      12 UA        &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;696 N39463  EWR   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;     555     600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;5&lt;/span&gt;     913     854      19 B6         507 N516JB  EWR   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;     557     600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;     709     723     -&lt;span style=&#39;color: #BB0000;&#39;&gt;14&lt;/span&gt; EV        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;708 N829AS  LGA   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;     557     600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;3&lt;/span&gt;     838     846      -&lt;span style=&#39;color: #BB0000;&#39;&gt;8&lt;/span&gt; B6          79 N593JB  JFK   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;     558     600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;2&lt;/span&gt;     753     745       8 AA         301 N3ALAA  LGA   &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows, 6 more variables: dest &amp;lt;chr&amp;gt;, air_time &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   distance &amp;lt;dbl&amp;gt;, hour &amp;lt;dbl&amp;gt;, minute &amp;lt;dbl&amp;gt;, time_hour &amp;lt;dttm&amp;gt;, and abbreviated&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   variable names ¹​dep_time, ²​sched_dep_time, ³​dep_delay, ⁴​arr_time,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ⁵​sched_arr_time, ⁶​arr_delay&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This is the syntax for &lt;em&gt;combining selections&lt;/em&gt; in the current dplyr package.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s check if it works on positive selections:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;month&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;day&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 3&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     year month   day&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Yep, all the same.&lt;/p&gt;
&lt;p&gt;So it seems it&amp;rsquo;s &lt;em&gt;optional&lt;/em&gt; for positive selections, but &lt;em&gt;necessary&lt;/em&gt; for negative selections.&lt;/p&gt;
&lt;h4 id=&#34;selection-helpers&#34;&gt;Selection helpers&lt;/h4&gt;
&lt;p&gt;There are other ways to select columns efficiently without explicitly naming them.&lt;/p&gt;
&lt;p&gt;Here are some examples of helpers which select variables by pattern-matching over the names. Note that the search term must be wrapped in quotes (since we are searching on text in the column name):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/starts_with.html&#39;&gt;ends_with&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;time&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 5&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dep_time sched_dep_time arr_time sched_arr_time air_time&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;      517            515      830            819      227&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;      533            529      850            830      227&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;      542            540      923            850      160&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;      544            545     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;004           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;022      183&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;      554            600      812            837      116&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;      554            558      740            728      150&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;      555            600      913            854      158&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;      557            600      709            723       53&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;      557            600      838            846      140&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;      558            600      753            745      138&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/starts_with.html&#39;&gt;starts_with&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;time&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 1&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    time_hour          &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;             &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can combine these two helpers (you can also think of them as &amp;lsquo;filters&amp;rsquo; or &amp;lsquo;constraints&amp;rsquo; to make contact with other programming languages) using logical operators. Here is an &amp;lsquo;OR&amp;rsquo; statement using the &lt;code&gt;|&lt;/code&gt; syntax. It means the selection returns &lt;em&gt;all&lt;/em&gt; selections that match &lt;em&gt;either&lt;/em&gt; columns that end with &amp;ldquo;time&amp;rdquo; or start with &amp;ldquo;time&amp;rdquo;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/starts_with.html&#39;&gt;ends_with&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;time&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/starts_with.html&#39;&gt;starts_with&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;time&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 6&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dep_time sched_dep_time arr_time sched_arr_time air_time time_hour          &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;             &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;      517            515      830            819      227 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;      533            529      850            830      227 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;      542            540      923            850      160 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;      544            545     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;004           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;022      183 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;      554            600      812            837      116 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;      554            558      740            728      150 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;      555            600      913            854      158 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;      557            600      709            723       53 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;      557            600      838            846      140 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;      558            600      753            745      138 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In this particular case there is a more compact way to get the same result, using the &lt;a href=&#34;https://tidyselect.r-lib.org/reference/starts_with.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;contains()&lt;/code&gt;&lt;/a&gt; helper. But this solution has lower resolution, since &amp;ldquo;time&amp;rdquo; could be anywhere in the column name.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyselect.r-lib.org/reference/starts_with.html&#39;&gt;contains&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;time&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 336,776 × 6&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dep_time sched_dep_time arr_time sched_arr_time air_time time_hour          &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;             &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;      517            515      830            819      227 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;      533            529      850            830      227 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;      542            540      923            850      160 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;      544            545     &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;004           &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;022      183 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;      554            600      812            837      116 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;      554            558      740            728      150 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;05:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;      555            600      913            854      158 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;      557            600      709            723       53 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;      557            600      838            846      140 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;      558            600      753            745      138 2013-01-01 &lt;span style=&#39;color: #555555;&#39;&gt;06:00:00&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 336,766 more rows&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;But you get the idea. The usefulness of these &amp;lsquo;selection helpers&amp;rsquo; depends on the column naming conventions you create (or most likely inherit) from a colleague or online.&lt;/p&gt;
&lt;h2 id=&#34;break-out-exercises-1&#34;&gt;Break out exercises:&lt;/h2&gt;
&lt;p&gt;See 5.4.1 in the text.&lt;/p&gt;
&lt;p&gt;But just state with these:&lt;/p&gt;
&lt;p&gt;Create a couple of select queries which pull out dep_time, dep_delay, arr_time, and arr_delay from flights, just using what we learned above.&lt;/p&gt;
&lt;p&gt;One should be explicit, and others (at least slightly!) more efficient.&lt;/p&gt;
&lt;p&gt;If you get through these with no issues, feel free to explore more of the execises in 5.4.1.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>S04E09: R for Data Science - Chapter 5.1 - 5.2</title>
      <link>https://biodash.github.io/codeclub/s04e09_r4ds-ch5-1/</link>
      <pubDate>Thu, 06 Oct 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s04e09_r4ds-ch5-1/</guid>
      <description>&lt;figure&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/dplyr_filter.jpeg width=&#34;70%&#34;&gt;
&lt;figcaption&gt;
Artwork by Allison Horst
&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;hr&gt;
&lt;h2 id=&#34;i----chapter-51-introduction&#34;&gt;I &amp;ndash; Chapter 5.1: Introduction&lt;/h2&gt;
&lt;h3 id=&#34;key-points&#34;&gt;Key points&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Function name conflicts: The function &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; in the &lt;em&gt;stats&lt;/em&gt; package (which is loaded by default in R) will be &amp;ldquo;masked&amp;rdquo; / &amp;ldquo;overwritten&amp;rdquo; by &lt;em&gt;dplyr&lt;/em&gt;&amp;rsquo;s &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; function when you load the &lt;em&gt;tidyverse&lt;/em&gt;. To still use a masked function (or a function from an installed-but-not-loaded package!), use the &amp;ldquo;full&amp;rdquo; notation, e.g. &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;stats::filter()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A &lt;em&gt;data frame&lt;/em&gt; is rectangular data structure (with rows and columns), while a &amp;ldquo;tibble&amp;rdquo; is a tidyverse-style data frame. Tibbles mainly differ from regular data frames in how they are printed to screen by default. See the two examples below: &lt;code&gt;cars&lt;/code&gt; is a regular data frame and &lt;code&gt;flights&lt;/code&gt; is a tibble.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The most common R data types are &lt;em&gt;integers&lt;/em&gt; (tibble abbreviation: &lt;code&gt;int&lt;/code&gt;), &lt;em&gt;doubles&lt;/em&gt; (&lt;code&gt;dbl&lt;/code&gt;), &lt;em&gt;character strings&lt;/em&gt; (&lt;code&gt;chr&lt;/code&gt;), &lt;em&gt;logicals&lt;/em&gt; (&lt;code&gt;lgl&lt;/code&gt;), and &lt;em&gt;factors&lt;/em&gt; (&lt;code&gt;fctr&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;em&gt;dplyr&lt;/em&gt; package is designed to work with dataframes: both the input and the output is a dataframe.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# &#39;mtcars&#39; is a regular dataframe&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;                    mpg cyl disp  hp drat    wt  qsec vs am gear carb&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;# &#39;flights&#39; is a tibble, which affects its printing behavior&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/hadley/nycflights13&#39;&gt;nycflights13&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 19&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;    year month   day dep_time sched_dep…¹ dep_d…² arr_t…³ sched…⁴ arr_d…⁵ carrier&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      517         515       2     830     819      11 UA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      533         529       4     850     830      20 UA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      542         540       2     923     850      33 AA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      544         545      -&lt;span style=&#39;color: #BB0000;&#39;&gt;1&lt;/span&gt;    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;004    &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;022     -&lt;span style=&#39;color: #BB0000;&#39;&gt;18&lt;/span&gt; B6     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      554         600      -&lt;span style=&#39;color: #BB0000;&#39;&gt;6&lt;/span&gt;     812     837     -&lt;span style=&#39;color: #BB0000;&#39;&gt;25&lt;/span&gt; DL     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;013     1     1      554         558      -&lt;span style=&#39;color: #BB0000;&#39;&gt;4&lt;/span&gt;     740     728      12 UA     &lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 9 more variables: flight &amp;lt;int&amp;gt;, tailnum &amp;lt;chr&amp;gt;, origin &amp;lt;chr&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   dest &amp;lt;chr&amp;gt;, air_time &amp;lt;dbl&amp;gt;, distance &amp;lt;dbl&amp;gt;, hour &amp;lt;dbl&amp;gt;, minute &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   time_hour &amp;lt;dttm&amp;gt;, and abbreviated variable names ¹​sched_dep_time,&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   ²​dep_delay, ³​arr_time, ⁴​sched_arr_time, ⁵​arr_delay&lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;ii----chapter-52-filter&#34;&gt;II &amp;ndash; Chapter 5.2: &lt;code&gt;filter()&lt;/code&gt;&lt;/h2&gt;
&lt;h3 id=&#34;key-points-1&#34;&gt;Key points&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; function removes rows (observations) from a dataframe based on certain conditions. You specify those conditions for one or more columns.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When you refer to a column, don&amp;rsquo;t quote its name! (e.g. in &lt;code&gt;filter(flights, month == 1)&lt;/code&gt;, where &lt;code&gt;month&lt;/code&gt; is the column name.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use &amp;ldquo;comparison operators&amp;rdquo; like &lt;code&gt;&amp;gt;&lt;/code&gt; (greater than) to specify conditions. Note that &lt;em&gt;two&lt;/em&gt; equals signs &lt;code&gt;==&lt;/code&gt; (and not a single, &lt;code&gt;=&lt;/code&gt;) signifies equality, and that &lt;code&gt;!=&lt;/code&gt; means &amp;ldquo;does not equal&amp;rdquo;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To combine multiple conditions, use logical (Boolean) operators: &lt;code&gt;&amp;amp;&lt;/code&gt; (and), &lt;code&gt;|&lt;/code&gt; (or), and &lt;code&gt;!&lt;/code&gt; (not). Separating conditions by a comma also means &amp;ldquo;and&amp;rdquo; in &lt;em&gt;dplyr&lt;/em&gt;, e.g. in &lt;code&gt;filter(flights, month == 1, day == 1)&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;code&gt;%in%&lt;/code&gt; operator tests if the value(s) on the left-hand side are contained in the values on the right hand side, e.g. &lt;code&gt;4 %in% 1:5&lt;/code&gt; asks whether 4 is contained in the sequence of numbers from 1 to 5, which will return &lt;code&gt;TRUE&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Missing values are denoted by &lt;code&gt;NA&lt;/code&gt;, and almost any operation with an &lt;code&gt;NA&lt;/code&gt; will return another &lt;code&gt;NA&lt;/code&gt;. To test if &lt;code&gt;x&lt;/code&gt; is or contains &lt;code&gt;NA&lt;/code&gt;s, don&amp;rsquo;t use &lt;code&gt;x == NA&lt;/code&gt; but &lt;code&gt;is.na(x)&lt;/code&gt;. When you filter based on a column, rows with &lt;code&gt;NA&lt;/code&gt;s in that column will by default be removed by &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;Find all flights that&amp;hellip;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Had an arrival delay of two or more hours&lt;/li&gt;
&lt;li&gt;Flew to Houston (&lt;code&gt;IAH&lt;/code&gt; or &lt;code&gt;HOU&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Were operated by United (&lt;code&gt;UA&lt;/code&gt;), American (&lt;code&gt;AA&lt;/code&gt;), or Delta (&lt;code&gt;DL&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Departed in summer (July, August, and September)&lt;/li&gt;
&lt;li&gt;Arrived more than two hours late, but didn&amp;rsquo;t leave late&lt;/li&gt;
&lt;li&gt;Were delayed by at least an hour, but made up over 30 minutes in flight&lt;/li&gt;
&lt;li&gt;Departed between midnight and 6am (inclusive)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Before you start, load the necessary packages:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/hadley/nycflights13&#39;&gt;nycflights13&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Delays are given in minutes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Times of day are numbered from &lt;code&gt;0001&lt;/code&gt; (1 minute past midnight) to &lt;code&gt;2400&lt;/code&gt; (midnight).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;&lt;em&gt;In the solutions below, I am piping the output to &lt;a href=&#34;https://rdrr.io/r/base/nrow.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;nrow()&lt;/code&gt;&lt;/a&gt;,&lt;/em&gt; &lt;em&gt;so you can check if you got the same number of rows.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;\1. Had an arrival delay (=&amp;gt; &lt;code&gt;arr_delay&lt;/code&gt;) of two or more hours (=&amp;gt; &lt;code&gt;&amp;gt;= 120&lt;/code&gt;):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       &lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;120&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 10200&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;\2. Flew to Houston (&lt;code&gt;IAH&lt;/code&gt; or &lt;code&gt;HOU&lt;/code&gt;) &amp;ndash; destination is the &lt;code&gt;dest&lt;/code&gt; column:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       &lt;span class=&#39;nv&#39;&gt;dest&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/match.html&#39;&gt;%in%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;IAH&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;HOU&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 9313&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;\3. Were operated by United (&lt;code&gt;UA&lt;/code&gt;), American (&lt;code&gt;AA&lt;/code&gt;), or Delta (&lt;code&gt;DL&lt;/code&gt;) &amp;mdash; this information is in the &lt;code&gt;carrier&lt;/code&gt; column:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       &lt;span class=&#39;nv&#39;&gt;carrier&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/match.html&#39;&gt;%in%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;UA&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;AA&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;DL&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 139504&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;\4. Departed in summer (July, August, and September) &amp;mdash; use the &lt;code&gt;month&lt;/code&gt; column:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       &lt;span class=&#39;nv&#39;&gt;month&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/match.html&#39;&gt;%in%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;9&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 86326&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This would also work:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       &lt;span class=&#39;nv&#39;&gt;month&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;month&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;9&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;\5. Arrived more than two hours late, but didn&amp;rsquo;t leave late &amp;mdash; use the &lt;code&gt;arr_delay&lt;/code&gt; (arrival delay) and &lt;code&gt;dep_delay&lt;/code&gt; (departure delay) columns:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       &lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;120&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 29&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;\6. Were delayed by at least an hour, but made up over 30 minutes in flight &amp;mdash; use the &lt;code&gt;dep_delay&lt;/code&gt; and &lt;code&gt;arr_delay&lt;/code&gt; columns, and note that &amp;ldquo;making up over 30 miniutes&amp;rdquo; implies that the arrival delay was more than 30 minutes smaller than the departure delay:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       &lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;60&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dep_delay&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;arr_delay&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;30&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1844&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;\7. Departed between midnight and 6am (inclusive) &amp;mdash; use the &lt;code&gt;dep_time&lt;/code&gt; column and note that &lt;code&gt;2400&lt;/code&gt; is midnight:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       &lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;600&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2400&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 9373&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;p&gt;How many flights have a missing &lt;code&gt;dep_time&lt;/code&gt;? What other variables are missing for these flights? What might these rows represent?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;ul&gt;
&lt;li&gt;A &amp;ldquo;missing&amp;rdquo; &lt;code&gt;dep_time&lt;/code&gt; means that this cell contains the value &lt;code&gt;NA&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Recall that you can test if something is &lt;code&gt;NA&lt;/code&gt; with the &lt;a href=&#34;https://rdrr.io/r/base/NA.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;is.na()&lt;/code&gt;&lt;/a&gt; function!&lt;/li&gt;
&lt;li&gt;To count the number of flights, you can look at the information printed along with the dataframe (&lt;code&gt;... with X more rows&lt;/code&gt;), or pipe (&lt;code&gt;%&amp;gt;%&lt;/code&gt;) the dataframe into the &lt;a href=&#34;https://rdrr.io/r/base/nrow.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;nrow()&lt;/code&gt;&lt;/a&gt; function, which counts the number of rows.&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;How many flights have a missing &lt;code&gt;dep_time&lt;/code&gt;?&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flights&lt;/span&gt;,&lt;/span&gt;
&lt;span&gt;       &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dep_time&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 8255&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;What other variables are missing for these flights?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;For example, arrival times.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;What might these rows represent?&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;These are cancelled flights.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>S04E08: R for Data Science - Chapters 4, 6, and 8</title>
      <link>https://biodash.github.io/codeclub/s04e08_r4ds-ch4-6-8/</link>
      <pubDate>Thu, 15 Sep 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s04e08_r4ds-ch4-6-8/</guid>
      <description>&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/r4ds_cover.png width=&#34;45%&#34;&gt;
&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;i----brief-code-club-introduction&#34;&gt;I &amp;ndash; Brief Code Club Introduction&lt;/h2&gt;
&lt;h3 id=&#34;organizers&#34;&gt;Organizers&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Michael Broe&lt;/em&gt; &amp;ndash; Evolution, Ecology and Organismal Biology (EEOB)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Jessica Cooperstone&lt;/em&gt; &amp;ndash; Horticulture &amp;amp; Crop Science (HCS) / Food Science &amp;amp; Technology (FST)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Stephen Opiyo&lt;/em&gt; &amp;ndash; Molecular &amp;amp; Cellular Imaging Center (MCIC) - Columbus&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Jelmer Poelstra&lt;/em&gt; &amp;ndash; Molecular &amp;amp; Cellular Imaging Center (MCIC) - Wooster&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Mike Sovic&lt;/em&gt; &amp;ndash; Infectious Diseases Institute AMSL - Genomics Lab&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;code-club-practicalities&#34;&gt;Code Club practicalities&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;In-person (Columbus &amp;amp; Wooster) and Zoom hybrid&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Mix of instruction/discussion with the entire group, and doing exercises in breakout groups of up to 4-5 people.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When doing &lt;strong&gt;exercises in breakout groups&lt;/strong&gt;, we encourage you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;To briefly introduce yourselves and to do the exercises as a group&lt;/li&gt;
&lt;li&gt;On Zoom, to turn your cameras on and to have someone share their screen (use the &lt;code&gt;Ask for help&lt;/code&gt; button in Zoom to get help from an organizer)&lt;/li&gt;
&lt;li&gt;To let a &lt;em&gt;less&lt;/em&gt; experienced person do the screen sharing and coding&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can &lt;strong&gt;ask a question&lt;/strong&gt; at any time, by speaking or typing in the Zoom chat.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can generally come early or stay late for &lt;strong&gt;troubleshooting&lt;/strong&gt; but also for questions related to your research.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some more notes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;We recommend that you &lt;strong&gt;read&lt;/strong&gt; the relevant (part of the) chapter before each session, especially if the material in the chapter is new to you.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We try to make each session &lt;strong&gt;as stand-alone as possible&lt;/strong&gt;. Still, if you missed one or more sessions, you would ideally catch up on reading those parts of the book, especially when we split a chapter across multiple sessions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We &lt;strong&gt;record&lt;/strong&gt; the whole-group parts of the Zoom call, and share the recordings only with Code Club participants.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;new-to-code-club-or-r&#34;&gt;New to Code Club or R?&lt;/h3&gt;
&lt;p&gt;Take a look at these pages on our website:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Computer setup for Code Club&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/&#34;&gt;Resources and tips to get started with R&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub-schedule/#previous-semesters&#34;&gt;List of all previous Code Club session topics&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;ii----the-r-for-data-science-book-r4ds&#34;&gt;II &amp;ndash; The R for Data Science book (R4DS)&lt;/h2&gt;
&lt;p&gt;This excellent book by Hadley Wickham (also author of many of the R packages used in the book!) and Garret Grolemund, has a freely available &lt;strong&gt;&lt;a href=&#34;https://r4ds.had.co.nz/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;online version&lt;/a&gt; that is regularly updated&lt;/strong&gt; and contains exercises. It was originally published in 2016.&lt;/p&gt;
&lt;p&gt;The book focuses on the so-called &lt;strong&gt;&amp;quot;&lt;em&gt;tidyverse&lt;/em&gt;&amp;quot; ecosystem&lt;/strong&gt; in R. The &lt;em&gt;tidyverse&lt;/em&gt; can be seen as a &lt;strong&gt;modern dialect of R&lt;/strong&gt;. In previous Code Clubs, we have often &amp;ndash;but not always!&amp;ndash; been doing things &amp;ldquo;the &lt;em&gt;tidyverse&lt;/em&gt; way&amp;rdquo; as well.&lt;/p&gt;
&lt;p&gt;For today&amp;rsquo;s chapters, The R4DS exercises I think are not so good, so I&amp;rsquo;ve replaced some and added some of my own.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;iii----r4ds-chapter-4&#34;&gt;III &amp;ndash; R4DS Chapter 4&lt;/h2&gt;
&lt;p&gt;In the first two R4DS exercises for this chapter, the message is that R does not handle typos so make sure you spell things correctly.&lt;/p&gt;
&lt;p&gt;Exercise 3: take a look at the RStudio keyboard shortcuts by clicking &lt;code&gt;Tools&lt;/code&gt; &amp;gt; &lt;code&gt;Keyboard Shortcut Help&lt;/code&gt;, or you can press &lt;kbd&gt;Alt&lt;/kbd&gt; + &lt;kbd&gt;Shift&lt;/kbd&gt; + &lt;kbd&gt;K&lt;/kbd&gt; on a PC.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;iv----r4ds-chapter-6&#34;&gt;IV &amp;ndash; R4DS Chapter 6&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Run the following code:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;cars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What went wrong?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;&lt;a href=&#34;https://pillar.r-lib.org/reference/glimpse.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;glimpse()&lt;/code&gt;&lt;/a&gt; is a function from the &lt;em&gt;dplyr&lt;/em&gt; package, one of the core &lt;em&gt;tidyverse&lt;/em&gt; packages that are loaded as part of the tidyverse.&lt;/p&gt;
&lt;p&gt;However, in every R session in which you want to use tidyverse function, you always need call &lt;a href=&#34;https://tidyverse.tidyverse.org&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library(tidyverse)&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now you can use &lt;a href=&#34;https://pillar.r-lib.org/reference/glimpse.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;glimpse()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://pillar.r-lib.org/reference/glimpse.html&#39;&gt;glimpse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;cars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 50&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 2&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ speed &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 4, 4, 7, 7, 8, 9, 10, 10, 10, 11, 11, 12, 12, 12, 12, 13, 13, 13…&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ dist  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 2, 10, 4, 22, 16, 10, 18, 26, 34, 17, 28, 14, 20, 24, 28, 26, 34…&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;Note, if you got an error like this when running &lt;a href=&#34;https://tidyverse.tidyverse.org&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library(tidyverse)&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error in library(tidyverse) : there is no package called ‘tidyverse’&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&amp;hellip;that means you still need to &lt;em&gt;install&lt;/em&gt; it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;iv----r4ds-chapter-8&#34;&gt;IV &amp;ndash; R4DS Chapter 8&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Create an RStudio Project for Code Club.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Run the code below in your new Project:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;carat&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;price&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;/span&gt;
&lt;span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_hex.html&#39;&gt;geom_hex&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggsave.html&#39;&gt;ggsave&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;diamonds.pdf&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;
&lt;span&gt;&lt;/span&gt;
&lt;span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/write_delim.html&#39;&gt;write_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;diamonds&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;diamonds.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;What does the code above do?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Find the files &lt;code&gt;diamonds.pdf&lt;/code&gt; and &lt;code&gt;diamonds.csv&lt;/code&gt; on your computer, without using a search function. How did you know where to look for them?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Where is the R working directory on your computer?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The code does the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Load the &lt;em&gt;tidyverse&lt;/em&gt; package&lt;/li&gt;
&lt;li&gt;Create a simple plot using the tidyverse &lt;code&gt;diamonds&lt;/code&gt; dataset&lt;/li&gt;
&lt;li&gt;Save the plot to disk as a PDF file&lt;/li&gt;
&lt;li&gt;Save the &lt;code&gt;diamonds&lt;/code&gt; dataframe to disk as a CSV file&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The files were saved in the same folder as your newly created RStudio project. (See also the next point.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Whenever you have an active RStudio Project, R&amp;rsquo;s working directory will be in the same folder as your RStudio project.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>S04E01: R for Data Science - Chapter 1</title>
      <link>https://biodash.github.io/codeclub/s04e01_r4ds-ch1/</link>
      <pubDate>Thu, 09 Jun 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s04e01_r4ds-ch1/</guid>
      <description>&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/r4ds_cover.png width=&#34;45%&#34;&gt;
&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;i----intro-to-this-season-of-code-club&#34;&gt;I &amp;ndash; Intro to this season of Code Club&lt;/h2&gt;
&lt;h3 id=&#34;organizers&#34;&gt;Organizers&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Michael Broe&lt;/em&gt; &amp;ndash; Evolution, Ecology and Organismal Biology (EEOB)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Jessica Cooperstone&lt;/em&gt; &amp;ndash; Horticulture &amp;amp; Crop Science (HCS) / Food Science &amp;amp; Technology (FST)&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Stephen Opiyo&lt;/em&gt; &amp;ndash; Molecular &amp;amp; Cellular Imaging Center (MCIC) - Columbus&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Jelmer Poelstra&lt;/em&gt; &amp;ndash; Molecular &amp;amp; Cellular Imaging Center (MCIC) - Wooster&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Mike Sovic&lt;/em&gt; &amp;ndash; Center for Applied Plant Sciences (CAPS)&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;code-club-practicalities&#34;&gt;Code Club practicalities&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;In-person (Columbus &amp;amp; Wooster) and Zoom hybrid&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Mix of instruction/discussion with the entire group, and doing exercises in breakout groups of up to 4-5 people.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When doing &lt;strong&gt;exercises in breakout groups&lt;/strong&gt;, we encourage you:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;To briefly introduce yourselves and to do the exercises as a group&lt;/li&gt;
&lt;li&gt;On Zoom, to turn your cameras on and to have someone share their screen (use the &lt;code&gt;Ask for help&lt;/code&gt; button in Zoom to get help from an organizer)&lt;/li&gt;
&lt;li&gt;To let a &lt;em&gt;less&lt;/em&gt; experienced person do the screen sharing and coding&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can &lt;strong&gt;ask a question&lt;/strong&gt; at any time, by speaking or typing in the Zoom chat.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can generally come early or stay late for &lt;strong&gt;troubleshooting&lt;/strong&gt; but also for questions related to your research.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;More general notes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;We recommend that you &lt;strong&gt;read&lt;/strong&gt; the relevant (part of the) chapter before each session, especially if the material in the chapter is new to you.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We try to make each session &lt;strong&gt;as stand-alone as possible&lt;/strong&gt;. Still, if you missed one or more sessions, you would ideally catch up on reading those parts of the book, especially when we split a chapter across multiple sessions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We &lt;strong&gt;record&lt;/strong&gt; the whole-group parts of the Zoom call, and share the recordings only with Code Club participants.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We&amp;rsquo;re always hoping for someone outside of the group of organizers to &lt;strong&gt;lead a session&lt;/strong&gt; &amp;ndash; this might be more feasible now that we&amp;rsquo;re going through a book?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;new-to-code-club-or-r&#34;&gt;New to Code Club or R?&lt;/h3&gt;
&lt;p&gt;Take a look at these pages on our website:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Computer setup for Code Club&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/&#34;&gt;Resources and tips to get started with R&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub-schedule/#previous-semesters&#34;&gt;List of all previous Code Club session topics&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;ii----the-r-for-data-science-book-r4ds&#34;&gt;II &amp;ndash; The R for Data Science book (R4DS)&lt;/h2&gt;
&lt;p&gt;This excellent book by Hadley Wickham (also author of many of the R packages used in the book!) and Garret Grolemund, has a freely available &lt;strong&gt;&lt;a href=&#34;https://r4ds.had.co.nz/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;online version&lt;/a&gt; that is regularly updated&lt;/strong&gt; and contains exercises. It was originally published in 2016.&lt;/p&gt;
&lt;p&gt;The book focuses on the so-called &lt;strong&gt;&amp;quot;&lt;em&gt;tidyverse&lt;/em&gt;&amp;quot; ecosystem&lt;/strong&gt; in R. The &lt;em&gt;tidyverse&lt;/em&gt; can be seen as a &lt;strong&gt;modern dialect of R&lt;/strong&gt;. Most of its functionality is also contained in &amp;ldquo;base R&amp;rdquo; (that which comes shipped with R by default), but it has an improved and more consistent programming interface or &amp;ldquo;syntax&amp;rdquo;. In previous Code Clubs, we have often &amp;ndash;but not always!&amp;ndash; been doing things &amp;ldquo;the &lt;em&gt;tidyverse&lt;/em&gt; way&amp;rdquo; as well.&lt;/p&gt;
&lt;p&gt;The book doesn&amp;rsquo;t technically assume any &lt;strong&gt;previous experience with R&lt;/strong&gt;, but if you&amp;rsquo;re completely new to R and to coding in any language, we would recommend you take a look at some introductory R material (&lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/&#34;&gt;see this page for some resources&lt;/a&gt;) before we start with Chapter 2 next week.&lt;/p&gt;
&lt;p&gt;We will &lt;em&gt;not&lt;/em&gt; be able to finish the book by the end of the summer. But if folks are liking the book, we may carry on with it during the fall semester.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;iii----r4ds-chapter-1-notes&#34;&gt;III &amp;ndash; R4DS Chapter 1 notes&lt;/h2&gt;
&lt;h3 id=&#34;11---what-you-will-learn&#34;&gt;1.1 - What you will learn&lt;/h3&gt;
&lt;p&gt;The data science process visualized:&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/data-science.png width=&#34;80%&#34;&gt;
&lt;/p&gt;
&lt;h4 id=&#34;what-is-tidy-data&#34;&gt;What is tidy data?&lt;/h4&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Brief explanation and examples&lt;/b&gt; (Click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;First, you can think of this along the lines of the colloquial meaning of the word: the data is well-organized.&lt;/p&gt;
&lt;p&gt;Additionally, computer-readability should be prioritized over human-readability (think: no color-coded cells, multiple header columns, or merged cells).&lt;/p&gt;
&lt;p&gt;But, most of all, &amp;ldquo;tidy&amp;rdquo; in the context of the &lt;em&gt;tidyverse&lt;/em&gt; refers to the following, as it is phrased in the book:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In brief, when your data is tidy, each column is a variable, and each row is an observation.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;But what does this mean? In practice, it often means having your data not in a &amp;ldquo;wide format&amp;rdquo; (all the information about each sample/individual in one row) but in a &amp;ldquo;&lt;strong&gt;long format&lt;/strong&gt;&amp;rdquo; (variables not spread across multiple columns) &amp;ndash; see the examples below.&lt;/p&gt;
&lt;p&gt;Example 1, not tidy:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;     name quiz1 quiz2 test1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1  Billy     C     D     C&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2   Suzy     F     A     A&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3 Lionel     B     C     B&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Example 1, tidy:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 9 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   name   assessment grade&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Billy  quiz1      C    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Billy  quiz2      D    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Billy  test1      C    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Lionel quiz1      B    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Lionel quiz2      C    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Lionel test1      B    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;7&lt;/span&gt; Suzy   quiz1      F    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;8&lt;/span&gt; Suzy   quiz2      A    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;9&lt;/span&gt; Suzy   test1      A&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Example 2, not tidy (in &lt;em&gt;matrix&lt;/em&gt; form):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt;         gene1 gene2 gene3 gene4 gene5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; sample1    48    53    42    50    52&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; sample2    39    43    37    64    47&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; sample3    45    55    51    58    52&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; sample4    42    40    41    64    49&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; sample5    48    49    54    49    43&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Example 2, tidy:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 25 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    sample  gene  count&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; sample1 gene1    48&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; sample1 gene2    53&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; sample1 gene3    42&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; sample1 gene4    50&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; sample1 gene5    52&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; sample2 gene1    39&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; sample2 gene2    43&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; sample2 gene3    37&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; sample2 gene4    64&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; sample2 gene5    47&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 15 more rows&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;em&gt;tidyverse&lt;/em&gt; is, as the name suggests, generally designed to work with data that is &amp;ldquo;tidy&amp;rdquo; as shown above. With &lt;em&gt;ggplot2&lt;/em&gt;, in particular, you&amp;rsquo;ll quickly run into difficulties when trying to make plots using wide-format dataframes.&lt;/p&gt;
&lt;p&gt;For more, the book has a separate chapter on &lt;a href=&#34;https://r4ds.had.co.nz/tidy-data.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;tidy data&lt;/a&gt;, and there is also &lt;a href=&#34;https://cran.r-project.org/web/packages/tidyr/vignettes/tidy-data.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;tidyr&lt;/em&gt; package explainer on tidy data&lt;/a&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;h3 id=&#34;13---what-you-wont-learn&#34;&gt;1.3 - What you won&amp;rsquo;t learn&lt;/h3&gt;
&lt;p&gt;Some perhaps unfamiliar terms from this section:&lt;/p&gt;
&lt;h4 id=&#34;131---processing-big-datahttpsr4dshadconzintroductionhtmlbig-data&#34;&gt;&lt;a href=&#34;https://r4ds.had.co.nz/introduction.html#big-data&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;1.3.1 - Processing big data&lt;/a&gt;&lt;/h4&gt;
&lt;blockquote&gt;
&lt;p&gt;Fortunately each problem is independent of the others (a setup that is sometimes called embarrassingly parallel), so you just need a system (like Hadoop or Spark) that allows you to send different datasets to different computers for processing.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;At OSU, and most other universities, we instead tend to make use of &amp;ldquo;&lt;strong&gt;supercomputers&lt;/strong&gt;&amp;rdquo; when we want to simultaneously run an analysis many times, and more broadly, if we have &amp;ldquo;big data&amp;rdquo;. Specifically, we have the &lt;a href=&#34;https://www.osc.edu/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&amp;ldquo;Ohio Supercomputer Center&amp;rdquo; (OSC)&lt;/a&gt; here.&lt;/p&gt;
&lt;h4 id=&#34;133---non-rectangular-datahttpsr4dshadconzintroductionhtmlnon-rectangular-data&#34;&gt;&lt;a href=&#34;https://r4ds.had.co.nz/introduction.html#non-rectangular-data&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;1.3.3 - Non-rectangular data&lt;/a&gt;&lt;/h4&gt;
&lt;p&gt;Rectangular data is basically data that can be effectively entered in a spreadsheet (and in R, we tend to put this in a so-called &amp;ldquo;dataframe&amp;rdquo; or &amp;ldquo;tibble&amp;rdquo;). &lt;strong&gt;The &lt;em&gt;tidyverse&lt;/em&gt; is highly dataframe-oriented&lt;/strong&gt;, so it makes sense that the book focuses on rectangular data.&lt;/p&gt;
&lt;br&gt;
&lt;h3 id=&#34;142---rstudio-interface&#34;&gt;1.4.2 - RStudio interface&lt;/h3&gt;
&lt;p&gt;R itself simply provides a &amp;ldquo;&lt;em&gt;console&lt;/em&gt;&amp;rdquo; (command-line interface) where you can type your commands. RStudio, on the other hand, allows you to see the R console side-by-side with your scripts, plots, and more.&lt;/p&gt;
&lt;p&gt;Once you have a running instance of RStudio, &lt;strong&gt;create a new R script&lt;/strong&gt; by clicking &lt;code&gt;File&lt;/code&gt; &amp;gt; &lt;code&gt;New File&lt;/code&gt; &amp;gt; &lt;code&gt;R Script&lt;/code&gt;. Now, you should see all 4 &amp;ldquo;panes&amp;rdquo; that the RStudio window is divided into:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Top-left&lt;/em&gt;: The &lt;strong&gt;Editor&lt;/strong&gt; for your scripts and other documents (&lt;em&gt;hidden when no file is open&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Bottom-left&lt;/em&gt;: The &lt;strong&gt;R Console&lt;/strong&gt; to interactively run your code (+ other tabs).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Top-right&lt;/em&gt;: Your &lt;strong&gt;Environment&lt;/strong&gt; with R objects you have created (+ other tabs).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Bottom-right&lt;/em&gt;: Tabs for &lt;strong&gt;Files&lt;/strong&gt;, &lt;strong&gt;Plots&lt;/strong&gt;, &lt;strong&gt;Help&lt;/strong&gt;, and others.&lt;/li&gt;
&lt;/ul&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/rstudio-layout-ed.png width=&#34;95%&#34;&gt;
&lt;/p&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;check-that-you-have-r-and-rstudio-working&#34;&gt;Check that you have R and RStudio working&lt;/h3&gt;
&lt;p&gt;Take a moment to &lt;em&gt;&lt;strong&gt;explore the RStudio interface&lt;/strong&gt;&lt;/em&gt;. Were you able to open a new file to get the Editor pane?&lt;/p&gt;
&lt;p&gt;Take a look at your &lt;em&gt;&lt;strong&gt;version of R&lt;/strong&gt;&lt;/em&gt;: this was printed in the console when you started RStudio (see the RStudio screenshot above).&lt;/p&gt;
&lt;p&gt;The current version of R is &lt;code&gt;4.2.0&lt;/code&gt;. If your version of R is below &lt;code&gt;4.0&lt;/code&gt;, it will be a good idea to update R. To do so, you can follow &lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/#updating-r&#34;&gt;these instructions&lt;/a&gt;. But it is better to start this process at the very end of this session or after it, since it may take a while.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h3 id=&#34;143--144---r-packages&#34;&gt;1.4.3 &amp;amp; 1.4.4 - R packages&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;An R package is a collection of functions, data, and documentation that extends the capabilities of base R.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So, you can think of packages as &amp;ldquo;add-ons&amp;rdquo; / &amp;ldquo;extensions&amp;rdquo; to base R.&lt;/p&gt;
&lt;h4 id=&#34;installation-versus-loading&#34;&gt;Installation versus loading&lt;/h4&gt;
&lt;p&gt;Packages have to be separately &lt;strong&gt;installed&lt;/strong&gt; (usually &lt;em&gt;from within R&lt;/em&gt;, using R code) and once you have done this, you don&amp;rsquo;t need to redo it unless:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You want a different version of the package&lt;/li&gt;
&lt;li&gt;You have switched to a different version of R&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Unlike installation, &lt;strong&gt;loading&lt;/strong&gt; a package is necessary again and again, in every R session that you want to use it.&lt;/p&gt;
&lt;h4 id=&#34;the-tidyverse&#34;&gt;The tidyverse&lt;/h4&gt;
&lt;p&gt;The &lt;em&gt;tidyverse&lt;/em&gt; is unusual in that it is a &lt;em&gt;collection&lt;/em&gt; of packages that can still be installed and loaded with a single command. The individual &lt;em&gt;tidyverse&lt;/em&gt; packages are the focus of several chapters in the book, for instance:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Package&lt;/th&gt;
&lt;th&gt;Functionality&lt;/th&gt;
&lt;th&gt;Main chapter&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;&lt;strong&gt;ggplot2&lt;/strong&gt;&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Creating plots&lt;/td&gt;
&lt;td&gt;Ch. 3&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;&lt;strong&gt;tidyr&lt;/strong&gt;&lt;/em&gt; &amp;amp; &lt;em&gt;&lt;strong&gt;dplyr&lt;/strong&gt;&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Manipulating dataframes&lt;/td&gt;
&lt;td&gt;Ch. 5 &amp;amp; 7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;&lt;strong&gt;readr&lt;/strong&gt;&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Reading in data&lt;/td&gt;
&lt;td&gt;Ch. 11&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;&lt;strong&gt;stringr&lt;/strong&gt;&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Working with &amp;ldquo;strings&amp;rdquo; (text)&lt;/td&gt;
&lt;td&gt;Ch. 14&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;&lt;strong&gt;forcats&lt;/strong&gt;&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Working with &amp;ldquo;factors&amp;rdquo; &lt;br&gt; (categorical variables)&lt;/td&gt;
&lt;td&gt;Ch. 15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;em&gt;&lt;strong&gt;purrr&lt;/strong&gt;&lt;/em&gt;&lt;/td&gt;
&lt;td&gt;Iteration with functions&lt;/td&gt;
&lt;td&gt;Ch. 21&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h4 id=&#34;data-packages&#34;&gt;Data packages&lt;/h4&gt;
&lt;p&gt;Additionally, the book uses a couple of &amp;ldquo;data packages&amp;rdquo; (packages that only contain data, and no functions): &lt;em&gt;nycflights13&lt;/em&gt;, &lt;em&gt;gapminder&lt;/em&gt;, and &lt;em&gt;Lahman&lt;/em&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;iv----breakout-rooms&#34;&gt;IV &amp;ndash; Breakout rooms&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;1-introduce-yourselves&#34;&gt;1. Introduce yourselves!&lt;/h3&gt;
&lt;p&gt;Please take a moment to introduce yourself to your breakout roommates. You may also want to mention:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Your level of experience with R (and perhaps other coding languages)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What you want to use R for, or what you are already using R for&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Why you think this book might be useful, if you have an idea already&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;2-installload-the-packages&#34;&gt;2. Install/load the packages&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;Usually, exercises can be done with your breakout group on one computer, but the following should be done individually, to check that everyone has R up and running.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Most of you should already have the &lt;em&gt;&lt;strong&gt;tidyverse&lt;/strong&gt;&lt;/em&gt; installed, so let&amp;rsquo;s start by trying to &lt;em&gt;load&lt;/em&gt; it. This is done with the &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; function. To check if you can load the &lt;em&gt;tidyverse&lt;/em&gt;, run the following and see if you get similar output as printed below:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/load_tidyverse.png width=&#34;90%&#34;&gt;
&lt;/p&gt;
&lt;p&gt;If instead, you got something like:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error in library(tidyverse) : there is no package called ‘tidyverse’&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&amp;hellip;that means you still need to install it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Note: the package name is &#34;quoted&#34; in the install.packages() function:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## ... but it is not (normally) in library():&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;Now, let&amp;rsquo;s also install the &lt;strong&gt;data packages&lt;/strong&gt; &amp;ndash; we can do that all at once:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;nycflights13&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;gapminder&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Lahman&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The previous installation commands should return a whole bunch of output, but if all went well, you should not see any errors. Instead, look for phrases like &lt;code&gt;* DONE (nycflights13)&lt;/code&gt;, which indicate successful installation of a package.&lt;/p&gt;
&lt;p&gt;You can also &lt;em&gt;load&lt;/em&gt; the data packages (we have to do that for each package individually):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/hadley/nycflights13&#39;&gt;nycflights13&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/jennybc/gapminder&#39;&gt;gapminder&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://CRAN.R-project.org/package=Lahman&#39;&gt;Lahman&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You won&amp;rsquo;t see any output when loading most packages, like the three above (but unlike the &lt;em&gt;tidyverse&lt;/em&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Bonus question:&lt;/strong&gt; What are these &amp;ldquo;conflicts&amp;rdquo; in the &lt;em&gt;tidyverse&lt;/em&gt; startup messages referring to?&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;3-bonus-questions-or-remarks-about-the-chapter&#34;&gt;3. Bonus: Questions or remarks about the chapter?&lt;/h3&gt;
&lt;p&gt;Discuss or ask about whatever you thought was interesting/confusing/etc about the chapter!&lt;/p&gt;
&lt;p&gt;If nothing else comes up, you could think about and discuss the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://r4ds.had.co.nz/introduction.html#python-julia-and-friends&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;1.3.2&lt;/a&gt;: &lt;em&gt;&lt;strong&gt;&amp;ldquo;Data science teams&amp;rdquo;&lt;/strong&gt;&lt;/em&gt; &amp;ndash; Are grad students in a lab &amp;ldquo;data science teams&amp;rdquo;, or are they talking about something else? Do you think this might say something about the expected primary audience for the book?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://r4ds.had.co.nz/introduction.html#hypothesis-confirmation&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;1.3.4&lt;/a&gt;: &amp;ldquo;&lt;strong&gt;Hypothesis generation&lt;/strong&gt;&amp;rdquo; vs. &amp;ldquo;&lt;strong&gt;hypothesis confirmation&lt;/strong&gt;&amp;rdquo; &amp;ndash; are you familiar with this distinction and do you use it in practice?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://r4ds.had.co.nz/introduction.html#python-julia-and-friends&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;1.3.2&lt;/a&gt;: Other languages commonly used for data analysis: &lt;strong&gt;Python&lt;/strong&gt; and &lt;strong&gt;Julia&lt;/strong&gt;. Are you familiar at all with these languages? Why did you want to learn R instead?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Session S03E12: Incorporating your own functions into loops</title>
      <link>https://biodash.github.io/codeclub/s03e12_functions_in_loops/</link>
      <pubDate>Tue, 19 Apr 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s03e12_functions_in_loops/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New To Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has some pointers that might be helpful if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Please open RStudio before Code Club to test things out &amp;ndash; if you run into issues, join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Learn how to incorporate your own functions into loops.&lt;/li&gt;
&lt;li&gt;Learn how to efficiently &lt;em&gt;save&lt;/em&gt; the outputs of your loop into a data structure.&lt;/li&gt;
&lt;li&gt;Learn how using a functional (like &lt;code&gt;purr::map&lt;/code&gt;) saves you a lot of housekeeping.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;Again we&amp;rsquo;ll be using &lt;a href=&#34;https://tibble.tidyverse.org/reference/tibble.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tibble()&lt;/code&gt;&lt;/a&gt; from the tidyverse package, so we need to load that first.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching packages&lt;/span&gt; ─────────────────────────────────────── tidyverse 1.3.1 ──&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2&lt;/span&gt; 3.3.5     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;purrr  &lt;/span&gt; 0.3.4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tibble &lt;/span&gt; 3.1.6     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr  &lt;/span&gt; 1.0.8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr  &lt;/span&gt; 1.2.0     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;stringr&lt;/span&gt; 1.4.0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;readr  &lt;/span&gt; 2.1.2     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;forcats&lt;/span&gt; 0.5.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt; masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::filter()&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;    masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::lag()&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We&amp;rsquo;ll also reuse the toy data frame from last Code Club:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tibble.tidyverse.org/reference/tibble.html&#39;&gt;tibble&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  a &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  b &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  c &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  d &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 10 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;          a        b      c      d&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;1.57&lt;/span&gt;    0.647    1.39   0.851&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  0.239   0.667   -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.108&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;1.74&lt;/span&gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.520&lt;/span&gt;  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.663&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.343&lt;/span&gt;  0.652&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.035&lt;/span&gt;&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;9&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;1.69&lt;/span&gt;    -&lt;span style=&#39;color: #BB0000;&#39;&gt;1.30&lt;/span&gt;  -&lt;span style=&#39;color: #BB0000;&#39;&gt;1.58&lt;/span&gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  1.27    0.357    0.158 -&lt;span style=&#39;color: #BB0000;&#39;&gt;1.92&lt;/span&gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;1.04&lt;/span&gt;    0.490    0.897  1.33 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.212&lt;/span&gt;  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.753&lt;/span&gt;   -&lt;span style=&#39;color: #BB0000;&#39;&gt;1.68&lt;/span&gt;  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.503&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;  1.91    0.275    0.646  0.139&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.535&lt;/span&gt;  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.006&lt;/span&gt;&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;32&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;1.02&lt;/span&gt;  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.467&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  0.223  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.422&lt;/span&gt;    0.616 -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.553&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And we&amp;rsquo;ll also be re-using our own &lt;code&gt;normalize&lt;/code&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;normalize&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Last time we saw how to use this function to simplify our code:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In previous Code Clubs we&amp;rsquo;ve seen how you can apply a built-in function like &lt;code&gt;mean&lt;/code&gt; to each column of a data frame using a &lt;code&gt;for&lt;/code&gt; loop, &lt;code&gt;lapply&lt;/code&gt;, or &lt;code&gt;map&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We can use exactly the same techniques with our own functions.&lt;/p&gt;
&lt;p&gt;But I think it&amp;rsquo;s worth taking advantage of this time to revisit a couple of details (some of which were in the Bonus Material in &lt;a href=&#34;https://biodash.github.io/codeclub/s03e08_loops/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;S03E08&lt;/a&gt;).&lt;/p&gt;
&lt;h2 id=&#34;accessing-by-value-vsindex&#34;&gt;Accessing by value vs. index&lt;/h2&gt;
&lt;p&gt;In our first session on loops, we saw an example like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;11&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;12&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;13&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# We iterate over 10, 11, 12, 13&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -10&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -11&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -12&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -13&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here we are looping over the actual values in the vector. But we can also access the values &lt;em&gt;by their index&lt;/em&gt;. Here we loop over an index, and include that index in the body of the loop. It is very common in this usage to use the name &lt;code&gt;i&lt;/code&gt; for the variable. This is most common when the vector/list/data frame already exists as an object:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;numbers&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;11&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;12&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;13&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# We create a vector&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;             &lt;span class=&#39;c&#39;&gt;# We iterate over the indexes 1, 2, 3, 4&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;numbers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;     &lt;span class=&#39;c&#39;&gt;# We access the value using the index notation `[ ]`&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -10&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -11&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -12&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -13&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note that here we &amp;lsquo;hard-coded&amp;rsquo; the length of the vector inside the loop. We can generalize this so it will work on vectors of &lt;em&gt;any length&lt;/em&gt; by using this syntax:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;numbers&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;11&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;12&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;13&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;numbers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;numbers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# We iterate over 1, 2, 3,...&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;numbers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -10&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -11&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -12&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -13&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;storing-loop-outputs&#34;&gt;Storing loop outputs&lt;/h2&gt;
&lt;p&gt;We have also seen that unless you issue a &lt;a href=&#34;https://rdrr.io/r/base/print.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;print()&lt;/code&gt;&lt;/a&gt; statement which runs on &lt;em&gt;every separate iteration of the loop&lt;/em&gt;, the output values simply &amp;lsquo;go away&amp;rsquo;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;11&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;12&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;13&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Similarly if we want to actually &lt;em&gt;save&lt;/em&gt; the output of the loop in a vector, we need to save an output value on &lt;em&gt;every separate iteration of the loop&lt;/em&gt;. And this means we have to build the output vector iteration-by-iteration. Here is a first guess how to do this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;outputs&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/vector.html&#39;&gt;vector&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;                    &lt;span class=&#39;c&#39;&gt;# We &#39;initialize&#39; an *empty vector* to hold the outputs&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;outputs&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; logical(0)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;11&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;12&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;13&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;outputs&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;outputs&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# Each time round the loop we *append* a new value to the existing vector&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;outputs&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -10 -11 -12 -13&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This looks fine, &lt;strong&gt;however&lt;/strong&gt;, there is a problem. The vector &amp;lsquo;grows&amp;rsquo; at each iteration, and this means that, as Jelmer pointed out in the bonus material on loops, &amp;lsquo;&lt;strong&gt;R has to create an entirely new object in each iteration of the loop&lt;/strong&gt;, because the object&amp;rsquo;s memory requirements keep increasing.&amp;rsquo;&lt;/p&gt;
&lt;p&gt;This is not an issue for the toy vector we are using here, but say you were using a loop to create a data frame, column by column, with thousands of rows, and hundreds of columns. On every iteration the entire data frame would have to be copied and extended, and copied and extended, and&amp;hellip;&lt;/p&gt;
&lt;p&gt;So how do we avoid that?&lt;/p&gt;
&lt;p&gt;The technique is to initialize a vector (or list, or data frame) of the appropriate size for the outputs, which &lt;strong&gt;preallocates&lt;/strong&gt; the memory required to store it. Then instead of &lt;em&gt;appending&lt;/em&gt; to it on each iteration, we &lt;em&gt;write into it&lt;/em&gt; on each iteration. The size of the output vector is already fixed, and modifying values like this is way more efficient. Again, the magic is is to use indexes.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;output_vector&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/vector.html&#39;&gt;vector&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;length &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;output_vector&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] FALSE FALSE FALSE FALSE&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;numbers&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;11&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;12&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;13&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt; 
  &lt;span class=&#39;nv&#39;&gt;output_vector&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;numbers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;output_vector&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -10 -11 -12 -13&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;breakout-rooms-storing-loop-outputs&#34;&gt;Breakout rooms, storing loop outputs&lt;/h2&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;R has a function &lt;code&gt;letters&lt;/code&gt; which returns a character vector:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;letters&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] &#34;a&#34; &#34;b&#34; &#34;c&#34; &#34;d&#34; &#34;e&#34; &#34;f&#34; &#34;g&#34; &#34;h&#34; &#34;i&#34; &#34;j&#34; &#34;k&#34; &#34;l&#34; &#34;m&#34; &#34;n&#34; &#34;o&#34; &#34;p&#34; &#34;q&#34; &#34;r&#34; &#34;s&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [20] &#34;t&#34; &#34;u&#34; &#34;v&#34; &#34;w&#34; &#34;x&#34; &#34;y&#34; &#34;z&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;(&lt;code&gt;letters&lt;/code&gt; is a bit like &lt;code&gt;iris&lt;/code&gt;: it&amp;rsquo;s a character vector which is &amp;lsquo;just there&amp;rsquo;, like &lt;code&gt;iris&lt;/code&gt; is a data frame which is &amp;lsquo;just there&amp;rsquo;).&lt;/p&gt;
&lt;p&gt;The tidyverse also has a function &lt;a href=&#34;https://stringr.tidyverse.org/reference/case.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str_to_upper()&lt;/code&gt;&lt;/a&gt; which converts the case of a character:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://stringr.tidyverse.org/reference/case.html&#39;&gt;str_to_upper&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;A&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Write a for loop that converts each element of a character vector to upper case, saving the output by writing the output of each iteration into an empty vector.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;What is `letters[1]`? &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;upper_case&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/vector.html&#39;&gt;vector&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;length &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;26&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;26&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;upper_case&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://stringr.tidyverse.org/reference/case.html&#39;&gt;str_to_upper&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;letters&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;h2 id=&#34;back-to-normalize&#34;&gt;Back to &lt;code&gt;normalize&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;This gives us the machinery to use our own function in a for loop.&lt;/p&gt;
&lt;p&gt;First, recall how we can access a column vector using the &lt;code&gt;[[ ]]&lt;/code&gt; syntax:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] -1.56695706  0.23880352 -0.52028396 -0.03587572  1.26976225 -1.03948139&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [7] -0.21172370  1.90549573 -0.53548764  0.22250909&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;So we can iteratively access each column in a for loop:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.0000000 0.5200245 0.3014218 0.4409221 0.8169209 0.1519029 0.3902813&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [8] 1.0000000 0.2970435 0.5153320&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.9915841 1.0000000 0.4352500 0.0000000 0.8684414 0.9250426 0.3970564&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [8] 0.8335988 0.7141351 0.5377301&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 1.0000000 0.5131949 0.4367290 0.1242323 0.5998479 0.8402709 0.0000000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [8] 0.7587425 0.2170914 0.7489915&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.85264136 0.05580354 0.79127366 0.10586772 0.00000000 1.00000000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [7] 0.43627787 0.63372198 0.44736338 0.42096304&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And again, we can generalize this to a data frame of of any length.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.0000000 0.5200245 0.3014218 0.4409221 0.8169209 0.1519029 0.3902813&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [8] 1.0000000 0.2970435 0.5153320&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.9915841 1.0000000 0.4352500 0.0000000 0.8684414 0.9250426 0.3970564&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [8] 0.8335988 0.7141351 0.5377301&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 1.0000000 0.5131949 0.4367290 0.1242323 0.5998479 0.8402709 0.0000000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [8] 0.7587425 0.2170914 0.7489915&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.85264136 0.05580354 0.79127366 0.10586772 0.00000000 1.00000000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [7] 0.43627787 0.63372198 0.44736338 0.42096304&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here again, we are just printing the output, not saving it to a new data frame.&lt;/p&gt;
&lt;p&gt;So, according to our strategy, we want to create an empty data frame to hold our results. We can use information from our original data frame to do this.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;empty_vec&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/vector.html&#39;&gt;vector&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;length &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# Empty vector with correct number of rows&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;df_norm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tibble.tidyverse.org/reference/tibble.html&#39;&gt;tibble&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;a &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;empty_vec&lt;/span&gt;, b &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;empty_vec&lt;/span&gt;, c &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;empty_vec&lt;/span&gt;, d &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;empty_vec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;df_norm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;df_norm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 10 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;        a     b     c      d&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; 0     0.992 1     0.853 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; 0.520 1     0.513 0.055&lt;span style=&#39;text-decoration: underline;&#39;&gt;8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; 0.301 0.435 0.437 0.791 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; 0.441 0     0.124 0.106 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; 0.817 0.868 0.600 0     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; 0.152 0.925 0.840 1     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; 0.390 0.397 0     0.436 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; 1     0.834 0.759 0.634 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; 0.297 0.714 0.217 0.447 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; 0.515 0.538 0.749 0.421&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;using-a-map-command&#34;&gt;Using a &lt;code&gt;map&lt;/code&gt; command.&lt;/h2&gt;
&lt;p&gt;It&amp;rsquo;s a pain to have to &lt;em&gt;manually&lt;/em&gt; set up the &amp;lsquo;container&amp;rsquo; that will house your results. Couldn&amp;rsquo;t the computer do that for us? Yes! All of this housekeeping, the for loop, the preallocation of data frame size, is done behind the scenes as part of the implementation of &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;map&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;map_norm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://purrr.tidyverse.org/reference/map.html&#39;&gt;map&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;map_norm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ a: num [1:10] 0 0.52 0.301 0.441 0.817 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ b: num [1:10] 0.992 1 0.435 0 0.868 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ c: num [1:10] 1 0.513 0.437 0.124 0.6 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ d: num [1:10] 0.8526 0.0558 0.7913 0.1059 0 ...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice that the output of &lt;code&gt;map&lt;/code&gt; (like &lt;code&gt;lapply&lt;/code&gt;) is a list. But we can easily convert it into a data frame:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;map_norm_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://purrr.tidyverse.org/reference/map.html&#39;&gt;map&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; 
  &lt;span class=&#39;nv&#39;&gt;as_tibble&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;map_norm_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; tibble [10 × 4] (S3: tbl_df/tbl/data.frame)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ a: num [1:10] 0 0.52 0.301 0.441 0.817 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ b: num [1:10] 0.992 1 0.435 0 0.868 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ c: num [1:10] 1 0.513 0.437 0.124 0.6 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ d: num [1:10] 0.8526 0.0558 0.7913 0.1059 0 ...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Session S03E11: Writing your own Functions</title>
      <link>https://biodash.github.io/codeclub/s03e11_functions/</link>
      <pubDate>Mon, 28 Mar 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s03e11_functions/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New To Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has some pointers that might be helpful if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Please open RStudio before Code Club to test things out &amp;ndash; if you run into issues, join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Learn the basic &lt;strong&gt;template&lt;/strong&gt; of a function in R.&lt;/li&gt;
&lt;li&gt;Learn another way to avoid repetition in your code by creating your own functions.&lt;/li&gt;
&lt;li&gt;Learn all the advantages of using functions instead of copied code blocks.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;We&amp;rsquo;ll be using &lt;a href=&#34;https://tibble.tidyverse.org/reference/tibble.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tibble()&lt;/code&gt;&lt;/a&gt; from the tidyverse package, so we need to load that first.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching packages&lt;/span&gt; ─────────────────────────────────────── tidyverse 1.3.1 ──&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2&lt;/span&gt; 3.3.5     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;purrr  &lt;/span&gt; 0.3.4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tibble &lt;/span&gt; 3.1.6     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr  &lt;/span&gt; 1.0.8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr  &lt;/span&gt; 1.2.0     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;stringr&lt;/span&gt; 1.4.0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;readr  &lt;/span&gt; 2.1.2     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;forcats&lt;/span&gt; 0.5.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt; masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::filter()&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;    masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::lag()&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;what-is-an-r-function&#34;&gt;What is an R function?&lt;/h2&gt;
&lt;p&gt;A good way to understand this is to translate knowledge you already have from math directly into R. &amp;lsquo;Once upon a time&amp;rsquo; you probably met something like this:&lt;/p&gt;
&lt;p&gt;$$y = 2x +3$$&lt;/p&gt;
&lt;p&gt;which relates an &lt;code&gt;expression&lt;/code&gt; involving $x$ (on the right hand side) to an equivalent value $y$.&lt;/p&gt;
&lt;p&gt;In mathematics, a function is just a &amp;lsquo;rule&amp;rsquo; that relates &lt;code&gt;inputs&lt;/code&gt; to &lt;code&gt;outputs&lt;/code&gt; (with certain constraints).&lt;/p&gt;
&lt;p&gt;Later you may have come across this formulation:&lt;/p&gt;
&lt;p&gt;$$f(x) = 2x +3$$&lt;/p&gt;
&lt;p&gt;Now the function has a name &lt;code&gt;f()&lt;/code&gt; (not a particularly good one, however).&lt;/p&gt;
&lt;p&gt;You probably recall that $x$ is called the &lt;code&gt;argument&lt;/code&gt; of the function. So how do we translate this into R?&lt;/p&gt;
&lt;p&gt;The crucial thing here is the R &lt;code&gt;function()&lt;/code&gt; operator:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;f&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We &lt;strong&gt;define&lt;/strong&gt; the function using this &lt;code&gt;function()&lt;/code&gt; operator, and also &lt;strong&gt;assign&lt;/strong&gt; the function to a name (here &lt;code&gt;f&lt;/code&gt;) using &amp;lt;-, just like assigning any other value to an object. This means that now &lt;code&gt;f&lt;/code&gt; is a function object: just like you create vector objects, or lists, or data frame objects, when you assign them to names. Notice too that in RStudio they appear in the Global Environment in a special &amp;lsquo;Functions&amp;rsquo; section, and clicking on them shows the code of the function. This means that if you have a large file with many functions defined, you don&amp;rsquo;t have to go back searching for the function definition in the code itself.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Terminology&lt;/strong&gt; (gotta have it!)&lt;/p&gt;
&lt;p&gt;&lt;code&gt;x&lt;/code&gt; here is also called the &lt;strong&gt;argument&lt;/strong&gt; to the function. In this case there is just one, there could be more.&lt;/p&gt;
&lt;p&gt;The expression inside the curly braces: $(2 * x) + 3$, is called the &lt;strong&gt;body&lt;/strong&gt; of the function.&lt;/p&gt;
&lt;p&gt;Here is the basic template of any function in R:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;name&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;arg1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;arg2...&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;o&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;body&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The arguments go inside (&amp;hellip;). The body is the block of code you want to reuse, and it&amp;rsquo;s contained in curly brackets {&amp;hellip;}.&lt;/p&gt;
&lt;p&gt;Giving good names to functions can be tricky. You to don&amp;rsquo;t want to be too explicit, and you don&amp;rsquo;t want to be too terse (&lt;code&gt;f()&lt;/code&gt; is too terse, btw). We&amp;rsquo;ll return to this below when we write fancier functions.&lt;/p&gt;
&lt;p&gt;But now we want to actually use the function to compute an output: this is termed &lt;strong&gt;calling&lt;/strong&gt; the function, by &lt;strong&gt;passing in&lt;/strong&gt; a specific value. That specific value gets &lt;strong&gt;assigned&lt;/strong&gt; to the argument inside the function.&lt;/p&gt;
&lt;p&gt;Here is a trivial example, assigning the value $1$ to the argument:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;f&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;So &lt;em&gt;after&lt;/em&gt; calling the function in this way &lt;code&gt;x&lt;/code&gt; is instantiated to &lt;code&gt;1&lt;/code&gt;, and what is really happening is:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;f&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;  &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;3&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Easy-peasy.&lt;/p&gt;
&lt;p&gt;But wait! if you simply call a function, its &lt;strong&gt;output&lt;/strong&gt; (which you are probably interested in) just goes away. If you want to save the output of the function, to be used later, you need to &lt;em&gt;assign the output to a variable&lt;/em&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;my_output&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;f&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;my_output&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This variable will now appear in the Values section of your Environment pane in RStudio, and can be reused in your subsequent code.&lt;/p&gt;
&lt;p&gt;But wait! remember R data-structures? What if we pass in a vector as the argument?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;f&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  5  7  9 11 13&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Woohoo! In R, the functions you write yourself are also automagically &amp;lsquo;vectorized&amp;rsquo;: vector in, vector out.&lt;/p&gt;
&lt;p&gt;But wait! how about a list???&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;f&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error in 2 * x: non-numeric argument to binary operator&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Whoops! Looks like R is vectorized over vectors :). If we want to process our new function over a list we&amp;rsquo;ll have to do something more fancy, like a for-loop. We&amp;rsquo;ll see how to incorporate our own functions into for-loops, building on previous sessions, next week.&lt;/p&gt;
&lt;h2 id=&#34;breakout-rooms-write-your-own-functions&#34;&gt;Breakout rooms, write your own functions&lt;/h2&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Write a function from scratch that computes the square of a single input. Give it a sensible name, and run it on some test input numbers to make sure it works.&lt;/p&gt;
&lt;p&gt;Make sure to look in the Functions pane of the RStudio Environment tab to check it is assigned correctly.&lt;/p&gt;
&lt;p&gt;Is your function vectorized? Run it on a simple vector argument to check.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;The relevant R exponentiation operator is `**`. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;square&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;**&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;square&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;square&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  1  4  9 16&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;The function in Exercise 1 has a single argument, the base, and raises it to the exponent 2.&lt;/p&gt;
&lt;p&gt;Write a function with two arguments, which includes both a base and exponent and try it out.&lt;/p&gt;
&lt;p&gt;Is your function vectorized? Run it on a simple base vector to check.&lt;/p&gt;
&lt;p&gt;Bonus: is it vectorized on both the base and the exponent?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;exponential&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;e&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;**&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;e&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;exponential&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1024&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;exponential&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]       1    1024   59049 1048576&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;exponential&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]   1   4  27 256&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;exponential&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  1  4  3 16&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;R does not have a built-in function for calculating the &lt;a href=&#34;https://en.m.wikipedia.org/wiki/Coefficient_of_variation&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;coefficient of variation&lt;/a&gt;, aka the &lt;strong&gt;RSD&lt;/strong&gt; (relative standard deviation). This is defined as &lt;em&gt;the ratio of the standard deviation to the mean&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Create a function that computes this, and test it on a couple of vectors.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;The relevant R built-in functions are &lt;code&gt;sd()&lt;/code&gt; and &lt;code&gt;mean()&lt;/code&gt;. The function should have one argument, which is assumed to be a vector. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;coefficient_of_variation&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;v&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/sd.html&#39;&gt;sd&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;v&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;/&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;v&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;coefficient_of_variation&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.5504819&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;coefficient_of_variation&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;15&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;175&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.4907454&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;why-write-functions-spoiler-alert-dry&#34;&gt;Why write functions? (Spoiler alert, DRY&amp;hellip;)&lt;/h2&gt;
&lt;h3 id=&#34;copying-your-code-is-not-good&#34;&gt;Copying your code is &lt;em&gt;not good&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;The first motivation for writing a function is when you find yourself cut-and-pasting code blocks with slight alterations each time.&lt;/p&gt;
&lt;p&gt;Say we have the following toy tidyverse data frame, where each column is a vector of 10 random numbers from a normal distribution, with &lt;code&gt;mean = 0&lt;/code&gt; and &lt;code&gt;sd = 1&lt;/code&gt; (the defaults for &lt;code&gt;rnorm&lt;/code&gt;):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tibble.tidyverse.org/reference/tibble.html&#39;&gt;tibble&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  a &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  b &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  c &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  d &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 10 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;          a       b       c      d&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;1.88&lt;/span&gt;    0.727  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.468&lt;/span&gt;   1.27 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;  0.039&lt;span style=&#39;text-decoration: underline;&#39;&gt;9&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.789&lt;/span&gt;  -&lt;span style=&#39;color: #BB0000;&#39;&gt;2.41&lt;/span&gt;    0.376&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.410&lt;/span&gt;   1.86    1.05   -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.618&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.266&lt;/span&gt;  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.204&lt;/span&gt;  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.715&lt;/span&gt;   0.279&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;  0.244  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.067&lt;/span&gt;&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;3&lt;/span&gt;  0.884  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.340&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;  0.064&lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;1.09&lt;/span&gt;    0.152  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.840&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;  0.749  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.494&lt;/span&gt;   0.681   0.341&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;1.35&lt;/span&gt;    0.208   0.077&lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;  2.15 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;1.17&lt;/span&gt;    0.088&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt; -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.829&lt;/span&gt;  -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.174&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;  0.733   1.05    0.808   0.190&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In previous Code Clubs we&amp;rsquo;ve seen how you can apply a built-in function like &lt;code&gt;mean&lt;/code&gt; to each column using a &lt;code&gt;for&lt;/code&gt; loop or &lt;code&gt;lapply&lt;/code&gt;. But say we wanted to do something a bit fancier that is not part of core R. For example, we can &lt;em&gt;normalize&lt;/em&gt; the values in a column so they range from 0 to 1 using the following code block:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.0000000 0.7297073 0.5582684 0.6132731 0.8073051 0.7390605 1.0000000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [8] 0.1988908 0.2699569 0.9939179&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This code is a literal translation of the mathematical formula for normalization:&lt;/p&gt;
&lt;p&gt;$$z_{i} = \frac{x_{i} - min(x)}{max(x)-min(x)}$$&lt;/p&gt;
&lt;p&gt;OK, so how can we do this for each column? Here is a first attempt:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 10 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;        a       b     c      d&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; 0      0.246  0.562 0.706 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; 0.730 -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.267&lt;/span&gt;  0     0.407 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; 0.558  0.630  1     0.074&lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; 0.613 -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.069&lt;/span&gt;&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;1&lt;/span&gt; 0.490 0.375 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; 0.807 -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.022&lt;/span&gt;&lt;span style=&#39;color: #BB0000; text-decoration: underline;&#39;&gt;8&lt;/span&gt; 0.952 0.168 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; 0.739 -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.370&lt;/span&gt;  0.741 0     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; 1     -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.167&lt;/span&gt;  0.894 0.396 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; 0.199  0.070&lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt; 0.719 1     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; 0.270  0.029&lt;span style=&#39;text-decoration: underline;&#39;&gt;9&lt;/span&gt; 0.458 0.223 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; 0.994  0.356  0.930 0.345&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This works, but it caused me mental anguish to type it out. Even with cut and paste! All those manual textual substitutions!! And manual data entry is prone to mistakes, especially repetitive tasks like this. And say you had 1,000 columns&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;And it didn&amp;rsquo;t work!!&lt;/strong&gt; Honestly, I swear that mistake was totally real: I didn&amp;rsquo;t notice it until I looked at the output. Can you spot the mistake?&lt;/p&gt;
&lt;p&gt;It turns out R has a &lt;code&gt;range&lt;/code&gt; function that returns the minimum and maximum of a vector, which somewhat simplifies the coding:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The result is a vector like &lt;code&gt;c(-1.2129504, 2.1011248)&lt;/code&gt; (it varies run to run, since the columns values are random) which we can then index, and so we only do the min/max computation once for each column, instead of three times, so we get the following block of code for each column:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Does this help?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Still pretty horrible, and arguably worse since we add a line for each column.&lt;/p&gt;
&lt;p&gt;How can we distill this into a function to avoid all that repetition?&lt;/p&gt;
&lt;h3 id=&#34;encapsulation-of-code-in-a-function&#34;&gt;Encapsulation of code in a function&lt;/h3&gt;
&lt;p&gt;The secret to function writing is abstracting the &lt;em&gt;constant&lt;/em&gt; from the &lt;em&gt;variable&lt;/em&gt;. (Using the &lt;code&gt;range&lt;/code&gt; function does throw into sharper relief what is constant and what is varying at least.) The constant part is the &lt;strong&gt;body&lt;/strong&gt; of the function: the template or boiler-plate you use over and over again. The variable parts are the &lt;strong&gt;arguments&lt;/strong&gt; of the function.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s what it looks like in this case:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;normalize&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Pretty cool, right? Here &lt;code&gt;normalize&lt;/code&gt; is the descriptive name we give the function.&lt;/p&gt;
&lt;p&gt;In the current case the argument of our function is a column vector pulled from the data frame. But we can potentially use this function on &lt;em&gt;any&lt;/em&gt; vector, so let&amp;rsquo;s not be too specific. The more generally you can write your function, the more useful it will be.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;test_vec&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;pi&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;8.657&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;80&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;test_vec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.000000000 0.051948052 0.001838866 0.073467532 1.000000000&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;A couple of things to note:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Including that extra line &lt;code&gt;rng &amp;lt;- range(x)&lt;/code&gt; is no longer a problem, since we just type it once. If you are typing things out over and over you might prefer brevity. &lt;em&gt;When you write a function, you should prefer clarity.&lt;/em&gt; It&amp;rsquo;s good practice to break the the function down into logical steps, and name them properly. It&amp;rsquo;s much easier for others to &amp;lsquo;read&amp;rsquo; your function, and much easier for you when you come back to it in a couple of years. This is the principle of making your code &amp;lsquo;self-annotated&amp;rsquo;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Functions should be simple, clear, and do &lt;em&gt;one thing well&lt;/em&gt;. You create programs by combining simple functions in a modular manner.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Our original horrible code can now be rewritten as:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Which is an improvement, but the real power comes from the fact that we can use our new function in &lt;code&gt;for&lt;/code&gt; loops and &lt;code&gt;apply&lt;/code&gt; statements. We&amp;rsquo;ll see how to do that next week.&lt;/p&gt;
&lt;p&gt;By writing our own functions, we&amp;rsquo;ve effectively extended what R can do. And this is all that packages are: libraries of new functions that extend the capabilities of base R. In fact, if there are functions you design for your particular subject area and find yourself using all the time, you can make your own package and load it, and all your favorite functions will be right there (but that&amp;rsquo;s for another day&amp;hellip;)&lt;/p&gt;
&lt;h3 id=&#34;exercise-4-functions-are-not-just-for-arithmetic&#34;&gt;Exercise 4: Functions are not just for arithmetic!&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;The &lt;a href=&#34;https://en.m.wikipedia.org/wiki/FASTQ_format&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;fastq&lt;/a&gt; file format for DNA sequencing uses a letter/punctuation code for the &lt;em&gt;quality of the base&lt;/em&gt; called at each position (the fourth line below) which is in one-to-one relationship to the bases in the second line:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@SIM:1:FCX:1:15:6329:1045 1:N:0:2
TCGCACTCAACGCCCTGCATATGACAAGACAGAATC
+
&amp;lt;&amp;gt;;##=&amp;gt;&amp;lt;9=AAAAAAAAAA9#:&amp;lt;#&amp;lt;;&amp;lt;&amp;lt;&amp;lt;????#=
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To translate a letter code into a numerical &lt;a href=&#34;https://en.m.wikipedia.org/wiki/Phred_quality_score&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;phred quality score&lt;/a&gt; we have to do two things: (i) translate the &lt;strong&gt;character&lt;/strong&gt; to an &lt;strong&gt;integer&lt;/strong&gt; using the &lt;a href=&#34;http://www.asciitable.com&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ASCII code&lt;/a&gt; look up table (ii) subtract 33 from that value (!). (High scores are good).&lt;/p&gt;
&lt;p&gt;For the first step, R has a built-in function that converts a character into an integer according to that table, for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/utf8Conversion.html&#39;&gt;utf8ToInt&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;!&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 33&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Write a function &lt;code&gt;phred_score()&lt;/code&gt; that computes the phred score for any character. Check that it returns 0 for &amp;ldquo;!&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Is this function vectorized? Apply your function to our example string:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;&amp;gt;;##=&amp;gt;&amp;lt;9=AAAAAAAAAA9#:&amp;lt;#&amp;lt;;&amp;lt;&amp;lt;&amp;lt;????#=&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;to convert it to a vector of phred quality scores.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt;Remember when you pass the value to this function it has to be an &lt;em&gt;R character string&lt;/em&gt;, which needs to be surrounded by quotes.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;phred_score&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;character&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/utf8Conversion.html&#39;&gt;utf8ToInt&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;character&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;33&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;phred_score&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;!&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;phred_score&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;&amp;lt;&amp;gt;;##=&amp;gt;&amp;lt;9=AAAAAAAAAA9#:&amp;lt;#&amp;lt;;&amp;lt;&amp;lt;&amp;lt;????#=&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 27 29 26  2  2 28 29 27 24 28 32 32 32 32 32 32 32 32 32 32 24  2 25 27  2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [26] 27 26 27 27 27 30 30 30 30  2 28&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note: &amp;ldquo;!&amp;rdquo; is the first &lt;strong&gt;printing character&lt;/strong&gt; in the ASCII table. The characters 0 through 32 were used historically to control the behavior of teleprinters: &amp;ldquo;the original ASCII specification included 33 non-printing control codes which originated with Teletype machines; most of these are now obsolete&amp;rdquo;. If the ASCII table started with &amp;ldquo;!&amp;rdquo; instead of &lt;code&gt;NUL&lt;/code&gt; we wouldn&amp;rsquo;t need the correction of subtracting 33, and &amp;ldquo;!&amp;rdquo; would translate to 0. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Session S03E10: Functional Programming With purrr::map() Functions</title>
      <link>https://biodash.github.io/codeclub/s03e10_purrr/</link>
      <pubDate>Mon, 21 Mar 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s03e10_purrr/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;List and differentiate between some useful purrr functions.&lt;/li&gt;
&lt;li&gt;Compare purrr functions to the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; functions from last session.&lt;/li&gt;
&lt;li&gt;Use purrr functions as alternatives to loops.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;highlights-from-last-session&#34;&gt;Highlights From Last Session&lt;/h2&gt;
&lt;p&gt;In the previous session, we explored some functions from the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; family of functions, which provided alternatives to writing loops to iteratively apply some function to the elements of a data structure such as a vector, list, or data frame. Let&amp;rsquo;s start with a simple list with three entries&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;generate-an-example-list&#34;&gt;Generate An Example List&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;our_list&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;A &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, B &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;11&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;, C &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;21&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;30&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;our_list&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; $A&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  1  2  3  4  5  6  7  8  9 10&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $B&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 11 12 13 14 15 16 17 18 19 20&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $C&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 21 22 23 24 25 26 27 28 29 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We could use a loop to calculate the mean for each of the entries.&lt;/p&gt;
&lt;h3 id=&#34;calculate-mean-for-each-list-entry-with-a-loop&#34;&gt;Calculate Mean For Each List Entry With A Loop&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;results_loop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;results_loop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;results_loop&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 15.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[3]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 25.5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Like we saw last week, &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; gave us an alternative way to do the same thing, and with simpler and clearer code&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;calculate-mean-for-each-variable-with-lapply&#34;&gt;Calculate Mean For Each Variable With &lt;code&gt;lapply()&lt;/code&gt;&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;res_lapply&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/lapply.html&#39;&gt;lapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_list&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;res_lapply&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; $A&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $B&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 15.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $C&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 25.5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;I mentioned in the previous session that when working with the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; functions, it&amp;rsquo;s important to think about the structure/type of data going in to the function, and also that getting returned by the function. We saw that the &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; example above returned a list, and can confirm that with&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;res_lapply&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;list&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We also saw that &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sapply()&lt;/code&gt;&lt;/a&gt; was very similar to &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt;, but instead of a list being returned, the results were condensed down to a vector - specifically in this case, a numeric vector&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;res_sapply&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/lapply.html&#39;&gt;sapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_list&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;res_sapply&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;    A    B    C &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  5.5 15.5 25.5&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;res_sapply&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;numeric&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;map-functions-from-purrr&#34;&gt;&lt;code&gt;map()&lt;/code&gt; Functions From &lt;em&gt;purrr&lt;/em&gt;&lt;/h2&gt;
&lt;p&gt;In this session, we&amp;rsquo;re going to look at some of the &lt;code&gt;map()&lt;/code&gt; functions from the &lt;em&gt;purrr&lt;/em&gt; package, which is part of the &lt;em&gt;tidyverse&lt;/em&gt;. In some cases, these functions return the same results as their &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; analogues. As an example, compare the &lt;code&gt;map()&lt;/code&gt; function to &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt;&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;res_map&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_list&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;res_map&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; $A&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $B&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 15.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $C&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 25.5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;So why might you want to use the &lt;code&gt;map()&lt;/code&gt; functions? There are two primary reasons&amp;hellip;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The syntax/names of the &lt;code&gt;map()&lt;/code&gt; functions might be easier to understand and make for clearer code.&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;map()&lt;/code&gt; family provides additional functionality that might at best be cumbersome to achieve with the base R approaches. We won&amp;rsquo;t get to this in this session, but see the &lt;code&gt;imap()&lt;/code&gt; function for one example.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Ultimately, much of the value in using these &lt;code&gt;map()&lt;/code&gt; functions gets realized when you start writing your own custom functions, which is something we haven&amp;rsquo;t done yet, but will be doing soon. For now, we&amp;rsquo;ll work with some fairly basic examples just to get introduced to some of the syntax and usage of these functions. There&amp;rsquo;s a &lt;em&gt;purrr&lt;/em&gt; cheatsheet that you might find helpful available at &lt;a href=&#34;https://raw.githubusercontent.com/rstudio/cheatsheets/main/purrr.pdf&#34;&gt;https://raw.githubusercontent.com/rstudio/cheatsheets/main/purrr.pdf&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll start working with &lt;code&gt;map()&lt;/code&gt; in the first breakout session&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;breakout-exercises-1&#34;&gt;Breakout Exercises 1&lt;/h3&gt;
&lt;p&gt;Like with the first breakout exercise from last week, below I&amp;rsquo;m pulling out a subset of the numeric variables available in the &lt;em&gt;penguins&lt;/em&gt; data frame and reformating them into a list named &lt;em&gt;pens_list&lt;/em&gt; that we&amp;rsquo;ll use to practice with &lt;code&gt;map()&lt;/code&gt; functions.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select_if&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;is.numeric&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;as.list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ bill_length_mm   : num [1:344] 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ bill_depth_mm    : num [1:344] 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ flipper_length_mm: int [1:344] 181 186 195 NA 193 190 181 195 193 190 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ body_mass_g      : int [1:344] 3750 3800 3250 NA 3450 3650 3625 4675 3475 4250 ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Use &lt;code&gt;map()&lt;/code&gt; to calculate the mean value for each of the variables/entries in &lt;em&gt;pens_list&lt;/em&gt;. What type of results are returned (i.e. is it a list, vector, data frame, etc)?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Apply the &lt;a href=&#34;https://rdrr.io/r/base/mean.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mean()&lt;/code&gt;&lt;/a&gt; function with &lt;code&gt;map()&lt;/code&gt;. Remember there are NA&amp;rsquo;s in the data - see the help for &lt;a href=&#34;https://rdrr.io/r/base/mean.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mean()&lt;/code&gt;&lt;/a&gt; for dealing with those. You can view the result, or try &lt;a href=&#34;https://rdrr.io/r/base/class.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;class()&lt;/code&gt;&lt;/a&gt; to get the type of object returned.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;res_map&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;res_map&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; $bill_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 43.92193&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $bill_depth_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 17.15117&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $flipper_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 200.9152&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4201.754&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;res_map&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;list&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;As we saw last week, and in the example above, &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sapply()&lt;/code&gt;&lt;/a&gt; is similar to &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt;, but returns results as a vector instead of as a list. Take a look at the help for &lt;code&gt;map()&lt;/code&gt; and find a function that will return a vector of doubles (numerics) and apply it to the &lt;em&gt;pens_list&lt;/em&gt; object like you just did with &lt;code&gt;map()&lt;/code&gt;. Then find another function that will return the results as a data frame.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Try the &lt;code&gt;map_dbl()&lt;/code&gt; and &lt;code&gt;map_dfc()&lt;/code&gt; functions.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;map_vec&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map_dbl&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;map_vec&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;    bill_length_mm     bill_depth_mm flipper_length_mm       body_mass_g &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;          43.92193          17.15117         200.91520        4201.75439&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;map_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map_dfc&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;map_df&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 x 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;             &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt;           43.9          17.2              201.       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;&lt;span&gt;202.&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Remember that with &lt;code&gt;map()&lt;/code&gt;, the input is a single list or vector, and the function is applied to each element of the list of vector. A number of variants of the &lt;code&gt;map()&lt;/code&gt; function are available that define the type of output that gets returned.&lt;/p&gt;
&lt;h2 id=&#34;map2&#34;&gt;&lt;code&gt;map2()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;While &lt;code&gt;map()&lt;/code&gt; allowed us to apply some function to the elements of a single list or vector, &lt;code&gt;map2()&lt;/code&gt; lets us apply some operation to paired elements from two lists (or vectors).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;our_list1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;our_list1&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  1  2  3  4  5  6  7  8  9 10&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;our_list2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;11&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;our_list2&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 11 12 13 14 15 16 17 18 19 20&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here&amp;rsquo;s we&amp;rsquo;ll use &lt;code&gt;map2()&lt;/code&gt; to get the sums of corresponding pairs of elements from the two lists&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;map2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_list1&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;our_list2&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;.x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;.y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 12 14 16 18 20 22 24 26 28 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The tilde (~) in the third argument indicates a formula that will be converted to a function and applied. It&amp;rsquo;s actually kind of a short-hand way to write and apply a custom function, but since we haven&amp;rsquo;t gotten in to writing our own functions yet (though that&amp;rsquo;s coming soon!), for now, just remember that the function passed to &lt;code&gt;map2()&lt;/code&gt; has to take two arguments, which are defined as &amp;lsquo;.x&amp;rsquo; and &amp;lsquo;.y&amp;rsquo; (elements in corresponding positions of the first and second lists or vectors, respectively) in each iteration of the function.&lt;/p&gt;
&lt;h3 id=&#34;breakout-exercises-2&#34;&gt;Breakout Exercises 2&lt;/h3&gt;
&lt;p&gt;Below are two vectors containing bill-measurement data from the penguins data frame (bill length and bill depth).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Use &lt;code&gt;map2()&lt;/code&gt; to calculate the bill ratio for each penguin (length/depth). Output the result as a vector containing doubles (numerics), and save it as the object &lt;em&gt;bill_ratios&lt;/em&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Apply the &lt;code&gt;map2_dbl()&lt;/code&gt; function and use the third argument to define a formula that divides the length value by the width value.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_ratios&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map2_dbl&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;.x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;.y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;How many of the penguins in the dataset have bill ratios greater than 3?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Logicals in R can be interpreted as 1/0 (TRUE/FALSE). Try using &lt;a href=&#34;https://rdrr.io/r/base/sum.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sum()&lt;/code&gt;&lt;/a&gt; to sum over the results of a logical expression to get the number of ratios &amp;gt; 3. Alternatively, you could index &lt;em&gt;bill_ratios&lt;/em&gt; to retain just the values &amp;gt; 3, and then get the length of that vector. Remember that there are NA&amp;rsquo;s mixed in - how does this affect each of these two approaches?&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/sum.html&#39;&gt;sum&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_ratios&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 109&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# OR&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_ratios&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_ratios&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/na.fail.html&#39;&gt;na.omit&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 109&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;bonus&#34;&gt;Bonus&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Here&amp;rsquo;s one more dataset that&amp;rsquo;s based on the &lt;em&gt;penguins&lt;/em&gt; data (though much of it is made up). It represents measurements taken for each of three penguins over three years. &lt;em&gt;List1&lt;/em&gt; has data for year 1, &lt;em&gt;List2&lt;/em&gt; has data for year 2, and &lt;em&gt;List3&lt;/em&gt; has data for year 3.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;yr1_list&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Pen_1&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;39.1&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;18.7&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;flipper_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;181&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;body_mass_g&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3750&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             &lt;span class=&#39;s&#39;&gt;&#34;Pen_2&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;39.5&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;17.4&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;flipper_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;186&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;body_mass_g&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3800&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             &lt;span class=&#39;s&#39;&gt;&#34;Pen_3&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;40.3&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;18&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;flipper_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;195&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;body_mass_g&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3250&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;yr2_list&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Pen_1&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;39.8&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;18.9&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;flipper_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;184&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;body_mass_g&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3767&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             &lt;span class=&#39;s&#39;&gt;&#34;Pen_2&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;38.7&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;17.2&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;flipper_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;186&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;body_mass_g&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3745&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             &lt;span class=&#39;s&#39;&gt;&#34;Pen_3&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;40.7&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;18.6&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;flipper_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;217&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;body_mass_g&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3470&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;yr3_list&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Pen_1&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;40.2&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;19.3&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;flipper_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;188&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;body_mass_g&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3790&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             &lt;span class=&#39;s&#39;&gt;&#34;Pen_2&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;38.4&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;17.0&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;flipper_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;187&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;body_mass_g&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3710&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             &lt;span class=&#39;s&#39;&gt;&#34;Pen_3&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;40.9&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;18.9&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;flipper_length_mm&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;228&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;body_mass_g&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3493&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Try calculating the average value for each of the variables for each penguin over the three years. Output the results as a data frame. Note you&amp;rsquo;ll need an new &lt;code&gt;map()&lt;/code&gt; function that we haven&amp;rsquo;t used yet. Take a look at the help for &lt;code&gt;map2()&lt;/code&gt;, or the &lt;em&gt;purrr&lt;/em&gt; cheatsheet, to find a similar function that works on more than two lists (takes functions with 3 or more required arguments).&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;The &lt;code&gt;pmap()&lt;/code&gt; can be used here. It has some similarities to &lt;code&gt;map2()&lt;/code&gt;, but instead of applying to 2 lists, &lt;code&gt;pmap()&lt;/code&gt; works with 3 or more. Notice the names of the lists the function will be applied to are given as a single argument (a list). Provide a formula to calculate the mean. Unlike the &lt;code&gt;map2()&lt;/code&gt; function, which only works on functions that take 2 arguments (denoted &amp;lsquo;.x&amp;rsquo; and &amp;lsquo;.y&amp;rsquo;), the number of arguments passed to the function used in &lt;code&gt;pmap()&lt;/code&gt; can be three or more, and they are denoted &amp;lsquo;..1&amp;rsquo;, &amp;lsquo;..2&amp;rsquo;, &amp;lsquo;..3&amp;rsquo;, etc.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;pmap_dfr&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;yr1_list&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;yr2_list&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;yr3_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;..1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;..2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;..3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;/&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 x 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;             &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt;           39.7          19.0              184.       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;769 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt;           38.9          17.2              186.       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;752.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt;           40.6          18.5              213.       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;404.&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Session S03E09: Functional Programming With Apply() functions</title>
      <link>https://biodash.github.io/codeclub/s03e09_apply/</link>
      <pubDate>Tue, 08 Mar 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s03e09_apply/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Continue practicing with loops in R.&lt;/li&gt;
&lt;li&gt;Describe how the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; functions relate to loops in R.&lt;/li&gt;
&lt;li&gt;Use apply functions as alternatives to loops.&lt;/li&gt;
&lt;li&gt;Identify the input and output formats associated with different &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; functions.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;highlights-from-recent-sessions&#34;&gt;Highlights From Recent Sessions&lt;/h2&gt;
&lt;p&gt;In the past several sessions, we&amp;rsquo;ve talked about several things that have relevance to today&amp;rsquo;s discussion of the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; functions. Here&amp;rsquo;s a quick review&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;data-structures-and-indexing&#34;&gt;Data Structures And Indexing&lt;/h3&gt;
&lt;p&gt;There are several widely-used data structures in R. They include vectors, lists, and data frames. As Michael Broe showed in &lt;a href=&#34;https://biodash.github.io/codeclub/s03e06_datastructures/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;a recent session on data structures&lt;/a&gt;, each of these can be indexed, which means we can pull out one or more specific elements from those structures.&lt;/p&gt;
&lt;h3 id=&#34;vectors&#34;&gt;Vectors&lt;/h3&gt;
&lt;p&gt;Vectors have one dimension (can be characterized by their length), and all the elements of any vector in R have to be of the same class. They are often created with the &lt;a href=&#34;https://rdrr.io/r/base/c.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;c()&lt;/code&gt;&lt;/a&gt; (combine) function&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#Create some vectors&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;num_vector1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;num_vector1&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  1  2  3  4  5  6  7  8  9 10&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;num_vector1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;integer&#34;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;num_vector2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;num_vector2&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  1  2  6 10&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;num_vector2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;numeric&#34;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;log_vector&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;log_vector&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  TRUE FALSE  TRUE FALSE&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;log_vector&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;logical&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#Index a vector&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;num_vector2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 6&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;num_vector2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;log_vector&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;lists&#34;&gt;Lists&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#Create a list&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;my_list&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;num_vec1&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;num_vector1&lt;/span&gt;,
                &lt;span class=&#39;s&#39;&gt;&#34;num_vec2&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;num_vector2&lt;/span&gt;,
                &lt;span class=&#39;s&#39;&gt;&#34;log_vec&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#View the list&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;my_list&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; $num_vec1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  1  2  3  4  5  6  7  8  9 10&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $num_vec2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  1  2  6 10&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $log_vec&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  TRUE FALSE  TRUE FALSE&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#Try some indexing&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;my_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; $num_vec2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  1  2  6 10&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;my_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  1  2  6 10&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;my_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;num_vec2&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  1  2  6 10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;data-frames&#34;&gt;Data Frames&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#Create a data frame&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;num_vec&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;num_vector2&lt;/span&gt;,
                &lt;span class=&#39;s&#39;&gt;&#34;log_vec&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#View the data frame&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   num_vec log_vec&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1       1    TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2       2   FALSE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3       6    TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4      10   FALSE&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#OR&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/as.data.frame.html&#39;&gt;as.data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;my_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   num_vec2 log_vec&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1        1    TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2        2   FALSE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3        6    TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4       10   FALSE&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#Index the data frame&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   log_vec&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1    TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2   FALSE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3    TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4   FALSE&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  TRUE FALSE  TRUE FALSE&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;log_vec&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  TRUE FALSE  TRUE FALSE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;loops&#34;&gt;Loops&lt;/h3&gt;
&lt;p&gt;As Jelmer demonstrated in &lt;a href=&#34;https://biodash.github.io/codeclub/s03e08_loops/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;last week&amp;rsquo;s session&lt;/a&gt;, loops allow you to iteratively apply some task(s) to a series of inputs. In the simple loop below, we take each of the three values (1,3,6), print a statement with the original value, then negate the value and print another statement with the updated value&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/paste.html&#39;&gt;paste0&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Input value is &#34;&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/paste.html&#39;&gt;paste0&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Negated value is &#34;&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Input value is 1&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Negated value is -1&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Input value is 3&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Negated value is -3&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Input value is 6&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Negated value is -6&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;functions&#34;&gt;Functions&lt;/h3&gt;
&lt;p&gt;We use functions abundantly in R. Even the simple examples above used multiple functions, including &lt;a href=&#34;https://rdrr.io/r/base/c.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;c()&lt;/code&gt;&lt;/a&gt;, which combined items into a vector, &lt;a href=&#34;https://rdrr.io/r/base/class.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;class()&lt;/code&gt;&lt;/a&gt;, which returned the type, or class of an object, and &lt;a href=&#34;https://rdrr.io/r/base/paste.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;paste0()&lt;/code&gt;&lt;/a&gt;, which allowed us to stitch together character vectors and objects into a single expression. Functions typically accept (and often require) arguments - pieces of information that are provided inside the parentheses that may provide input for the function or details that modify its behavior. As a simple example, setting the na.rm argument in the &lt;a href=&#34;https://rdrr.io/r/base/mean.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mean()&lt;/code&gt;&lt;/a&gt; function provides a mean for all values in a vector after removing any that are NA. Otherwise, the mean is returned as &amp;ldquo;NA&amp;rdquo;&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;values&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;values&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  1  2  3  4  5 NA  7  8  9 10&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;values&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] NA&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;values&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5.444444&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;functionals&#34;&gt;Functionals&lt;/h2&gt;
&lt;p&gt;In contrast to traditional arguments like the &lt;em&gt;na.rm&lt;/em&gt; above, some functions accept other functions as arguments - these are sometimes called &lt;em&gt;functionals&lt;/em&gt;. In this session we&amp;rsquo;ll look at some of the functionals in the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; group. These provide alternatives to writing loops by allowing us to iteratively apply some function over structures like lists or data frames. They include&amp;hellip;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; - apply some function to the margins (rows or columns) of a rectangular object (i.e. matrix or data frame)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; - apply some function to each element of a list&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sapply()&lt;/code&gt;&lt;/a&gt; - similar to &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt;, but provides output in a different format&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/mapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mapply()&lt;/code&gt;&lt;/a&gt; - apply a function to multiple lists&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Key to understanding how and when to use each of these is thinking about the structure of the data going in and the structure of the results that get returned. We&amp;rsquo;ll start with &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;lapply&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; allows you to iteratively apply a function to items in a list, and by default, returns a list of results with the same number of entries as the input had. The only required arguments are the list the function will be applied to and the function itself. Keep in mind that these &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; functions are alternatives to loops. We&amp;rsquo;ll try calculating means with both the loop approach and the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; approach on the &lt;em&gt;simple_list&lt;/em&gt; example below&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;simple_list&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;,
                    &lt;span class=&#39;m&#39;&gt;11&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;15&lt;/span&gt;,
                    &lt;span class=&#39;m&#39;&gt;16&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;30&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;simple_list&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  1  2  3  4  5  6  7  8  9 10&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 11 12 13 14 15&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[3]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id=&#34;calculate-means-with-a-loop&#34;&gt;Calculate Means With A Loop&lt;/h4&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;num_entries&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;simple_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;results_list_loop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;num_entries&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;current_mean&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;simple_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;results_list_loop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;current_mean&lt;/span&gt;
  
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;results_list_loop&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 13&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[3]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 23&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id=&#34;calculate-means-with-lapply&#34;&gt;Calculate Means With &lt;code&gt;lapply()&lt;/code&gt;&lt;/h4&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;results_list_apply&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/lapply.html&#39;&gt;lapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;simple_list&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;results_list_apply&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 13&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[3]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 23&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice we can use a lot less code with &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; to get the same result as with the for loop.&lt;/p&gt;
&lt;p&gt;Give &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; a try in a Breakout Room&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;breakout-exercises-1&#34;&gt;Breakout Exercises 1&lt;/h3&gt;
&lt;p&gt;As we&amp;rsquo;ve talked about before, lists and data frames are closely related data structures in R - data frames are a special type of list in which all the entries are of the same size, and so they can be neatly organized into a rectangular row/column structure. When data fit that rectangular pattern, it&amp;rsquo;s easy to switch them between lists and data frames.&lt;/p&gt;
&lt;p&gt;The code below pulls out the columns of the penguins data frame that are numeric and reformats them into a list named &lt;em&gt;pens_list&lt;/em&gt;, which we&amp;rsquo;re previewing with the &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select_if&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;is.numeric&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;as.list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ bill_length_mm   : num [1:344] 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ bill_depth_mm    : num [1:344] 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ flipper_length_mm: int [1:344] 181 186 195 NA 193 190 181 195 193 190 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ body_mass_g      : int [1:344] 3750 3800 3250 NA 3450 3650 3625 4675 3475 4250 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ year             : int [1:344] 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Calculate the median value for each of the variables/entries in &lt;em&gt;pens_list&lt;/em&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; You can write a loop to do this, or, preferably, use &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt;. You&amp;rsquo;ll need one additional argument (na.rm) for the &lt;a href=&#34;https://rdrr.io/r/stats/median.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;median()&lt;/code&gt;&lt;/a&gt; function - see the &lt;a href=&#34;https://rdrr.io/r/base/mean.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mean()&lt;/code&gt;&lt;/a&gt; example above, or check the help for the &lt;a href=&#34;https://rdrr.io/r/stats/median.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;median()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; functions for more details.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# loop option&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;results_loop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;results_loop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/median.html&#39;&gt;median&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;results_loop&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 44.45&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 17.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[3]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 197&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[4]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4050&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[5]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2008&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#lapply option&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/lapply.html&#39;&gt;lapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;median&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; $bill_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 44.45&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $bill_depth_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 17.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $flipper_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 197&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4050&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $year&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2008&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;You might have noticed that one of the columns is &lt;em&gt;year&lt;/em&gt;. We don&amp;rsquo;t really need to get the median for that, so use &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; to calculate the medians again, but this time only do it for the first 4 columns..&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Index the list in the &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; function with square brackets to apply the function to just the first 4 entries.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;
&lt;span class=&#39;c&#39;&gt;#lapply option&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/lapply.html&#39;&gt;lapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;median&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; $bill_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 44.45&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $bill_depth_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 17.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $flipper_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 197&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4050&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Try the same code again, but this time run it with &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sapply()&lt;/code&gt;&lt;/a&gt; instead of &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt;. What&amp;rsquo;s the difference in these two functions?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Simply replace &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; from the previous exercise with &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sapply()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/lapply.html&#39;&gt;sapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pens_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;median&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;    bill_length_mm     bill_depth_mm flipper_length_mm       body_mass_g &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;             44.45             17.30            197.00           4050.00&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h3 id=&#34;apply&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; allowed us to apply a function to separate entries in a list. &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; does something similar, but applies the function to the margins (rows or columns) of objects with two dimensions like data frames or matrices.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s start with a simple matrix&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;simple_mat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/matrix.html&#39;&gt;matrix&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;15&lt;/span&gt;, nrow &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;simple_mat&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;      [,1] [,2] [,3] [,4] [,5]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1,]    1    4    7   10   13&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [2,]    2    5    8   11   14&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [3,]    3    6    9   12   15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now we&amp;rsquo;ll use &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; to get means for entries in &lt;em&gt;simple_mat&lt;/em&gt;. Like &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; requires that we provide arguments to define the object the function will be applied to and the function itself. But since with &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; the function can either be applied to the rows or columns, we need a third argument to specify which we want. This is done with either a &amp;lsquo;1&amp;rsquo; for rows or a &amp;lsquo;2&amp;rsquo; for columns&amp;hellip;&lt;/p&gt;
&lt;h4 id=&#34;get-the-mean-for-each-column&#34;&gt;Get The Mean For Each Column&lt;/h4&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/apply.html&#39;&gt;apply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;simple_mat&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  2  5  8 11 14&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id=&#34;get-the-mean-for-each-row&#34;&gt;Get The Mean For Each Row&lt;/h4&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/apply.html&#39;&gt;apply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;simple_mat&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 7 8 9&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;breakout-exercises-2&#34;&gt;Breakout Exercises 2&lt;/h3&gt;
&lt;p&gt;The code below will download a dataframe that contains average monthly temperature data for 282 US locations from 1981-2010, reformat it a bit to make it easier to work with, and store it as the object &lt;em&gt;temp_data&lt;/em&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;temp_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_csv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/data/temperature/city_temp_data_noaa.csv&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;unite&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Location&#34;&lt;/span&gt;,
        &lt;span class=&#39;nv&#39;&gt;City&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;State&lt;/span&gt;,
        sep &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34; &#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;column_to_rownames&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Location&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Preview &lt;em&gt;temp_data&lt;/em&gt;. How is it structured? What do the rows and columns represent?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;a href=&#34;https://rdrr.io/r/utils/head.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;head()&lt;/code&gt;&lt;/a&gt; or &lt;code&gt;glimpse()&lt;/code&gt; to preview the dataset.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;temp_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;                   JAN  FEB  MAR  APR  MAY  JUN  JUL  AUG  SEP  OCT  NOV  DEC&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; BIRMINGHAM AP AL 53.8 58.4 66.7 74.4 81.5 87.7 90.8 90.6 85.1 75.3 65.4 55.9&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; HUNTSVILLE AL    51.2 55.9 64.9 73.6 81.3 88.2 90.7 90.9 85.0 74.6 63.7 53.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; MOBILE AL        60.0 63.2 69.8 76.1 83.0 88.2 90.4 90.5 87.3 79.4 70.3 61.9&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; MONTGOMERY AL    57.4 61.8 69.7 76.6 84.0 89.8 92.1 91.9 87.3 78.3 69.0 59.6&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ANCHORAGE AK     23.1 26.6 33.9 44.5 56.0 62.8 65.4 63.5 55.1 40.5 27.8 24.8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ANNETTE AK       41.6 42.7 44.9 50.2 56.3 61.1 64.3 64.7 59.3 51.6 44.6 41.5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now calculate the mean temperature for each month. Based on the locations sampled, what month is the warmest overall? The coldest?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; to calculate the means for each column (columns are designated with &amp;lsquo;2&amp;rsquo;).&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/apply.html&#39;&gt;apply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;temp_data&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;      JAN      FEB      MAR      APR      MAY      JUN      JUL      AUG &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 44.35709 48.03156 55.75035 64.83936 73.33227 80.73582 84.88865 83.81418 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      SEP      OCT      NOV      DEC &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 77.35922 66.87234 55.59610 46.22589&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now calculate the mean temperature for each location. Which location has the warmest annual temperature? The coldest? Since there are a lot of results to sort through, consider using indexing to extract the warmest and coldest temperatures.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; to calculate the means for each row (rows are designated with &amp;lsquo;1&amp;rsquo;). Save the results to an object, and then use logical indexing in combination with the &lt;a href=&#34;https://rdrr.io/r/base/Extremes.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;max()&lt;/code&gt;&lt;/a&gt; function to pull out the entry with the maximum value or &lt;a href=&#34;https://rdrr.io/r/base/Extremes.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;min()&lt;/code&gt;&lt;/a&gt; to pull out the minimum value.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;row_means&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/apply.html&#39;&gt;apply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;temp_data&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;row_means&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;row_means&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;row_means&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; POHNPEI-CAROLINE IS. PC &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                  88.175&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;row_means&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;row_means&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;row_means&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; BARROW AK &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  17.18333&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;How many locations have a mean temp &amp;gt; 75F?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use indexing like in the previous exercise. You can print the results, or use the length function to get the number returned.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;row_means&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;row_means&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;75&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 68&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;bonus&#34;&gt;Bonus&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;How many states or territories have at least one city in the dataset with a mean temp &amp;gt; 75F?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; The states or territories are given by the last 2 characters in the row names of the data frame (which become the names of the vector elements in the results of &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt;). Extract the set of names, use a regular expression to pull out the last two characters from each (consider &lt;code&gt;stringr::str_rep&lt;/code&gt;, or &lt;a href=&#34;https://rdrr.io/r/base/grep.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;gsub()&lt;/code&gt;&lt;/a&gt;), then unique them to get each one that&amp;rsquo;s represented and find the length of that vector.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;loc_names&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;row_means&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;row_means&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;75&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/names.html&#39;&gt;names&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 
&lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;stringr&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://stringr.tidyverse.org/reference/str_replace.html&#39;&gt;str_replace&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;loc_names&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;(.+)(..)&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\2&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;unique_states&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;unique_states&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] &#34;AL&#34; &#34;AZ&#34; &#34;CA&#34; &#34;FL&#34; &#34;GA&#34; &#34;HI&#34; &#34;LA&#34; &#34;MS&#34; &#34;NV&#34; &#34;NM&#34; &#34;SC&#34; &#34;TX&#34; &#34;PC&#34; &#34;PR&#34;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;unique_states&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 14&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;purrr-an-alternative-tidy-approach-to-apply-functions&#34;&gt;Purrr: An Alternative (Tidy) Approach To &lt;code&gt;apply()&lt;/code&gt; Functions&lt;/h2&gt;
&lt;p&gt;There are &lt;em&gt;tidy&lt;/em&gt; alternatives to the apply functions - they&amp;rsquo;re part of the &lt;em&gt;purrr&lt;/em&gt; package, which we&amp;rsquo;ll explore in the next session. In the meantime, if you want a preview, you can find details on &lt;em&gt;purrr&lt;/em&gt; &lt;a href=&#34;https://purrr.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>S03E08: For Loops and If Statements</title>
      <link>https://biodash.github.io/codeclub/s03e08_loops/</link>
      <pubDate>Thu, 03 Mar 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s03e08_loops/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;housekeeping&#34;&gt;Housekeeping&lt;/h2&gt;
&lt;h4 id=&#34;new-to-code-club&#34;&gt;New to Code Club?&lt;/h4&gt;
&lt;p&gt;Check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;h4 id=&#34;session-goals&#34;&gt;Session goals&lt;/h4&gt;
&lt;p&gt;Today, you will learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The basics of &lt;code&gt;for&lt;/code&gt; loops.&lt;/li&gt;
&lt;li&gt;How to print and save output from &lt;code&gt;for&lt;/code&gt; loops&lt;/li&gt;
&lt;li&gt;How to use &lt;code&gt;if&lt;/code&gt; statements&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;r-packages-we-will-use&#34;&gt;R packages we will use&lt;/h4&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## This will _install_ the packages only if you don&#39;t already have them:&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidyverse/glue&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;glue&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## This will _load_ the packages:&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidyverse/glue&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;i----introduction&#34;&gt;I &amp;ndash; Introduction&lt;/h2&gt;
&lt;p&gt;Last week, we learned that we should avoid copy-pasting our code when we want to repeat operations.&lt;/p&gt;
&lt;p&gt;We also focused on one alternative approach: making use of R&amp;rsquo;s vectorization capabilities. When passed a vector, most functions will automatically be performed separately for all elements in the vector, and you don&amp;rsquo;t need to explicitly iterate over (e.g., loop over) these elements:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2.5&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4.1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3.6&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.45&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1.125 1.845 3.150 1.620&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;However, vectorization can only be applied to a specific set of problems. A more universal solution when you need to repeat operations is &lt;strong&gt;iteration&lt;/strong&gt;. The two main iteration approaches in R involve &lt;em&gt;loops&lt;/em&gt; and &lt;em&gt;functionals&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Today, we will focus on loops and over the next two weeks, Mike Sovic will teach us about functionals.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In R, &lt;em&gt;functionals&lt;/em&gt; like &lt;code&gt;apply&lt;/code&gt; and &lt;code&gt;map&lt;/code&gt; are often preferred over loops because they are more elegant and succinct than loops &amp;ndash; but this can also make them harder to understand.&lt;/p&gt;
&lt;p&gt;Loops are a good place to start learning to use iteration because:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;They make the iteration aspect explicit and are therefore more intuitive than functionals.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;They can easily accommodate longer blocks of code without the need to &lt;em&gt;also&lt;/em&gt; write your own function.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;They are a near-universal feature in programming languages and are a &lt;em&gt;very&lt;/em&gt; common sight in languages like Python and Bash, so they are good to familiarize yourself with.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Today, we will talk about the most common type of loop: the &lt;code&gt;for&lt;/code&gt; loop. (Other types of loops in R are &lt;code&gt;while&lt;/code&gt; loops and &lt;code&gt;repeat&lt;/code&gt; loops &amp;ndash; I honestly never use those.)&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;ii----for-loop-basics&#34;&gt;II &amp;ndash; &lt;code&gt;for&lt;/code&gt; loop basics&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;for&lt;/code&gt; loops iterate over a &lt;em&gt;collection&lt;/em&gt;, such as a vector, allowing you to &lt;strong&gt;perform one or more actions for each element in the collection,&lt;/strong&gt; &lt;strong&gt;one element at a time.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;The basic syntax is as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;for &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;item&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;collection&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;# ...code to do things for each element, one at a time...&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The simple example below will help to understand the syntax:&lt;/p&gt;
&lt;p&gt;(Note that this example is so simple that vectorization would have also worked; we&amp;rsquo;ll move on to more realistic loop examples in the next section.)&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## A loop to print negated values:&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;# We iterate over 1, 2, 3, 4&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;             &lt;span class=&#39;c&#39;&gt;# Multiply each number by -1&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;On the first line, we initialized the &lt;code&gt;for&lt;/code&gt; loop, telling it to &lt;strong&gt;assign each item in the vector to the variable &lt;code&gt;a_number&lt;/code&gt;,&lt;/strong&gt; &lt;strong&gt;one at a time&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The code &lt;em&gt;inside&lt;/em&gt; the loop (which is inside the &lt;code&gt;{}&lt;/code&gt; braces and is indented) &lt;em&gt;will run as many times as there are elements in the collection&lt;/em&gt;. Each time it runs, &lt;code&gt;a_number&lt;/code&gt; contains a single value from the vector.&lt;/p&gt;
&lt;p&gt;In other words, what you are instructing R to do is:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Iteration 1&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -1&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Iteration 2&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -2&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Iteration 3&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -3&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Iteration 4&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Just printing the same loop for reference:&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;# We iterate over 1, 2, 3, 4&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;             &lt;span class=&#39;c&#39;&gt;# Multiply each number by -1&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The name given to the variable that will contain one &lt;em&gt;item&lt;/em&gt; at a time, here &lt;code&gt;a_number&lt;/code&gt;, is an arbitrary choice, just like when you assign variables the regular way (&lt;code&gt;a_number &amp;lt;- 1&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The &lt;em&gt;collection&lt;/em&gt; is usually a vector or a list: one that already exists or which you create on the fly in the loop initialization line, like we did above with &lt;a href=&#34;https://rdrr.io/r/base/c.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;c(1, 2, 3, 4)&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;for&lt;/code&gt;, the parentheses &lt;code&gt;()&lt;/code&gt;, &lt;code&gt;in&lt;/code&gt;, and the curly braces &lt;code&gt;{}&lt;/code&gt; are all fixed elements of &lt;code&gt;for&lt;/code&gt; loops. Only the braces can be omitted in some cases, as we&amp;rsquo;ll see below.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;the-variable-in-the-loop&#34;&gt;The variable in the loop&lt;/h3&gt;
&lt;p&gt;As mentioned, the &lt;strong&gt;variable name&lt;/strong&gt; that we assign to is arbitrary: we could use anything, as long as we reference it with the same name inside the loop:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Example 1 with a different variable name: &#34;positive_number&#34;&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;positive_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;positive_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -4&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Example 2 with a different variable name: &#34;i&#34;&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note also that we actually don&amp;rsquo;t &lt;em&gt;have to&lt;/em&gt; use the variable we are looping over: we could also use a &lt;code&gt;for&lt;/code&gt; loop as a roundabout way to simply repeat something as many times as there are values in our collection:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Yes!&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;                     &lt;span class=&#39;c&#39;&gt;# Print &#34;Yes!&#34; in each of our four iterations &lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Yes!&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Yes!&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Yes!&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Yes!&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;printing-the-output&#34;&gt;Printing the output&lt;/h3&gt;
&lt;p&gt;In a loop, we need to explicitly use the &lt;a href=&#34;https://rdrr.io/r/base/print.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;print()&lt;/code&gt;&lt;/a&gt; function if we want to print something to screen &amp;ndash; nothing will be printed if we omit this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In practice, you might often want to store the result in a variable rather than just printing it to screen, and we&amp;rsquo;ll see how to do that in the next section.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;A note on syntax: the &lt;em&gt;curly braces&lt;/em&gt; are not strictly necessary for one-liners like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-i&#34;&gt;Breakout Rooms I&lt;/h2&gt;
&lt;h4 id=&#34;copy-and-run-this-code-to-get-set-up&#34;&gt;Copy and run this code to get set up!&lt;/h4&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## This will _install_ the packages only if you don&#39;t already have them:&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidyverse/glue&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;glue&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## This will _load_ the packages:&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidyverse/glue&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1-first-loops&#34;&gt;Exercise 1: First loops&lt;/h3&gt;
&lt;p&gt;Loop over the numbers 5 through 10; and inside the loop, simply print each number to screen.&lt;/p&gt;
&lt;p&gt;(Of course, feel free to look at the examples above for reference &amp;ndash; but &lt;em&gt;type out the loop&lt;/em&gt; to get the syntax under your fingers.)&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 6&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 7&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 9&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Loop over the first 8 penguin bill depth values (column &lt;code&gt;bill_depth_mm&lt;/code&gt; in the &lt;code&gt;penguins&lt;/code&gt; dataframe), and in each iteration of the loop, add &lt;code&gt;100&lt;/code&gt; to the focal bill depth. Print the results to screen.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints on extracting the bill depths&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;One way to extract the &lt;code&gt;bill_depth_mm&lt;/code&gt; column as a vector is using &lt;code&gt;penguins$bill_depth_mm&lt;/code&gt;. (Another is &lt;code&gt;penguins %&amp;gt;% pull(bill_depth_mm)&lt;/code&gt;.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;One way to take the first 8 values of a vector &lt;code&gt;my_vec&lt;/code&gt; is using &lt;code&gt;my_vec[1:8]&lt;/code&gt;. (Another is &lt;code&gt;my_vec %&amp;gt;% head(8)&lt;/code&gt;.)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_dep&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_dep&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 118.7&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 117.4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 118&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] NA&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 119.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 120.6&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 117.8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 119.6&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2-keeping-track-of-the-iteration-number&#34;&gt;Exercise 2: Keeping track of the iteration number&lt;/h3&gt;
&lt;p&gt;Create a vector with the first names of everyone in your breakout room group (e.g. &lt;code&gt;first_names &amp;lt;- c(&amp;quot;Phillida&amp;quot;, &amp;quot;Ethan&amp;quot;, &amp;quot;Tonci&amp;quot;)&lt;/code&gt;), and a second vector with everyone&amp;rsquo;s last names.&lt;/p&gt;
&lt;p&gt;Next, use a loop to print your breakout room&amp;rsquo;s equivalent of the following:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;The name of person 1 is Phillida Maas
The name of person 2 is Ethan Hope
The name of person 3 is Tonci Elwes
&lt;/code&gt;&lt;/pre&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint 1&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To get the numbers (&lt;code&gt;person 1&lt;/code&gt; etc) &lt;em&gt;and&lt;/em&gt; the corresponding first and last names, you&amp;rsquo;ll want to &lt;strong&gt;loop over a vector of numbers&lt;/strong&gt; (indices), in this case &lt;code&gt;1:3&lt;/code&gt;. You can then extract the corresponding names inside the loop by indexing with this number (as in &lt;code&gt;first_names[1]&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ideally, you will determine the number of names in your room with code instead of just counting them manually &amp;ndash; you can do so using the &lt;a href=&#34;https://rdrr.io/r/base/length.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;length()&lt;/code&gt;&lt;/a&gt; function. That way, you could use the exact same code if you had a different number of people in your group.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint 2: code with blanks&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Use the following code as a template, replacing the &lt;code&gt;...&lt;/code&gt; blanks:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;first_names&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Phillida&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Ethan&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Tonci&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;last_names&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Maas&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Hope&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Elwes&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;n_names&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# get the number of first or last names&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;first_name&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;last_name&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;string&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;The name of person &amp;#123;...&amp;#125; is &amp;#123;...&amp;#125; &amp;#123;...&amp;#125;&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;string&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;first_names&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Phillida&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Ethan&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Tonci&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;last_names&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Maas&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Hope&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Elwes&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;n_names&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;first_names&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# get the number of first or last names&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;index&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n_names&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;first_name&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;first_names&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;index&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;last_name&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;last_names&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;index&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;string&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;The name of person &amp;#123;index&amp;#125; is &amp;#123;first_name&amp;#125; &amp;#123;last_name&amp;#125;&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;string&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; The name of person 1 is Phillida Maas&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; The name of person 2 is Ethan Hope&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; The name of person 3 is Tonci Elwes&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;iii----plots-or-files-as-output&#34;&gt;III &amp;ndash; Plots or files as output&lt;/h2&gt;
&lt;p&gt;In the examples and exercises so far, we have simply printed some text output to screen. While this can be useful, in practice, you might often be interested in doing one of the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Printing a plot&lt;/em&gt; in each iteration of the loop&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Saving results or a plot &lt;em&gt;to file&lt;/em&gt; in each iteration of the loop&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Creating &lt;em&gt;a single R object&lt;/em&gt; (e.g. a dataframe) across the entire loop: in each iteration, you add one element (e.g. a row) to the object.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The latter scenario is especially verbose to do with a loop and moreover, the most intuitive way of doing that is unnecessarily slow (which is a key reason why loops in R have the &lt;em&gt;reputation&lt;/em&gt; of being slow). I explain the way to store all loop output in one object in the &lt;a href=&#34;https://biodash.github.io/#storing-loop-output-in-an-object/&#34;&gt;bonus materials below&lt;/a&gt; but when you need to do this, a functional approach is particularly worth considering &amp;ndash; we&amp;rsquo;ll learn how to do so in the next few weeks.&lt;/p&gt;
&lt;p&gt;Instead, let&amp;rsquo;s take a look at &lt;strong&gt;creating plots&lt;/strong&gt; and &lt;strong&gt;saving files&lt;/strong&gt; in loops. We&amp;rsquo;ll also take this opportunity to explicitly see how we &lt;em&gt;change a bit of code that does something once in order to use it in a loop.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Say that we want to make a scatterplot of bill lengths vs. bill depths in all penguin species in the &lt;code&gt;penguins&lt;/code&gt; dataframe. We&amp;rsquo;ll start with some code to make a scatterplot for one of the three species:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Select just the data for the focal species:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;one_penguin_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Gentoo&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Select only rows with Gentoo penguins&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;                         &lt;span class=&#39;c&#39;&gt;# Remove rows with NAs&lt;/span&gt;
  
&lt;span class=&#39;c&#39;&gt;## Create the plot:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_penguin_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Gentoo&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-15-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;How can we adapt this code to run it for all three penguin species with a loop?&lt;/p&gt;
&lt;p&gt;Since we will loop over the species, we&amp;rsquo;ll start by saving the species names in a vector:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;all_penguin_species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Next, we write the loop, looping over our vector of species names.&lt;/p&gt;
&lt;p&gt;The code inside the loop is going to be nearly identical to the code above, except that we use the variable &lt;code&gt;focal_species&lt;/code&gt; instead of the literal string &amp;ldquo;Gentoo&amp;rdquo; (that way, we make a plot for each species and not three plots for Gentoo Penguins):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;focal_species&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;all_penguin_species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## Select just the data for the focal species:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;one_penguin_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;focal_species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Using the `focal_species` variable&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## Create the plot:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_penguin_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;focal_species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;         &lt;span class=&#39;c&#39;&gt;# Using the `focal_species` variable&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## Print the plot:&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-17-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-17-2.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-17-3.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Note that the code above would be &lt;em&gt;exactly the same&lt;/em&gt; regardless of whether we had 3 or all 18 species of penguins in the world in this dataframe.&lt;/p&gt;
&lt;p&gt;Now, let&amp;rsquo;s see an example where instead of just printing the plots, we wanted to save each plot in an appropriately named file:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;focal_species&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;all_penguin_species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## Select just the data for the focal species:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;one_penguin_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;focal_species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## Create the plot:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_penguin_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;focal_species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## Save the plot&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;filename&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;&amp;#123;focal_species&amp;#125;_bill-len_bill-dp.png&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggsave&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;filename&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;         &lt;span class=&#39;c&#39;&gt;# Save the plot to file!&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This would create the following &lt;code&gt;png&lt;/code&gt; files:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Adelie_bill-len_bill-dp.png&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# Gentoo_bill-len_bill-dp.png&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# Chinstrap_bill-len_bill-dp.png&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Similarly, it is straightforward to save a text file with results in each iteration of a loop:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;focal_species&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;all_penguin_species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## Select just the data for the focal species:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;one_penguin_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;focal_species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## Save the results in a tab-separated values (tsv) file:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;filename&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;&amp;#123;focal_species&amp;#125;.tsv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;write_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_penguin_df&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;filename&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# Save the dataframe to file!&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This would create the following text files:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Adelie.tsv&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# Gentoo.tsv&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# Chinstrap.tsv&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;iv----if-statements&#34;&gt;IV &amp;ndash; &lt;code&gt;if&lt;/code&gt; statements&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;if&lt;/code&gt; statements are similar in syntax to &lt;code&gt;for&lt;/code&gt; loops, and are also considered a &amp;ldquo;control flow&amp;rdquo; structure. But their purpose is different from loops: instead of iterating, &lt;strong&gt;&lt;code&gt;if&lt;/code&gt; statements do something once and they &lt;em&gt;only&lt;/em&gt; do it when a condition is fulfilled.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;For instance, we may want to check in a script whether a certain directory (folder) exists on our computer, and if it doesn&amp;rsquo;t, then we create the directory:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## `!dir.exists()` will be `TRUE` if the directory doesn&#39;t already exist&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;## `!` inverts a logical, so the below says &#34;If the directory does _not_ exist&#34;&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.exists&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;important_directory&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Creating new directory&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;important_directory&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;else&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Dir already exists&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Inside the parentheses &lt;code&gt;()&lt;/code&gt; after &lt;code&gt;if&lt;/code&gt;, we should define a test that evaluates to either &lt;code&gt;TRUE&lt;/code&gt; or &lt;code&gt;FALSE&lt;/code&gt;. If the test evaluates to &lt;code&gt;TRUE&lt;/code&gt;, whatever is inside the curly braces &lt;code&gt;{}&lt;/code&gt; will be &lt;strong&gt;executed&lt;/strong&gt;, and if it is &lt;code&gt;FALSE&lt;/code&gt;, what is inside the curly braces will be &lt;strong&gt;ignored&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;We can &lt;em&gt;optionally&lt;/em&gt; add an &lt;code&gt;else&lt;/code&gt; clause: what to do if the test evaluated to &lt;code&gt;FALSE&lt;/code&gt;. (And for more complicated cases, &lt;code&gt;else if&lt;/code&gt; clauses can add additional tests and actions.)&lt;/p&gt;
&lt;p&gt;&lt;code&gt;if&lt;/code&gt; statements are commonly combined with &lt;code&gt;for&lt;/code&gt; loops &amp;ndash; we may want to only execute the functions in our loop for items in our collection that fulfill a certain condition:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Only `TRUE` for numbers &amp;gt;7&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;     &lt;span class=&#39;c&#39;&gt;# Hence, this is only executed for numbers &amp;gt;7&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 9&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;Like in &lt;code&gt;for&lt;/code&gt; loops, braces can be omitted in &lt;code&gt;if&lt;/code&gt; statements in one-liners:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 9&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-ii&#34;&gt;Breakout Rooms II&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-3-a-plotting-loop&#34;&gt;Exercise 3: A plotting loop&lt;/h3&gt;
&lt;p&gt;Using a loop and the &lt;code&gt;penguins&lt;/code&gt; dataframe, produce a separate scatterplot for each island with bill length vs. body weight, using different colors for the species and different shapes for the sexes.&lt;/p&gt;
&lt;p&gt;Print each plot &lt;em&gt;and&lt;/em&gt; save each plot to file.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The loop plotting example we went through above have almost the same code that you&amp;rsquo;ll need here, so take another look at that if you&amp;rsquo;re stuck.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Islands are in the &lt;code&gt;island&lt;/code&gt; column and penguin sexes are in the &lt;code&gt;sex&lt;/code&gt; column.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use the &lt;code&gt;shape&lt;/code&gt; aesthetic in &lt;em&gt;ggplot2&lt;/em&gt; to get different shapes for the sexes.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;all_islands&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;focal_island&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;all_islands&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## Select just the data for the focal island:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;one_island_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;focal_island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## Create the plot:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_island_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;,
                   color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;focal_island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## Save and print the plot&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;filename&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;&amp;#123;focal_island&amp;#125;_bill-len_bill-dp.png&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggsave&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;filename&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-25-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-25-2.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-25-3.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-4-if-in-a-loop&#34;&gt;Exercise 4: &lt;code&gt;if&lt;/code&gt; in a loop&lt;/h3&gt;
&lt;p&gt;In the previous exercise, you should have noticed that one island only has a single species of penguin.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s say that we don&amp;rsquo;t want to create this plot for islands with only a single species. Modify your loop from the previous exercise to include an &lt;code&gt;if&lt;/code&gt; statement such that you will only make plots for islands with multiple species of penguins.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;You&amp;rsquo;ll want to count the number of distinct species in the dataframe after filtering it to contain penguins for one island only. One way to do that is using &lt;a href=&#34;https://rdrr.io/r/base/length.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;length(unique(...))&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;all_islands&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;focal_island&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;all_islands&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## Select just the data for the focal island:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;one_island_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;focal_island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## Check how many species there are:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;n_species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_island_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n_species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;## Create the plot:&lt;/span&gt;
    &lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_island_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;,
                     color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;focal_island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    
    &lt;span class=&#39;c&#39;&gt;## Save and print the plot&lt;/span&gt;
    &lt;span class=&#39;nv&#39;&gt;filename&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;&amp;#123;focal_island&amp;#125;_bill-len_bill-dp.png&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;ggsave&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;filename&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-26-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-26-2.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;&lt;strong&gt;Bonus:&lt;/strong&gt; Add an &lt;code&gt;else&lt;/code&gt; clause to print a message to screen that no plot will be created for the focal island.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;all_islands&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;focal_island&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;all_islands&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## Select just the data for the focal species:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;one_island_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;focal_island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
   
  &lt;span class=&#39;c&#39;&gt;## Check how many species there are&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;n_species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_island_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n_species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;## Create the plot:&lt;/span&gt;
    &lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_island_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;,
                     color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;focal_island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    
    &lt;span class=&#39;c&#39;&gt;## Save and print the plot&lt;/span&gt;
    &lt;span class=&#39;nv&#39;&gt;filename&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;&amp;#123;focal_island&amp;#125;_bill-len_bill-dp.png&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;ggsave&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;filename&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;else&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Not creating a plot for &amp;#123;focal_island&amp;#125;&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Not creating a plot for Torgersen&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-27-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-27-2.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;bonus-material&#34;&gt;Bonus Material&lt;/h2&gt;
&lt;h3 id=&#34;test-operators-and-functions&#34;&gt;Test operators and functions&lt;/h3&gt;
&lt;p&gt;Common test operators and functions include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;==&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;!=&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; to test for (in)equality for numbers and characters alike&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;, &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;gt;=&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;lt;=&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; for numeric comparisons&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/match.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;%in%&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; to test for &amp;ldquo;group membership&amp;rdquo; (see examples below)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/NA.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;is.na()&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/NULL.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;is.null()&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; to test for &lt;code&gt;NA&lt;/code&gt; and &lt;code&gt;NULL&lt;/code&gt; values, respectively&lt;/li&gt;
&lt;li&gt;Any test can be negated (inverted) with an exclamation mark &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Logic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;!&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Some examples:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;!=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] FALSE&lt;/span&gt;

&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%in%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;     &lt;span class=&#39;c&#39;&gt;# 8 is contained in the vector 5, 8, 10&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;

&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%in%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;        &lt;span class=&#39;c&#39;&gt;# 8 is not contained in the vector 10:20&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] FALSE&lt;/span&gt;

&lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%in%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Gentoo&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;

&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can also combine tests with &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Logic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;amp;&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; (logical and) and &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Logic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;|&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; (logical or):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# With `&amp;amp;`, TRUE is returned if both tests are TRUE:&lt;/span&gt;
&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;8&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;
&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;8&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] FALSE&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# With `|`, TRUE is returned if at least one of the tests is TRUE: &lt;/span&gt;
&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;8&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;
&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;8&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;
&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;!=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;8&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] FALSE&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h3 id=&#34;storing-loop-output&#34;&gt;Storing loop output&lt;/h3&gt;
&lt;p&gt;If we want the output to be saved in an object of some kind, we need to explicitly make an assignment in each iteration of the loop. &lt;em&gt;This is where we need to start paying attention to the design of our loop.&lt;/em&gt; Unless computational speed is of no concern, you should &lt;strong&gt;avoid growing an object in each iteration of the loop&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For example, you might be inclined to do the following if you wanted to compute and store the medians of each column in a data frame:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## We initialize a vector in which we collect the column medians:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/vector.html&#39;&gt;vector&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## We extract one column using &#34;dataframe_name[[column_number]]&#34;:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;column_median&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/median.html&#39;&gt;median&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## We add the single-column median to our vector of medians:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;column_median&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]   44.45   17.30  197.00 4050.00&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Similarly, if you were working with a data frame, you may be tempted to add a column (with &lt;a href=&#34;https://rdrr.io/r/base/cbind.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;cbind()&lt;/code&gt;&lt;/a&gt;) or a row (with &lt;a href=&#34;https://rdrr.io/r/base/cbind.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;rbind()&lt;/code&gt;&lt;/a&gt;) to the data frame in each iteration of the loop.&lt;/p&gt;
&lt;p&gt;The problem with these approaches is that &lt;strong&gt;R has to create an entirely new object in each iteration of the loop&lt;/strong&gt;, because the object&amp;rsquo;s memory requirements keep increasing.&lt;/p&gt;
&lt;p&gt;Instead, before you start the loop, you&amp;rsquo;ll want to give the final vector (here, &lt;code&gt;column_medians&lt;/code&gt;) the appropriate size:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/vector.html&#39;&gt;vector&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;length &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;column_median&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/median.html&#39;&gt;median&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;column_median&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]    0.00    0.00   44.45   17.30  197.00 4050.00&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note that for very small problems, such as the example above, there will &lt;em&gt;not&lt;/em&gt; be a noticeable difference in computing time between pre-assigning a properly sized object versus growing an object inside the loop. However, it is still good to get into the habit of pre-assigning an object of the right size.&lt;/p&gt;
&lt;p&gt;Some &lt;strong&gt;summary guidelines for loops&lt;/strong&gt;, especially when you are working with large datasets and speed is an issue:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Don&amp;rsquo;t use a loop when you can instead use vectorized operations.&lt;/li&gt;
&lt;li&gt;When you write a loop, avoid doing things &lt;em&gt;inside&lt;/em&gt; the loop that don&amp;rsquo;t need to be repeated.&lt;/li&gt;
&lt;li&gt;Don&amp;rsquo;t grow objects inside the loop. Instead, pre-assign an object large enough to contain all output of the loop and fill it in inside the loop.&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;h4 id=&#34;further-reading&#34;&gt;Further reading&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://r4ds.had.co.nz/iteration.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;The iteration chapter&lt;/a&gt; in Hadley Wickham&amp;rsquo;s R for Data Science (2017). Doesn&amp;rsquo;t really cover &lt;code&gt;if&lt;/code&gt; statements.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://swcarpentry.github.io/r-novice-gapminder/07-control-flow/index.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Software Carpentry Control Flow lesson&lt;/a&gt;. Starts out with &lt;code&gt;if&lt;/code&gt; statements.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>S03E07: Avoid Copy-pasting Code - Intro and Vectorization</title>
      <link>https://biodash.github.io/codeclub/s03e07_vectorization/</link>
      <pubDate>Wed, 23 Feb 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s03e07_vectorization/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;housekeeping&#34;&gt;Housekeeping&lt;/h2&gt;
&lt;h4 id=&#34;new-to-code-club&#34;&gt;New to Code Club?&lt;/h4&gt;
&lt;p&gt;Check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;h4 id=&#34;session-goals&#34;&gt;Session goals&lt;/h4&gt;
&lt;p&gt;Today, you will learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;That you should avoid copy-pasting your code&lt;/li&gt;
&lt;li&gt;Which alternatives exist in R&lt;/li&gt;
&lt;li&gt;What &lt;em&gt;vectorization&lt;/em&gt; is and how to make use of it&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;r-packages-we-will-use&#34;&gt;R packages we will use&lt;/h4&gt;
&lt;p&gt;We will use &lt;em&gt;palmerpenguins&lt;/em&gt; for its &lt;code&gt;penguins&lt;/code&gt; dataframe, the &lt;em&gt;tidyverse&lt;/em&gt; for dataframe manipulation and plotting, and &lt;em&gt;glue&lt;/em&gt;&amp;rsquo;s &lt;code&gt;glue&lt;/code&gt; function to paste strings.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## This will _install_ the packages only if you don&#39;t already have them:&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidyverse/glue&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;glue&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## This will _load_ the packages:&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidyverse/glue&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;i----avoid-copy-pasting-code&#34;&gt;I &amp;ndash; Avoid copy-pasting code&lt;/h2&gt;
&lt;h3 id=&#34;dont-repeat-yourself&#34;&gt;Don&amp;rsquo;t Repeat Yourself&lt;/h3&gt;
&lt;p&gt;Sometimes, you have a bit of code, and you need to repeat the operations in that code &lt;em&gt;almost&lt;/em&gt; exactly.&lt;/p&gt;
&lt;p&gt;This can apply to anywhere from a single line to dozens of lines of code. For instance, you may want to rerun a statistical model with different parameter values, or repeat an analysis for different batches or subsets of samples. In the context of our trusty penguins dataset, we may want to repeat an analysis for each of the 4 morphological measurements taken for each penguin.&lt;/p&gt;
&lt;p&gt;Your first instinct is perhaps to copy-paste your code several times, and make the necessary slight adjustments in each instance. There are problems with this approach, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You will end up with a lot of code, reducing clarity and making it more error-prone&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Making changes to the parts of the code shared by all blocks becomes challenging.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Avoiding such code repetition is where the programming mantra &amp;ldquo;Don&amp;rsquo;t Repeat Yourself&amp;rdquo; (&amp;ldquo;DRY&amp;rdquo;) comes from.&lt;/p&gt;
&lt;br&gt;
&lt;h3 id=&#34;alternatives&#34;&gt;Alternatives&lt;/h3&gt;
&lt;p&gt;So, what are the alternatives?&lt;/p&gt;
&lt;p&gt;In R, two key approaches that allow you to avoid copy-pasting your code both involve &lt;em&gt;iteration&lt;/em&gt; to repeat a procedure, and do so either:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Using a &lt;em&gt;&lt;strong&gt;loop&lt;/strong&gt;&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Using &lt;em&gt;&lt;strong&gt;&amp;ldquo;functional programming&amp;rdquo;&lt;/strong&gt;&lt;/em&gt;: apply a function multiple times with special functions (&amp;ldquo;functionals&amp;rdquo;) from the base R &lt;code&gt;apply&lt;/code&gt;-family or &lt;em&gt;purrr&lt;/em&gt;&amp;rsquo;s &lt;code&gt;map&lt;/code&gt;-family.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Loops are especially useful if you have a whole block of code that needs to be rerun, while functionals are easier to apply when you need to rerun a single function call.&lt;/p&gt;
&lt;p&gt;You can additionally avoid code repetition by:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Writing your own functions&lt;/strong&gt;&lt;/em&gt; (using &lt;em&gt;arguments&lt;/em&gt; to make them flexible)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In simple cases, making use of R&amp;rsquo;s &lt;em&gt;&lt;strong&gt;vectorization&lt;/strong&gt;&lt;/em&gt; capabilities.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;These approaches are clearer, less error-prone, and more flexible than copy-pasting code. They can also be combined.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;We will tackle all of these approaches in Code Club in the upcoming weeks, starting with vectorization this week.&lt;/strong&gt;&lt;/p&gt;
&lt;br&gt;
&lt;h3 id=&#34;but-first-an-iteration-example&#34;&gt;But first, an iteration example&lt;/h3&gt;
&lt;p&gt;Below, I will give a quick example of each of the two iteration approaches: a loop and a functional. Hopefully, this will be illustrative even if you don&amp;rsquo;t understand all the details: come back in the next few weeks to learn more about it!&lt;/p&gt;
&lt;p&gt;Say that we wanted to compute the mean for each of the 4 measurements taken for each penguin: bill length, bill depth, flipper length, and body mass.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g sex  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie  Torge…           39.1          18.7              181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;750 male &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Adelie  Torge…           39.5          17.4              186        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;800 fema…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Adelie  Torge…           40.3          18                195        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;250 fema…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Adelie  Torge…           &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;                 &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Adelie  Torge…           36.7          19.3              193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;450 fema…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Adelie  Torge…           39.3          20.6              190        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;650 male &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1 more variable: year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;First, let&amp;rsquo;s see how we can do this for one measurement:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## We extract a vector of bill lengths from the penguins dataframe with `$`&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;## Note that any NAs would cause the mean to be NA without na.rm=TRUE&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 43.92193&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Among other options, we could also extract this 3rd column using `[[`:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 43.92193&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;(For an overview of base R data frame indexing, see the &lt;a href=&#34;#base-r-data-frame-indexing&#34;&gt;bottom of the the page&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;If we would simply repeat this procedure using the first syntax four times, we would write:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 43.92193&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 17.15117&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 200.9152&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4201.754&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;But that is a bit repetitive. And it would get especially repetitive if we had 20 different measurements. Or if, instead of just computing the mean, we wanted to perform an analysis consisting of multiple steps.&lt;/p&gt;
&lt;p&gt;How would using iteration in a case like this look like?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;With a &lt;code&gt;for&lt;/code&gt; loop:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## The columns we are interested in are columns 3 through 6 (3:6)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;## We can extract each column with the `[[...]]` notation we saw last week&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_index&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;column_mean&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_index&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 43.92193&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 17.15117&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 200.9152&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4201.754&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;With &lt;em&gt;purrr&lt;/em&gt;&amp;rsquo;s &lt;code&gt;map()&lt;/code&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;map&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $bill_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 43.92193&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $bill_depth_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 17.15117&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $flipper_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 200.9152&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4201.754&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;In this simple example where we are working with a dataframe, a specialized &lt;em&gt;dplyr&lt;/em&gt; approach with &lt;code&gt;across()&lt;/code&gt; also works:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;summarise&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;across&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;           43.9          17.2              201.       &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;202.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h4 id=&#34;what-about-vectorization&#34;&gt;What about vectorization?&lt;/h4&gt;
&lt;p&gt;While iteration using loops or functionals is very useful, in R, we don&amp;rsquo;t need to use these strategies as much as in other languages. The main reason for this is that R often makes use of &lt;em&gt;vectorization&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;To illustrate vectorization, we&amp;rsquo;ll work with a vector of bill lengths that we extract from the penguins dataframe (though as we&amp;rsquo;ll see later, all of this works in dataframes, too):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Remove rows with NAs:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;              

&lt;span class=&#39;c&#39;&gt;## Extract a column with `$`, then take the first 10 values: &lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 39.1 39.5 40.3 36.7 39.3 38.9 39.2 41.1 38.6 34.6&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Say that we wanted to convert each value in the &lt;code&gt;bill_len&lt;/code&gt; vector from millimeters to inches. Would we need to multiply each individual value by 0.0393701?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.0393701&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1.539371&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.0393701&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1.555119&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.0393701&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1.586615&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# And so on...&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Or should we resort to a loop or a &lt;code&gt;map()&lt;/code&gt;-type function here? Fortunately, none of this is necessary! You may already know that in R, you can simply do:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.0393701&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 1.539371 1.555119 1.586615 1.444883 1.547245 1.531497 1.543308 1.618111&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [9] 1.519686 1.362205&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Similarly, say that we wanted to log-transform every value in the vector, then we can just use the &lt;a href=&#34;https://rdrr.io/r/base/Log.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;log()&lt;/code&gt;&lt;/a&gt; function once for the entire vector:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Log.html&#39;&gt;log&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 3.666122 3.676301 3.696351 3.602777 3.671225 3.660994 3.668677 3.716008&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [9] 3.653252 3.543854&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If you knew about this, perhaps you didn&amp;rsquo;t even think of much of it? Actually, it is worth dwelling on this capability, which is called &lt;em&gt;vectorization&lt;/em&gt; and is a pretty unique feature of the R language. In many other languages, you would in fact write a loop to transform each individual value.&lt;/p&gt;
&lt;p&gt;So let&amp;rsquo;s learn a bit more about vectorization.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;ii----vectorization-patterns&#34;&gt;II &amp;ndash; Vectorization patterns&lt;/h2&gt;
&lt;h3 id=&#34;a-vector-and-a-scalar&#34;&gt;A vector and a &amp;ldquo;scalar&amp;rdquo;&lt;/h3&gt;
&lt;p&gt;When we multiplied the value &lt;code&gt;0.0393701&lt;/code&gt; with the vector &lt;code&gt;bill_len&lt;/code&gt;, &lt;code&gt;0.0393701&lt;/code&gt; was automatically recycled as many times as needed to be multiplied with &lt;em&gt;each individual value&lt;/em&gt; in the &lt;code&gt;bill_len&lt;/code&gt; vector.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 39.1 39.5 40.3 36.7 39.3 38.9 39.2 41.1 38.6 34.6&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.0393701&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 1.539371 1.555119 1.586615 1.444883 1.547245 1.531497 1.543308 1.618111&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [9] 1.519686 1.362205&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;(A single value like &lt;code&gt;0.0393701&lt;/code&gt; is often called a &amp;ldquo;scalar&amp;rdquo; or a variable, but in R it is really a vector of length 1.)&lt;/p&gt;
&lt;p&gt;As mentioned, you would write a loop to do this in many other languages, and in fact, under the hood, R &lt;em&gt;also&lt;/em&gt; uses a loop to do this!&lt;/p&gt;
&lt;p&gt;Vectorization is very useful for two reasons:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;You&lt;/em&gt; don&amp;rsquo;t have to write the loop (or another iteration construct), which saves you a fair bit of typing and makes the code clearer.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The under-the-hood-loop is being executed &lt;em&gt;much&lt;/em&gt; faster than a loop that you would write with R code, because it is written in &lt;code&gt;C&lt;/code&gt;/&lt;code&gt;C++&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;vectors-of-equal-length&#34;&gt;Vectors of equal length&lt;/h3&gt;
&lt;p&gt;We can also use vectorized operations when both vectors contain multiple items. For instance, say we want to get the ratio of bill length to bill depth for each penguin:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Like above with bill length, we create a vector with 10 bill depths:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_dp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## We compute the ratio:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_dp&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 2.090909 2.270115 2.238889 1.901554 1.907767 2.185393 2.000000 2.335227&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [9] 1.820755 1.639810&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 39.1 39.5 40.3 36.7 39.3 38.9 39.2 41.1 38.6 34.6&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_dp&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 18.7 17.4 18.0 19.3 20.6 17.8 19.6 17.6 21.2 21.1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What happened here is that the first value is &lt;code&gt;bill_len&lt;/code&gt; was divided by the first value in &lt;code&gt;bill_dp&lt;/code&gt;, the second value in &lt;code&gt;bill_len&lt;/code&gt; by the second value in &lt;code&gt;bill_dp&lt;/code&gt;, and so forth.&lt;/p&gt;
&lt;p&gt;This also works directly for the columns of a data frame:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_ratio&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_ratio&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2.090909 2.270115 2.238889       NA 1.901554 1.907767&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In the above examples, both vectors had the same length. In Exercise 1, you&amp;rsquo;ll see that vectorization also works with two vectors with multiple values that &lt;em&gt;differ in length&lt;/em&gt;.&lt;/p&gt;
&lt;h3 id=&#34;vectorized-functions&#34;&gt;Vectorized functions&lt;/h3&gt;
&lt;p&gt;Above, we already briefly saw that we can simply pass a vector to the &lt;a href=&#34;https://rdrr.io/r/base/Log.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;log()&lt;/code&gt;&lt;/a&gt; function and it will compute the log for each of them and return a vector of the same length.&lt;/p&gt;
&lt;p&gt;So, the &lt;a href=&#34;https://rdrr.io/r/base/Log.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;log()&lt;/code&gt;&lt;/a&gt; function works the same regardless of whether you pass a single value or a vector with multiple values:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Log.html&#39;&gt;log&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;21&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3.044522&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Log.html&#39;&gt;log&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 3.666122 3.676301 3.696351 3.602777 3.671225 3.660994 3.668677 3.716008&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [9] 3.653252 3.543854&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Because in R, a single value like &lt;code&gt;21&lt;/code&gt; is really a vector of length 1, this behavior makes sense.&lt;/p&gt;
&lt;p&gt;Just remember that for most functions, you do really need to pass a vector and not just a sequence of numbers:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## This way, log() thinks you are passing 3 separate arguments:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Log.html&#39;&gt;log&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;15&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error in log(10, 15, 20): unused argument (20)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Now, you pass 1 argument which is a vector created with `c()`&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Log.html&#39;&gt;log&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;15&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2.302585 2.708050 2.995732&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;There are many other vectorized functions that will transform each value in a vector, such as &lt;a href=&#34;https://rdrr.io/r/base/Round.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;round()&lt;/code&gt;&lt;/a&gt; (rounding numbers) and &lt;a href=&#34;https://rdrr.io/r/base/MathFun.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;abs()&lt;/code&gt;&lt;/a&gt; (taking absolute numbers).&lt;/p&gt;
&lt;p&gt;Other vectorized functions summarize a vector into a single value, such as &lt;a href=&#34;https://rdrr.io/r/base/sum.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sum()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://rdrr.io/r/base/mean.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mean()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-i&#34;&gt;Breakout Rooms I&lt;/h2&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Code to get set up&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## This will _install_ the packages only if you don&#39;t already have them:&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidyverse/glue&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;glue&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Load the packages we will use&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidyverse/glue&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Create a vector of bill lengths&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1-unequal-length&#34;&gt;Exercise 1: Unequal length&lt;/h3&gt;
&lt;p&gt;Vectorization also works when two vectors with multiple elements do not have the same length. For instance, in the example below, we divide the first value by 10, the second by 100, the third again by 10, and so on:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 3.910 0.395 4.030 0.367 3.930 0.389 3.920 0.411 3.860 0.346&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;&lt;strong&gt;Given the length of &lt;code&gt;bill_len&lt;/code&gt; (which is 10), do you see any issues if you would&lt;/strong&gt; &lt;strong&gt;divide by a vector of length 3? Try it out and see what happens.&lt;/strong&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;While 10 is a multiple of 2, it is not a multiple of 3. This means that the shorter vector will not be recycled in its entirety the last time around.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;R will perform the operation but issue a warning about it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning in bill_len/c(10, 100, 1000): longer object length is not a multiple of shorter object length&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 3.9100 0.3950 0.0403 3.6700 0.3930 0.0389 3.9200 0.4110 0.0386 3.4600&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;p&gt;&lt;strong&gt;Negate &lt;em&gt;every other&lt;/em&gt; value in the &lt;code&gt;bill_len&lt;/code&gt; vector.&lt;/strong&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Negation means turning a positive value into a negative value and vice versa (e.g. &lt;code&gt;3&lt;/code&gt; =&amp;gt; &lt;code&gt;-3&lt;/code&gt; and &lt;code&gt;-15&lt;/code&gt; =&amp;gt; &lt;code&gt;15&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can leave the other values unchanged simply by multiplying them by 1.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  39.1 -39.5  40.3 -36.7  39.3 -38.9  39.2 -41.1  38.6 -34.6&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2-strings&#34;&gt;Exercise 2: Strings&lt;/h3&gt;
&lt;p&gt;The &lt;code&gt;glue&lt;/code&gt; function from the package of the same name allows you to combine literal strings with values or strings contained in R objects. For instance:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Biscoe&#34;&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;The island of &amp;#123;island&amp;#125;&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; The island of Biscoe&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;So, you combine both literal strings and R objects in a single quoted string, and access the values of R objects using braces &lt;code&gt;{}&lt;/code&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;&lt;strong&gt;Extract the names of the three islands contained in the &lt;code&gt;penguins&lt;/code&gt; dataframe,&lt;/strong&gt; &lt;strong&gt;and save them in an vector called &lt;code&gt;islands&lt;/code&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Use the &lt;a href=&#34;https://rdrr.io/r/base/unique.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;unique()&lt;/code&gt;&lt;/a&gt; function to get a &amp;ldquo;deduplicated&amp;rdquo; vector of islands, i.e. with one entry per island.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;islands&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;islands&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] Torgersen Biscoe    Dream    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Levels: Biscoe Dream Torgersen&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Or tidyverse style:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;islands&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;pull&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note: it is fine that &lt;code&gt;islands&lt;/code&gt; is still a &lt;em&gt;factor&lt;/em&gt;, like the &lt;code&gt;island&lt;/code&gt; column in &lt;code&gt;penguins&lt;/code&gt; was.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;p&gt;&lt;strong&gt;Make use of vectorization to print each island&amp;rsquo;s name like so:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; The island of Torgersen&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; The island of Biscoe&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; The island of Dream&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Island of &amp;#123;islands&amp;#125;&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Island of Torgersen&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Island of Biscoe&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Island of Dream&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;iii----vectorization-with-logical-indices&#34;&gt;III &amp;ndash; Vectorization with logical indices&lt;/h2&gt;
&lt;p&gt;We can also use vectorized solutions when we want to operate only on elements that satisfy a certain condition. To do so, we make use of R&amp;rsquo;s ability to index a vector with a &lt;em&gt;logical vector&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s say we don&amp;rsquo;t trust any bill length measurement of over 40 mm, and we want to remove those from our vector.&lt;/p&gt;
&lt;p&gt;First, we need to know that statements with a comparison operator like &lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/a&gt;, or &lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;==&lt;/code&gt;&lt;/a&gt; will test each value and return a logical vector with the results.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# The resulting vector contains TRUE or FALSE for each entry in the original vector:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;39.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 39.1 39.5 40.3 36.7 39.3 38.9 39.2 41.1 38.6 34.6&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Or, going back to our example with values &amp;gt;40:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;40&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] FALSE FALSE  TRUE FALSE FALSE FALSE FALSE  TRUE FALSE FALSE&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;When we index the original vector with such a logical vector (sometimes referred to as a &lt;em&gt;mask&lt;/em&gt;), we only get the &lt;code&gt;TRUE&lt;/code&gt;s, i.e. values &amp;gt;40:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;40&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 40.3 41.1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This is very succinct and powerful!&lt;/p&gt;
&lt;p&gt;With a similar strategy, you can also retain all elements of the vector but manipulate some of them:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## We create a separate vector so we don&#39;t change the original one:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_len_ed&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Only change values &amp;gt; 40:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_len_ed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;40&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_len_ed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;40&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_len_ed&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  39.1  39.5 -59.7  36.7  39.3  38.9  39.2 -58.9  38.6  34.6&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;But for those kinds of operations, the vectorized &lt;a href=&#34;https://rdrr.io/r/base/ifelse.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ifelse()&lt;/code&gt;&lt;/a&gt; function is easier and clearer:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# ifelse(test, return-this-if-true, return-this-if-false)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_len_ed&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/ifelse.html&#39;&gt;ifelse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;test &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;40&lt;/span&gt;,
                      yes &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;, no &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_len_ed&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  39.1  39.5 -59.7  36.7  39.3  38.9  39.2 -58.9  38.6  34.6&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;When creating logical vectors, the &lt;a href=&#34;https://rdrr.io/r/base/any.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;any()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://rdrr.io/r/base/all.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;all()&lt;/code&gt;&lt;/a&gt; functions are very handy.&lt;/p&gt;
&lt;p&gt;For instance, say we had a vector of p-values:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pvals&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0.06&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;0.048&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;0.01&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;0.73&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To check whether any of the p-values are significant:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/any.html&#39;&gt;any&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pvals&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.05&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To check whether all of the p-values are significant:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/all.html&#39;&gt;all&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pvals&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.05&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] FALSE&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Moreover, because &lt;code&gt;TRUE&lt;/code&gt; corresponds to 1 and &lt;code&gt;FALSE&lt;/code&gt; to 0, you can also directly count the number of elements that satisfy a condition:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/sum.html&#39;&gt;sum&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pvals&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.05&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-ii&#34;&gt;Breakout Rooms II&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-3-logical-vectors&#34;&gt;Exercise 3: Logical vectors&lt;/h3&gt;
&lt;p&gt;Create a vector &lt;code&gt;bill_len_NA&lt;/code&gt; where all values &amp;gt; 40 have been turned into &lt;code&gt;NA&lt;/code&gt;s.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Using logical vector subsetting:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_len_NA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_len_NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_len_NA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;40&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_len_NA&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 39.1 39.5   NA 36.7 39.3 38.9 39.2   NA 38.6 34.6&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Or, using `ifelse()`:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_len_NA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/ifelse.html&#39;&gt;ifelse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;40&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_len&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_len_NA&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 39.1 39.5   NA 36.7 39.3 38.9 39.2   NA 38.6 34.6&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;p&gt;Remove all &lt;code&gt;NA&lt;/code&gt;s from &lt;code&gt;bill_len_NA&lt;/code&gt;. (If you don&amp;rsquo;t know the function to identify &lt;code&gt;NA&lt;/code&gt;s in a vector, take a look at the Hints.)&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The function &lt;a href=&#34;https://rdrr.io/r/base/NA.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;is.na()&lt;/code&gt;&lt;/a&gt; will check which values in a vector are &lt;code&gt;NA&lt;/code&gt;s: it returns a logical vector with &lt;code&gt;TRUE&lt;/code&gt;s for &lt;code&gt;NA&lt;/code&gt; values and &lt;code&gt;FALSE&lt;/code&gt;s for non-&lt;code&gt;NA&lt;/code&gt; values.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Since you want to &lt;em&gt;remove&lt;/em&gt; &lt;code&gt;NA&lt;/code&gt; values, you need to negate the output of the &lt;a href=&#34;https://rdrr.io/r/base/NA.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;is.na()&lt;/code&gt;&lt;/a&gt; function when subsetting. You can negate logical tests in R with a &lt;a href=&#34;https://rdrr.io/r/base/Logic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;!&lt;/code&gt;&lt;/a&gt;. So, &lt;code&gt;!is.na()&lt;/code&gt; would have &lt;code&gt;TRUE&lt;/code&gt; for non-&lt;code&gt;NA&lt;/code&gt; values, which would allow you to keep them.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_len_NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_len_NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 39.1 39.5 36.7 39.3 38.9 39.2 38.6 34.6&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-4-ifelse-plot&#34;&gt;Exercise 4: &lt;code&gt;ifelse()&lt;/code&gt; plot&lt;/h3&gt;
&lt;p&gt;With &lt;em&gt;ggplot&lt;/em&gt;, make a &lt;code&gt;geom_point()&lt;/code&gt; plot of &lt;code&gt;bill_length_mm&lt;/code&gt; versus &lt;code&gt;bill_depth_mm&lt;/code&gt; only for Gentoo Penguins. In this plot, highlight penguins with a bill length to bill depth ratio larger than 3.5 by giving those points a different color.&lt;/p&gt;
&lt;p&gt;(Don&amp;rsquo;t hesitate to look at the Hints if you&amp;rsquo;re not sure how to approach this.)&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints 1 &lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Create a new dataframe with:
&lt;ul&gt;
&lt;li&gt;Just Gentoo penguins (use the function &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt;)&lt;/li&gt;
&lt;li&gt;No &lt;code&gt;NA&lt;/code&gt;s (use the function &lt;code&gt;drop_na()&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;A new column with a logical vector indicating whether the bill length to bill depth ratio is &amp;gt;3.5 (e.g., use the &lt;code&gt;mutate()&lt;/code&gt; function with an &lt;a href=&#34;https://rdrr.io/r/base/ifelse.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ifelse()&lt;/code&gt;&lt;/a&gt; statement).&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;When creating the plot, assign the new column to the &lt;code&gt;color&lt;/code&gt; aesthetic.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;An alternative:&lt;/em&gt; you don&amp;rsquo;t even need to create the logical-vector-column, you could also directly map the &lt;code&gt;color&lt;/code&gt; aesthetic to a logical expression!&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints 2 &lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Here is some example skeleton code for the data processing:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## Only retain rows for 1 penguin species:&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## Remove rows with NAs:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;c&#39;&gt;## Create a new column `ratio` with a logical vector:&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;ratio &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/ifelse.html&#39;&gt;ifelse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;&amp;gt; 3.5&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;&amp;lt; 3.5&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Here is some example skeleton code for the plot:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## Use the new column with the logical vector for the `color` aesthetic&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Create the new dataframe&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;gent&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Gentoo&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    ratio &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/ifelse.html&#39;&gt;ifelse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3.5&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;&amp;gt; 3.5&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;&amp;lt; 3.5&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Make the plot:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;gent&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ratio&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-38-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Or include the comparison directly in the &lt;code&gt;ggplot&lt;/code&gt; call (!):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Create the new dataframe without making a new variable&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;gent&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Gentoo&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Make the plot and include the logical expression in the `aes()` call:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;gent&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;,
                 color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill length ratio &amp;gt; 3.5&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-39-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;bonus&#34;&gt;Bonus&lt;/h2&gt;
&lt;h3 id=&#34;matrix-vectorization&#34;&gt;Matrix vectorization&lt;/h3&gt;
&lt;p&gt;We can also perform vectorized operations on &lt;em&gt;entire matrices&lt;/em&gt;. With the following matrix:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## We use the &#34;sample&#34; function to get 25 random values between 1 and a 100,&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;## and put those in a 5*5 matrix:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/matrix.html&#39;&gt;matrix&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/sample.html&#39;&gt;sample&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;25&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, nrow &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;, ncol &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mat&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      [,1] [,2] [,3] [,4] [,5]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1,]   53   47   52   31   16&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [2,]   13   83    4   37   34&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [3,]   17   89   40   30   20&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [4,]   60   81   98   66   90&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [5,]   36   58   91   19   82&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&amp;hellip;we could multiple all values by 10 or get the square of each value simply as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;mat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      [,1] [,2] [,3] [,4] [,5]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1,]  530  470  520  310  160&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [2,]  130  830   40  370  340&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [3,]  170  890  400  300  200&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [4,]  600  810  980  660  900&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [5,]  360  580  910  190  820&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;mat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mat&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      [,1] [,2] [,3] [,4] [,5]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1,] 2809 2209 2704  961  256&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [2,]  169 6889   16 1369 1156&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [3,]  289 7921 1600  900  400&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [4,] 3600 6561 9604 4356 8100&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [5,] 1296 3364 8281  361 6724&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;base-r-data-frame-indexing&#34;&gt;Base R data frame indexing&lt;/h3&gt;
&lt;p&gt;Extract a column &lt;em&gt;as a vector&lt;/em&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## By name:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## By index (column number):&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Extract one or more columns &lt;em&gt;as a data frame&lt;/em&gt; using &lt;code&gt;[row, column]&lt;/code&gt; notation,&lt;br&gt;
with a leading comma (&lt;code&gt;[, column]&lt;/code&gt;) meaning all rows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## By name:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;island&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## By index (column numbers):&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Subset rows by a condition, with a trailing comma (&lt;code&gt;[row, ]&lt;/code&gt;) meaning all columns:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;40&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
</description>
    </item>
    
    <item>
      <title>S03E06: Data structures and subsetting</title>
      <link>https://biodash.github.io/codeclub/s03e06_datastructures/</link>
      <pubDate>Tue, 15 Feb 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s03e06_datastructures/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New To Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has some pointers that might be helpful if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Please open RStudio before Code Club to test things out &amp;ndash; if you run into issues, join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Learn the uses of base-R&amp;rsquo;s three subsetting operators: &lt;code&gt;[ ]&lt;/code&gt;, &lt;code&gt;[[ ]]&lt;/code&gt;, and &lt;code&gt;$&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Learn how the behavior of these operators varies depending on the &lt;strong&gt;data structure&lt;/strong&gt; you are subsetting (vector, list, or data frame).&lt;/li&gt;
&lt;li&gt;Learn the value of the &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; command.&lt;/li&gt;
&lt;li&gt;Learn how these base-R operators relate to tidyverse commands.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;In our previous set of Code Clubs on stats packages, we&amp;rsquo;ve encountered data structures of various kinds. Here we put the data structure material all in one place, and put it in a wider R context. We&amp;rsquo;ll move below and beyond the tidyverse to get an overview of accessing various kinds of data structure in R.&lt;/p&gt;
&lt;h2 id=&#34;intro-what-is-subsetting-anyway&#34;&gt;Intro: What is &amp;lsquo;subsetting&amp;rsquo; anyway?&lt;/h2&gt;
&lt;p&gt;Subsetting (also known as indexing) is simply a way of using base-R syntax to extract specific pieces of a data structure.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ve already seen two &lt;strong&gt;dplyr&lt;/strong&gt; verbs that perform this kind of operation: &lt;code&gt;filter&lt;/code&gt; (to extract specific rows) and &lt;code&gt;select&lt;/code&gt; (to extract specific columns).&lt;/p&gt;
&lt;p&gt;But these are tidyverse commands, and only work with data frames.&lt;/p&gt;
&lt;p&gt;R has two more basic data structures, from which everything else is built, &lt;strong&gt;vectors&lt;/strong&gt; and &lt;strong&gt;lists&lt;/strong&gt;, and for these we need different subsetting operators (dplyr functions won&amp;rsquo;t work). We&amp;rsquo;ll also see that data frames are just a special kind of list, and that base-R subsetting operators also work for these, which can often be useful and efficient.&lt;/p&gt;
&lt;p&gt;In your R experience you will almost certainly come across both code and output which does not adhere to tidyverse conventions. We have already come across outputs which are &lt;em&gt;not&lt;/em&gt; data frames in &lt;a href=&#34;https://biodash.github.io/codeclub/s03e01_ttests/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;SO3E01: t-tests&lt;/a&gt; and &lt;a href=&#34;https://biodash.github.io/codeclub/s03e02_anova/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;S03E02: ANOVA&lt;/a&gt; which we will revisit below.&lt;/p&gt;
&lt;p&gt;Since the behavior of these operators depends on the actual data structure you are working with, it&amp;rsquo;s useful when experimenting to use them in conjunction with the &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; function, which compactly displays the internal structure of an any R object. A knowledge of the make-up of these data structures is also important when you come to write your own loops, iterations, and functions.&lt;/p&gt;
&lt;p&gt;The most important distinction between vectors and lists is within vectors &lt;em&gt;every value must be of the same type&lt;/em&gt;: for example, all characters, or all integers, etc. Inside lists, you can &lt;em&gt;mix values of any type&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;In addition, a list is best thought of as a general purpose container, which can contain not just mixed values, but also &lt;em&gt;entire vectors&lt;/em&gt; of any type.&lt;/p&gt;
&lt;p&gt;Since we&amp;rsquo;ll be comparing base-R with tidyverse functions, we need to load the tidyverse, and we&amp;rsquo;ll also be using the &lt;code&gt;palmerpenguins&lt;/code&gt; package to reproduce our previous ANOVA results:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;vectors&#34;&gt;Vectors&lt;/h2&gt;
&lt;p&gt;A vector is absolutely the most basic data structure in R. Every value in a vector must be of the &lt;strong&gt;same type&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;There are four basic &lt;strong&gt;types&lt;/strong&gt; of vector: integer, double, character, and logical. Vectors are created by hand with the &lt;a href=&#34;https://rdrr.io/r/base/c.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;c()&lt;/code&gt;&lt;/a&gt; (combine, concatenate) function. We can check the type with the &lt;a href=&#34;https://rdrr.io/r/base/typeof.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;typeof()&lt;/code&gt;&lt;/a&gt; operator. This is totally redundant if you just created the vector yourself, but when you are debugging code, or creating a vector using an expression, you might want to check exactly what type of vector is being used:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;vec_dbl&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;vec_dbl&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3 4 5&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_dbl&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;double&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;vec_seq&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/seq.html&#39;&gt;seq&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;vec_seq&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3 4 5&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_seq&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;integer&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;vec_which&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;vec_which&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3 4 5&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_which&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;integer&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;vec_chr&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;b&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;c&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;d&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;e&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;vec_chr&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;a&#34; &#34;b&#34; &#34;c&#34; &#34;d&#34; &#34;e&#34;&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_chr&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;character&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Vectors have an insanely simple &lt;strong&gt;str&lt;/strong&gt;ucture:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_dbl&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  num [1:5] 1 2 3 4 5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; also displays the type, and RStudio displays the result of &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; in the Values pane. (Note that &amp;lsquo;double&amp;rsquo; and &amp;lsquo;num(eric)&amp;rsquo; mean exactly the same thing in R.)&lt;/p&gt;
&lt;p&gt;For such a simple structure, there are a surprisingly large number of ways to subset a vector. We&amp;rsquo;ll just look a a small sample here, and use the following example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2.1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4.2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3.3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5.4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2.1 4.2 3.3 5.4&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  num [1:4] 2.1 4.2 3.3 5.4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;(Notice for this example we are using a pedagocial trick, where the &lt;em&gt;number after the decimal point&lt;/em&gt; indicates the position (index) of the value before the decimal point).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Positive integers&lt;/strong&gt; return elements at the specified positions. Any expression that evaluates to a vector of positions can be used as the index. The index operator is &lt;code&gt;[ ]&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3.3&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3.3 2.1&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.2 3.3 5.4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Negative integers&lt;/strong&gt; &lt;em&gt;exclude&lt;/em&gt; elements at the specified positions:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2.1 4.2 5.4&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.2 5.4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The bottom line here is that each value in a vector has an implicit index (position), and we can use that index to pull out values of interest. This can be extremely useful when writing for-loops that move through a vector accessing one value at a time.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Attributes&lt;/strong&gt;. One of the unusual features of R as opposed to other programming languages is that you can assign metadata of various kinds to the elements of vectors (and lists). For example, we can assign a &lt;strong&gt;name&lt;/strong&gt; to each element, and then use a &lt;strong&gt;character vector&lt;/strong&gt; as the index expression:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2.1&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;b&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;4.2&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;c&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3.3&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;d&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5.4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Named num [1:4] 2.1 4.2 3.3 5.4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  - attr(*, &#34;names&#34;)= chr [1:4] &#34;a&#34; &#34;b&#34; &#34;c&#34; &#34;d&#34;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;d&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;c&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   d   c   a &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5.4 3.3 2.1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; command now shows us that we now have a &amp;lsquo;Named&amp;rsquo; numeric vector, and that we have a &amp;ldquo;names&amp;rdquo; attribute, which is itself a character vector.&lt;/p&gt;
&lt;h3 id=&#34;exercise-1a&#34;&gt;Exercise 1a&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Consider the words &amp;ldquo;yellow&amp;rdquo;, &amp;ldquo;red&amp;rdquo;, and &amp;ldquo;green&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Create a numeric vector called &amp;ldquo;lengths&amp;rdquo; which simply shows the &lt;em&gt;length of the words&lt;/em&gt; (in that order).&lt;/p&gt;
&lt;p&gt;Look at its structure using &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Extract the first and last elements of this vector, indexing by position.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;lengths&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;lengths&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  num [1:3] 6 3 5&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;lengths&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 6 5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;h3 id=&#34;exercise-1b&#34;&gt;Exercise 1b&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Now create a second vector called &amp;ldquo;named_lengths&amp;rdquo;, with the same word-lengths, but now also using a corresponding names attribute: &amp;ldquo;yellow&amp;rdquo;, &amp;ldquo;red&amp;rdquo; and &amp;ldquo;green&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Look at its structure using &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Again, extract the first and last elements, but now using a character vector as the index.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;named_lengths&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;yellow&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;red&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;green&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;named_lengths&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Named num [1:3] 6 3 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  - attr(*, &#34;names&#34;)= chr [1:3] &#34;yellow&#34; &#34;red&#34; &#34;green&#34;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;named_lengths&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;yellow&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;green&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; yellow  green &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      6      5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;lists&#34;&gt;Lists&lt;/h2&gt;
&lt;p&gt;There are two main differences between vectors and lists: (i) lists can contain elements of &lt;strong&gt;different types&lt;/strong&gt;; and (ii) lists can contain &lt;strong&gt;entire vectors&lt;/strong&gt; as elements (and even other lists: which is why lists are sometimes referred to as &lt;strong&gt;recursive&lt;/strong&gt;: it can be lists of lists of lists, &amp;lsquo;all the way down&amp;rsquo;. This is a topic for another day!).&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s directly compare the structure of a &lt;em&gt;list&lt;/em&gt; of numbers to a &lt;em&gt;vector&lt;/em&gt; of numbers. Just as we create vectors by hand with the &lt;a href=&#34;https://rdrr.io/r/base/c.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;c()&lt;/code&gt;&lt;/a&gt; function, we create lists with the &lt;a href=&#34;https://rdrr.io/r/base/list.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;list()&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;l&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2.1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4.2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3.3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5.4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;l&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[3]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[4]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5.4&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;l&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 2.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 4.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 3.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 5.4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice the difference between &lt;em&gt;printing&lt;/em&gt; a list (all those brackets!!) and using the &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; command, which is much more compact and readable.&lt;/p&gt;
&lt;p&gt;What if we mix values of different types?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;l_mixed&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2.1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2L&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;T&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;l_mixed&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[3]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[4]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;a&#34;&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;l_mixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 2.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : int 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : logi TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : chr &#34;a&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Things get more interesting when we create a &lt;strong&gt;list of vectors&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;mixed_vectors&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;kim&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;sandy&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;lee&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;23&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;21&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;26&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mixed_vectors&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;kim&#34;   &#34;sandy&#34; &#34;lee&#34;  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 23 21 26&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mixed_vectors&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : chr [1:3] &#34;kim&#34; &#34;sandy&#34; &#34;lee&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num [1:3] 23 21 26&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In these examples we see the appearance of a new subsetting operator &lt;code&gt;[[ ]]&lt;/code&gt;, in addition to &lt;code&gt;[ ]&lt;/code&gt;. How do they differ? Let&amp;rsquo;s experiment, focussing on the second element of the list &lt;code&gt;c(23, 21, 26)&lt;/code&gt;. Let&amp;rsquo;s try to pull out that vector using the &lt;code&gt;[2]&lt;/code&gt; notation (it is the second element after all).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;mixed_vectors_subset_a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mixed_vectors&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mixed_vectors_subset_a&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 23 21 26&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mixed_vectors_subset_a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num [1:3] 23 21 26&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;This does not pull out the vector!!&lt;/strong&gt; Instead, it returns a &lt;strong&gt;sublist&lt;/strong&gt; which &lt;em&gt;contains&lt;/em&gt; that vector as the only element (we&amp;rsquo;ll see why R does this below&amp;hellip;).&lt;/p&gt;
&lt;p&gt;So how to we get our hands on the actual vector? This is where the &lt;code&gt;[[ ]]&lt;/code&gt; operator comes in:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;mixed_vectors_subset_b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mixed_vectors&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mixed_vectors_subset_b&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 23 21 26&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mixed_vectors_subset_b&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  num [1:3] 23 21 26&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We see that the behavior of the &lt;code&gt;[ ]&lt;/code&gt; operator is very different for lists: it selects the element(s) you request, but &lt;em&gt;always still wrapped inside a list&lt;/em&gt;. It &amp;lsquo;shrinks&amp;rsquo; the original list. The &lt;code&gt;[[ ]]&lt;/code&gt; operator on the other hand &amp;lsquo;drills-down&amp;rsquo; and just returns the &amp;lsquo;un-listed&amp;rsquo; vector in that position.&lt;/p&gt;
&lt;h2 id=&#34;data-frames&#34;&gt;Data frames&lt;/h2&gt;
&lt;p&gt;The reason R does things this way is because data frames are so central to the language. Let&amp;rsquo;s build a data frame from the ground up to see how it works.&lt;/p&gt;
&lt;p&gt;Basically the &amp;ldquo;inside&amp;rdquo; of a data frame is just a list with name attributes:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;attr_list&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;name &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;kim&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;sandy&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;lee&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, age &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;23&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;21&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;26&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;attr_list&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $name&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;kim&#34;   &#34;sandy&#34; &#34;lee&#34;  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $age&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 23 21 26&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;attr_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ name: chr [1:3] &#34;kim&#34; &#34;sandy&#34; &#34;lee&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ age : num [1:3] 23 21 26&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice that instead of &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; displaying &lt;code&gt;$ : ...&lt;/code&gt; for each entry, we now see attributes &lt;code&gt;$ name: ...&lt;/code&gt; , &lt;code&gt;$ age: ...&lt;/code&gt; for each entry. Also note that all those double &lt;code&gt;[[ ]]&lt;/code&gt; notations have disappeared when we print. This should give you a clue that &lt;code&gt;$age&lt;/code&gt;, for example, is a kind of alias for &lt;code&gt;[[2]]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Finally, we can &amp;lsquo;wrap&amp;rsquo; this into an official data frame structure:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/as.data.frame.html&#39;&gt;as.data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;attr_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    name age&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1   kim  23&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 sandy  21&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3   lee  26&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &#39;data.frame&#39;:  3 obs. of  2 variables:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ name: chr  &#34;kim&#34; &#34;sandy&#34; &#34;lee&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ age : num  23 21 26&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Or wrap it into a tidyverse tibble:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;my_tibble&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tibble.tidyverse.org/reference/as_tibble.html&#39;&gt;as_tibble&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;attr_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;my_tibble&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   name    age&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; kim      23&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; sandy    21&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; lee      26&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;my_tibble&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; tibble [3 × 2] (S3: tbl_df/tbl/data.frame)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ name: chr [1:3] &#34;kim&#34; &#34;sandy&#34; &#34;lee&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ age : num [1:3] 23 21 26&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;So a data frame is basically a list (intepreted as columns), with a names attribute for the columns (interpreted as headers). And with the extra condition that all the columns are of the same length, so it&amp;rsquo;s rectangular. So we should be able to use our standard list subsetting operators on it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;col_2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;col_2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &#39;data.frame&#39;:  3 obs. of  1 variable:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ age: num  23 21 26&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Since a data frame is a list, subsetting using &lt;code&gt;[ ]&lt;/code&gt; returns the specified column &lt;em&gt;still inside a data frame&lt;/em&gt;. What about &lt;code&gt;[[ ]]&lt;/code&gt;?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;vec_2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  num [1:3] 23 21 26&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Using &lt;code&gt;[[ ]]&lt;/code&gt; pulls out the data vector from the column.&lt;/p&gt;
&lt;p&gt;Just like vectors, we can also subset a data frame by the name attribute, instead of by position:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;col_2_by_name&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;age&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;col_2_by_name&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &#39;data.frame&#39;:  3 obs. of  1 variable:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ age: num  23 21 26&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;vec_2_by_name&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;age&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_2_by_name&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  num [1:3] 23 21 26&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Finally &lt;code&gt;my_df$age&lt;/code&gt; is simply a shorthand for &lt;code&gt;my_df[[&amp;quot;age&amp;quot;]]&lt;/code&gt; without the &lt;code&gt;[[ ]]&lt;/code&gt; and the &lt;code&gt;&amp;quot; &amp;quot;&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;vec_2_by_dollar_name&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;age&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_2_by_dollar_name&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  num [1:3] 23 21 26&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;direct-comparison-with-tidyverse-functions&#34;&gt;Direct comparison with tidyverse functions&lt;/h2&gt;
&lt;p&gt;The dplyr command &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; over a data frame is exactly analogous to the single bracket operator &lt;code&gt;my_df[&amp;quot;age&amp;quot;]&lt;/code&gt;. It returns a data frame with a single column:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;col_2_select&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;age&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;col_2_select&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   age&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1  23&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2  21&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3  26&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;col_2_select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &#39;data.frame&#39;:  3 obs. of  1 variable:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ age: num  23 21 26&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The dplyr command &lt;a href=&#34;https://dplyr.tidyverse.org/reference/pull.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;pull()&lt;/code&gt;&lt;/a&gt; over a data frame is exactly analogous to the double bracket operator &lt;code&gt;my_df[[&amp;quot;age&amp;quot;]]&lt;/code&gt;. It returns the data vector inside that column:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;col_2_pull&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/pull.html&#39;&gt;pull&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;age&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;col_2_pull&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 23 21 26&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;col_2_pull&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  num [1:3] 23 21 26&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The &amp;lsquo;problem&amp;rsquo; with these dplyr functions is that they &lt;em&gt;require&lt;/em&gt; a data frame as input, and we recently saw in &lt;a href=&#34;https://biodash.github.io/codeclub/s03e01_ttests/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;S03E01: t-tests&lt;/a&gt; that the statistical t-test output was &lt;em&gt;not&lt;/em&gt; a data frame:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pop1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;, mean &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, sd &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pop2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;, mean &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, sd &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/t.test.html&#39;&gt;t.test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop1&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 10&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ statistic  : Named num 0.32&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr &#34;t&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ parameter  : Named num 37.9&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr &#34;df&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ p.value    : num 0.751&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ conf.int   : num [1:2] -1.77 2.44&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;conf.level&#34;)= num 0.95&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ estimate   : Named num [1:2] 10.17 9.84&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr [1:2] &#34;mean of x&#34; &#34;mean of y&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ null.value : Named num 0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr &#34;difference in means&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ stderr     : num 1.04&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ alternative: chr &#34;two.sided&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ method     : chr &#34;Welch Two Sample t-test&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ data.name  : chr &#34;pop1 and pop2&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  - attr(*, &#34;class&#34;)= chr &#34;htest&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This is not a data frame, but an &amp;lsquo;htest&amp;rsquo; class object. Further, it cannot be converted to a data frame in the usual way:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;as.data.frame&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tresult&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;Error&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;as.data.frame.default&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tresult&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;cannot&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;coerce&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;class&lt;/span&gt; ‘&lt;span class=&#34;s&#34;&gt;&amp;#34;htest&amp;#34;&lt;/span&gt;’ &lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;data.frame&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This is precisely why the tidyverse developed the &lt;a href=&#34;https://generics.r-lib.org/reference/tidy.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;broom::tidy()&lt;/code&gt;&lt;/a&gt; function, which works with legacy base-R outputs, and converts them to data frames. But if you have lots of t-tests, the overhead of converting all the outputs using broom, then using dplyr functions to access data, can be inefficient and overkill.&lt;/p&gt;
&lt;p&gt;The t-test output is not a data frame, but it &lt;strong&gt;is&lt;/strong&gt; a named list, so we can subset it directly. For example, to pull out the &lt;code&gt;p.value&lt;/code&gt; we can do either:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.7507211&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p.value&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.7507211&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;which is really much simpler than going through broom. In addition, we can get extra granularity very quickly using this notation. Say we want the lower bound of the confidence interval. We can &amp;lsquo;stack&amp;rsquo; indexes:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -1.774624&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;or&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;conf.int&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -1.774624&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This is saying &amp;lsquo;give me the 4th element (or the conf.int element), and then give me the 1st element of that&amp;rsquo;.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Reuse the t.test() code above, run &lt;code&gt;str&lt;/code&gt; on the output, and extract the &lt;code&gt;stderr&lt;/code&gt; value using both the &lt;code&gt;$&lt;/code&gt; and &lt;code&gt;[[ ]]&lt;/code&gt; indexing approaches.&lt;/p&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;stderr&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1.041051&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1.041051&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;When we ran our first ANOVA, we never actually looked at the data structure that was produced.&lt;/p&gt;
&lt;p&gt;Run the following code and inspect the output.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;bill_length_anova&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#34;nf&#34;&gt;aov&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;data&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;penguins&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;drop_na&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(),&lt;/span&gt;
      &lt;span class=&#34;n&#34;&gt;bill_length_mm&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;~&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;species&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;sex&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;+&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;species&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;*&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;sex&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;nf&#34;&gt;str&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bill_length_anova&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Aieee!&lt;/p&gt;
&lt;p&gt;What happens when you try to turn this into a data frame, using &lt;code&gt;as.data.frame(bill_length_anova)&lt;/code&gt;?&lt;/p&gt;
&lt;p&gt;Now you can see why &lt;code&gt;broom:tidy()&lt;/code&gt; is so useful! To remind yourselves what the tidied version looks like, run the code:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;tidy_anova&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;broom&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;tidy&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bill_length_anova&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;tidy_anova&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But we can still extract values from this data structure directly: you just have to work out where to look&amp;hellip;&lt;/p&gt;
&lt;p&gt;See if you can extract the total residual df from this data structure using the $ notation.&lt;/p&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_anova&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/aov.html&#39;&gt;aov&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
      &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;*&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_anova&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 13&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ coefficients : Named num [1:6] 37.26 9.32 8.31 3.13 1.39 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr [1:6] &#34;(Intercept)&#34; &#34;speciesChinstrap&#34; &#34;speciesGentoo&#34; &#34;sexmale&#34; ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ residuals    : Named num [1:333] -1.29 2.242 3.042 -0.558 -1.09 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr [1:333] &#34;1&#34; &#34;2&#34; &#34;3&#34; &#34;4&#34; ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ effects      : Named num [1:333] -802.79 44.75 70.8 33.7 3.82 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr [1:333] &#34;(Intercept)&#34; &#34;speciesChinstrap&#34; &#34;speciesGentoo&#34; &#34;sexmale&#34; ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ rank         : int 6&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ fitted.values: Named num [1:333] 40.4 37.3 37.3 37.3 40.4 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr [1:333] &#34;1&#34; &#34;2&#34; &#34;3&#34; &#34;4&#34; ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ assign       : int [1:6] 0 1 1 2 3 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ qr           :List of 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ qr   : num [1:333, 1:6] -18.2483 0.0548 0.0548 0.0548 0.0548 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..- attr(*, &#34;dimnames&#34;)=List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..$ : chr [1:333] &#34;1&#34; &#34;2&#34; &#34;3&#34; &#34;4&#34; ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..$ : chr [1:6] &#34;(Intercept)&#34; &#34;speciesChinstrap&#34; &#34;speciesGentoo&#34; &#34;sexmale&#34; ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..- attr(*, &#34;assign&#34;)= int [1:6] 0 1 1 2 3 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..- attr(*, &#34;contrasts&#34;)=List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..$ species: chr &#34;contr.treatment&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..$ sex    : chr &#34;contr.treatment&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ qraux: num [1:6] 1.05 1.03 1.05 1.05 1.03 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ pivot: int [1:6] 1 2 3 4 5 6&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ tol  : num 1e-07&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ rank : int 6&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;class&#34;)= chr &#34;qr&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ df.residual  : int 327&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ contrasts    :List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ species: chr &#34;contr.treatment&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ sex    : chr &#34;contr.treatment&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ xlevels      :List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ species: chr [1:3] &#34;Adelie&#34; &#34;Chinstrap&#34; &#34;Gentoo&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ sex    : chr [1:2] &#34;female&#34; &#34;male&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ call         : language aov(formula = bill_length_mm ~ species + sex + species * sex, data = penguins %&amp;gt;%      drop_na())&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ terms        :Classes &#39;terms&#39;, &#39;formula&#39;  language bill_length_mm ~ species + sex + species * sex&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..- attr(*, &#34;variables&#34;)= language list(bill_length_mm, species, sex)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..- attr(*, &#34;factors&#34;)= int [1:3, 1:3] 0 1 0 0 0 1 0 1 1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..- attr(*, &#34;dimnames&#34;)=List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. .. ..$ : chr [1:3] &#34;bill_length_mm&#34; &#34;species&#34; &#34;sex&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. .. ..$ : chr [1:3] &#34;species&#34; &#34;sex&#34; &#34;species:sex&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..- attr(*, &#34;term.labels&#34;)= chr [1:3] &#34;species&#34; &#34;sex&#34; &#34;species:sex&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..- attr(*, &#34;order&#34;)= int [1:3] 1 1 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..- attr(*, &#34;intercept&#34;)= int 1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..- attr(*, &#34;response&#34;)= int 1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..- attr(*, &#34;.Environment&#34;)=&amp;lt;environment: R_GlobalEnv&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..- attr(*, &#34;predvars&#34;)= language list(bill_length_mm, species, sex)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..- attr(*, &#34;dataClasses&#34;)= Named chr [1:3] &#34;numeric&#34; &#34;factor&#34; &#34;factor&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..- attr(*, &#34;names&#34;)= chr [1:3] &#34;bill_length_mm&#34; &#34;species&#34; &#34;sex&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ model        :&#39;data.frame&#39;:  333 obs. of  3 variables:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ bill_length_mm: num [1:333] 39.1 39.5 40.3 36.7 39.3 38.9 39.2 41.1 38.6 34.6 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ species       : Factor w/ 3 levels &#34;Adelie&#34;,&#34;Chinstrap&#34;,..: 1 1 1 1 1 1 1 1 1 1 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ sex           : Factor w/ 2 levels &#34;female&#34;,&#34;male&#34;: 2 1 1 1 2 1 2 1 2 2 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;terms&#34;)=Classes &#39;terms&#39;, &#39;formula&#39;  language bill_length_mm ~ species + sex + species * sex&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..- attr(*, &#34;variables&#34;)= language list(bill_length_mm, species, sex)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..- attr(*, &#34;factors&#34;)= int [1:3, 1:3] 0 1 0 0 0 1 0 1 1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. .. ..- attr(*, &#34;dimnames&#34;)=List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. .. .. ..$ : chr [1:3] &#34;bill_length_mm&#34; &#34;species&#34; &#34;sex&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. .. .. ..$ : chr [1:3] &#34;species&#34; &#34;sex&#34; &#34;species:sex&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..- attr(*, &#34;term.labels&#34;)= chr [1:3] &#34;species&#34; &#34;sex&#34; &#34;species:sex&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..- attr(*, &#34;order&#34;)= int [1:3] 1 1 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..- attr(*, &#34;intercept&#34;)= int 1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..- attr(*, &#34;response&#34;)= int 1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..- attr(*, &#34;.Environment&#34;)=&amp;lt;environment: R_GlobalEnv&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..- attr(*, &#34;predvars&#34;)= language list(bill_length_mm, species, sex)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..- attr(*, &#34;dataClasses&#34;)= Named chr [1:3] &#34;numeric&#34; &#34;factor&#34; &#34;factor&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. .. ..- attr(*, &#34;names&#34;)= chr [1:3] &#34;bill_length_mm&#34; &#34;species&#34; &#34;sex&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  - attr(*, &#34;class&#34;)= chr [1:2] &#34;aov&#34; &#34;lm&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;as.data.frame&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bill_length_anova&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

&lt;span class=&#34;n&#34;&gt;Error&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;as.data.frame.default&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;bill_length_anova&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;:&lt;/span&gt; 
  &lt;span class=&#34;n&#34;&gt;cannot&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;coerce&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;class&lt;/span&gt; ‘&lt;span class=&#34;nf&#34;&gt;c&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;aov&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;lm&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;’ &lt;span class=&#34;n&#34;&gt;to&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;a&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;data.frame&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tidy_anova&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;broom&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://generics.r-lib.org/reference/tidy.html&#39;&gt;tidy&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_anova&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;tidy_anova&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 4 × 6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   term           df  sumsq  meansq statistic    p.value&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; species         2 &lt;span style=&#39;text-decoration: underline;&#39;&gt;7&lt;/span&gt;015.  &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;508.      654.    5.03&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-115&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; sex             1 &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;136.  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;136.      212.    2.42&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;- 37&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; species:sex     2   24.5   12.2       2.28  1.03&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-  1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Residuals     327 &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;753.     5.36     &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;span style=&#39;color: #555555;&#39;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_anova&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df.residual&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 327&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>S03E05: Introduction to correlation</title>
      <link>https://biodash.github.io/codeclub/s03e05_correlation/</link>
      <pubDate>Thu, 10 Feb 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s03e05_correlation/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;housekeeping&#34;&gt;Housekeeping&lt;/h2&gt;
&lt;h4 id=&#34;new-to-code-club&#34;&gt;New to Code Club?&lt;/h4&gt;
&lt;p&gt;Check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio. A few related Code Club sessions include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e01_ttests/&#34;&gt;S03E01&lt;/a&gt;: T-tests&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e02_anova/&#34;&gt;S03E02&lt;/a&gt;: ANOVA&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e03_pca/&#34;&gt;S03E03&lt;/a&gt;: PCA&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e04_anova2/&#34;&gt;S03E04&lt;/a&gt;: ANOVA part II&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;what-will-we-go-over-today&#34;&gt;What will we go over today&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;We will introduce correlation.&lt;/li&gt;
&lt;li&gt;Learn using the &lt;a href=&#34;https://cran.r-project.org/web/packages/corrr/index.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;corrr()&lt;/code&gt;&lt;/a&gt; package.&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;r-packages-we-will-use&#34;&gt;R packages we will use&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;corrr&lt;/em&gt; &amp;ndash; for correlation analysis&lt;/li&gt;
&lt;li&gt;&lt;em&gt;palmerpenguins&lt;/em&gt; &amp;ndash; for the penguins data&lt;/li&gt;
&lt;li&gt;&lt;em&gt;tidyverse&lt;/em&gt; &amp;ndash; for data wrangling&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---what-is-correlation&#34;&gt;1 - What is correlation?&lt;/h2&gt;
&lt;p&gt;Correlation is a statistical method used to assess a linear association between two continuous variables. It is measured by a statistic called the correlation coefficient, which represents the strength of the linear association between the variables in question. It is a dimensionless quantity that takes a value in the range −1 to +1. A correlation coefficient of zero indicates that no linear relationship exists between two continuous variables, and a correlation coefficient of −1 or +1 indicates a perfect linear relationship. (The stronger the correlation, the closer the correlation coefficient comes to −1 and +1.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Positive coefficient&lt;/strong&gt;: If the coefficient is a positive number, the variables are positively related (i.e., as the value of one variable goes up, the value of the other also tends to do so).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Negative coefficient&lt;/strong&gt;: If the coefficient is a negative number, the variables are inversely related (i.e., as the value of one variable goes up, the value of the other tends to go down).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Types of correlation coefficients&lt;/strong&gt;: There are two main types of correlation coefficients, &lt;em&gt;Pearson&amp;rsquo;s correlation coefficient&lt;/em&gt; and &lt;em&gt;Spearman&amp;rsquo;s rank correlation coefficient&lt;/em&gt;. The correct usage of correlation coefficient type depends on the types of variables being studied.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Pearson&amp;rsquo;s correlation coefficient&lt;/em&gt;: Pearson&amp;rsquo;s correlation coefficient is denoted as &lt;strong&gt;ϱ&lt;/strong&gt; for a population parameter and as &lt;strong&gt;r&lt;/strong&gt; for a sample statistic. It is used when both variables being studied are normally distributed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Spearman&amp;rsquo;s rank correlation coefficient&lt;/em&gt;: Spearman&amp;rsquo;s rank correlation coefficient is denoted as &lt;strong&gt;ϱs&lt;/strong&gt; for a population parameter and as &lt;strong&gt;rs&lt;/strong&gt; for a sample statistic. It is appropriate when one or both variables are skewed or ordinal.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Rule of thumb for interpreting the size of a correlation coefficient&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;.90 to 1.00 (−.90 to −1.00) &amp;ndash; Very high positive (negative) correlation&lt;/li&gt;
&lt;li&gt;.70 to .90 (−.70 to −.90) &amp;ndash; High positive (negative) correlation&lt;/li&gt;
&lt;li&gt;.50 to .70 (−.50 to −.70) &amp;ndash; Moderate positive (negative) correlation&lt;/li&gt;
&lt;li&gt;.30 to .50 (−.30 to −.50) &amp;ndash; Low positive (negative) correlation&lt;/li&gt;
&lt;li&gt;.00 to .30 (.00 to −.30) &amp;ndash; Negligible correlation&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2---the-corrr-package-and-our-data&#34;&gt;2 - The &lt;em&gt;corrr&lt;/em&gt; package and our data&lt;/h2&gt;
&lt;p&gt;The &lt;em&gt;corrr&lt;/em&gt; package is a tool for exploring correlations. It makes it easy to perform routine tasks when exploring correlation matrices such as ignoring the diagonal, focusing on the correlations of certain variables against others, or rearranging and visualizing the matrix in terms of the strength of the correlations. The &lt;em&gt;corrr&lt;/em&gt; package exists within the Comprehensive R Archive Network, or &lt;a href=&#34;https://cran.r-project.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CRAN&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s install it &amp;ndash; we only need to do this once:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;corrr&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To use the &lt;em&gt;corrr&lt;/em&gt; package, we need to load it up using &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt;. We also need to load the &lt;em&gt;tidyverse&lt;/em&gt; since we will be using it later:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidymodels/corrr&#39;&gt;corrr&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching packages&lt;/span&gt; ─────────────────────────────────────── tidyverse 1.3.1 ──&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2&lt;/span&gt; 3.3.5     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;purrr  &lt;/span&gt; 0.3.4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tibble &lt;/span&gt; 3.1.6     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr  &lt;/span&gt; 1.0.7&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr  &lt;/span&gt; 1.2.0     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;stringr&lt;/span&gt; 1.4.0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;readr  &lt;/span&gt; 2.1.2     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;forcats&lt;/span&gt; 0.5.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt; masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::filter()&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;    masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::lag()&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;p&gt;&lt;strong&gt;Let&amp;rsquo;s get set up and grab some data to work with.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We will use the same dataset &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;palmerpenguins&lt;/code&gt;&lt;/a&gt; used in the previous weeks.&lt;/p&gt;
&lt;p&gt;If you didn&amp;rsquo;t install this package previously, please do so now:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then, to use the package, we need to use the function &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; to load it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The data we will use today is a dataframe called &lt;code&gt;penguins&lt;/code&gt;, which we reference after loading the package. We will look at the structure of the data:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# look at the first 10 rows, all columns&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 10 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species island    bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Adelie  Torgersen           39.1          18.7               181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;750&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Adelie  Torgersen           39.5          17.4               186        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;800&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Adelie  Torgersen           40.3          18                 195        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;250&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Adelie  Torgersen           &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;                  &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Adelie  Torgersen           36.7          19.3               193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;450&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Adelie  Torgersen           39.3          20.6               190        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;650&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Adelie  Torgersen           38.9          17.8               181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;625&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Adelie  Torgersen           39.2          19.6               195        &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;675&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Adelie  Torgersen           34.1          18.1               193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;475&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Adelie  Torgersen           42            20.2               190        &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;250&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 2 more variables: sex &amp;lt;fct&amp;gt;, year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# check the structure of penguins_data&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# glimpse() which is a part of dplyr functions &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# similarly to str() and can be used interchangeably&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 344&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ island            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Torgersen, Torgersen, Torgersen, Torgersen, Torgerse…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_length_mm    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_depth_mm     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ flipper_length_mm &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ body_mass_g       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sex               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; male, female, female, NA, female, male, female, male…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Okay, now we have a sense of what the &lt;code&gt;penguins&lt;/code&gt; dataset is.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2---basic-usage-of-the-corrr-package&#34;&gt;2 - Basic usage of the &lt;em&gt;corrr&lt;/em&gt; package&lt;/h2&gt;
&lt;p&gt;Now we want to use the &lt;em&gt;corrr&lt;/em&gt; package to correlate variables in the &lt;code&gt;penguins&lt;/code&gt; dataframe. The &lt;em&gt;corrr&lt;/em&gt; package uses the &lt;a href=&#34;https://corrr.tidymodels.org/reference/correlate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;correlate()&lt;/code&gt;&lt;/a&gt; function and returns correlation results in a tibble output.&lt;/p&gt;
&lt;p&gt;Now let&amp;rsquo;s select variables from the &lt;code&gt;penguins&lt;/code&gt; dataframe using the pipe operator &lt;code&gt;%&amp;gt;%&lt;/code&gt; and the &lt;code&gt;select()&lt;/code&gt; function. We then specify the name of the variables that we want to select. In this example, we are selecting variables &lt;code&gt;bill_length_mm&lt;/code&gt;, &lt;code&gt;bill_depth_mm&lt;/code&gt;, &lt;code&gt;flipper_length_mm&lt;/code&gt;, and &lt;code&gt;body_mass_g&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Then, we will compute correlations among the variables:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_cor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Take penguins_data&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/correlate.html&#39;&gt;correlate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;       &lt;span class=&#39;c&#39;&gt;# Select variables and calculate their correlations&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Correlation method: &#39;pearson&#39;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Missing treated using: &#39;pairwise.complete.obs&#39;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;penguins_cor&lt;/span&gt;        &lt;span class=&#39;c&#39;&gt;# Correlation results in tibble&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 4 × 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   term              bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; bill_length_mm            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;            -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.235&lt;/span&gt;             0.656       0.595&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; bill_depth_mm             -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.235&lt;/span&gt;        &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;                -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.584&lt;/span&gt;      -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.472&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; flipper_length_mm          0.656        -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.584&lt;/span&gt;            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;           0.871&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; body_mass_g                0.595        -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.472&lt;/span&gt;             0.871      &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The output of the &lt;a href=&#34;https://corrr.tidymodels.org/reference/correlate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;correlate()&lt;/code&gt;&lt;/a&gt; function can be piped (&lt;code&gt;%&amp;gt;%&lt;/code&gt;) to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&#34;https://corrr.tidymodels.org/reference/shave.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;shave()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://corrr.tidymodels.org/reference/rearrange.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;rearrange()&lt;/code&gt;&lt;/a&gt; functions for internal changes&lt;/li&gt;
&lt;li&gt;The &lt;a href=&#34;https://corrr.tidymodels.org/reference/focus.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;focus()&lt;/code&gt;&lt;/a&gt;, and &lt;a href=&#34;https://corrr.tidymodels.org/reference/stretch.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;stretch()&lt;/code&gt;&lt;/a&gt; functions to reshape the structure&lt;/li&gt;
&lt;li&gt;And the &lt;a href=&#34;https://corrr.tidymodels.org/reference/rplot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;rplot()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://corrr.tidymodels.org/reference/fashion.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fashion()&lt;/code&gt;&lt;/a&gt;, and &lt;a href=&#34;https://corrr.tidymodels.org/reference/network_plot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;network_plot()&lt;/code&gt;&lt;/a&gt; for visualizations.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Let us start with internal changes&lt;/em&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&#34;https://corrr.tidymodels.org/reference/shave.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;shave()&lt;/code&gt;&lt;/a&gt; function removes values of the upper or lower triangle and sets them to &lt;code&gt;NA&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&#34;https://corrr.tidymodels.org/reference/rearrange.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;rearrange()&lt;/code&gt;&lt;/a&gt; function arranges the columns and rows based on correlation strengths.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We can apply the &lt;a href=&#34;https://corrr.tidymodels.org/reference/shave.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;shave()&lt;/code&gt;&lt;/a&gt; function to remove the top triangle:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_cor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Take penguins_cor results&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/shave.html&#39;&gt;shave&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;          &lt;span class=&#39;c&#39;&gt;# Remove the upper triangle&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 4 × 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   term              bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; bill_length_mm            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;                &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;              &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; bill_depth_mm             -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.235&lt;/span&gt;        &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;                &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;              &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; flipper_length_mm          0.656        -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.584&lt;/span&gt;            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;              &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; body_mass_g                0.595        -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.472&lt;/span&gt;             0.871          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can see that the values in the upper triangle have been replaced by &lt;code&gt;NA&lt;/code&gt;s. Now let us remove &lt;code&gt;NA&lt;/code&gt;s by using the &lt;a href=&#34;https://corrr.tidymodels.org/reference/fashion.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fashion()&lt;/code&gt;&lt;/a&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_cor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Take penguins_cor results&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;shave&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;        &lt;span class=&#39;c&#39;&gt;# Remove the upper triangle&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/fashion.html&#39;&gt;fashion&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;        &lt;span class=&#39;c&#39;&gt;# Remove NAs&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                term bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1    bill_length_mm                                                           &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2     bill_depth_mm           -.24                                            &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3 flipper_length_mm            .66          -.58                              &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4       body_mass_g            .60          -.47               .87&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can see that the &lt;code&gt;NA&lt;/code&gt;s have been removed, and we have a clean tibble (dataframe).&lt;/p&gt;
&lt;p&gt;Now, let&amp;rsquo;s rearrange columns based on correlation strengths:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_cor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Take penguins_cor results&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;rearrange&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;    &lt;span class=&#39;c&#39;&gt;# Rearrange based on correlation strengths&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;shave&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;        &lt;span class=&#39;c&#39;&gt;# Remove the upper triangle&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/fashion.html&#39;&gt;fashion&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;        &lt;span class=&#39;c&#39;&gt;# Remove NAs&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                term flipper_length_mm body_mass_g bill_length_mm bill_depth_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 flipper_length_mm                                                           &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2       body_mass_g               .87                                         &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3    bill_length_mm               .66         .60                             &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4     bill_depth_mm              -.58        -.47           -.24&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can see that the values are arranged based on correlation strengths.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h2 id=&#34;breakout-session-1&#34;&gt;Breakout session 1&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;From the &lt;code&gt;penguins&lt;/code&gt; dataframe, create a new dataset called &lt;code&gt;penguins_biscoe&lt;/code&gt; by selecting only the penguins from the island of Biscoe.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the &lt;code&gt;penguins_biscoe&lt;/code&gt; dataframe, what are the correlations between &lt;code&gt;bill_length_mm&lt;/code&gt;, &lt;code&gt;bill_depth_mm&lt;/code&gt;, &lt;code&gt;flipper_length_mm&lt;/code&gt;, and &lt;code&gt;year&lt;/code&gt;?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Remove the upper triangle and &lt;code&gt;NA&lt;/code&gt;s from the results, and arrange based on correlation strengths.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Use the &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; function to only select penguins from the island of Biscoe.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Select the penguins from the island of Biscoe:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_biscoe&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;# Save results in new object&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Biscoe&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;     &lt;span class=&#39;c&#39;&gt;# Select data from only Biscoe island  &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Calculate correlation of the variables in &lt;code&gt;penguins_biscoe&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;biscoe_cor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_biscoe&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;# select bill_length_mm, bill_depth_mm, flipper_length_mm, and year&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/correlate.html&#39;&gt;correlate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;        &lt;span class=&#39;c&#39;&gt;# Calculate correlation&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Correlation method: &#39;pearson&#39;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Missing treated using: &#39;pairwise.complete.obs&#39;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;biscoe_cor&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 4 × 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   term              bill_length_mm bill_depth_mm flipper_length_mm    year&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; bill_length_mm           &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;             -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.444&lt;/span&gt;             0.866  0.096&lt;span style=&#39;text-decoration: underline;&#39;&gt;8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; bill_depth_mm            -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.444&lt;/span&gt;         &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;                -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.579&lt;/span&gt;  0.138 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; flipper_length_mm         0.866         -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.579&lt;/span&gt;            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;      0.105 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; year                      0.096&lt;span style=&#39;text-decoration: underline;&#39;&gt;8&lt;/span&gt;         0.138             0.105 &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To remove the upper triangle and rearrange the results:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;biscoe_cor&lt;/span&gt;  &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;      &lt;span class=&#39;c&#39;&gt;# Take biscoe_cor results&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/rearrange.html&#39;&gt;rearrange&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;    &lt;span class=&#39;c&#39;&gt;# Rearrange based on correlation strengths&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/shave.html&#39;&gt;shave&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;        &lt;span class=&#39;c&#39;&gt;# Remove the upper triangle&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/fashion.html&#39;&gt;fashion&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;          &lt;span class=&#39;c&#39;&gt;# Remove NAs&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                term flipper_length_mm bill_length_mm year bill_depth_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 flipper_length_mm                                                    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2    bill_length_mm               .87                                  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3              year               .11            .10                   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4     bill_depth_mm              -.58           -.44  .14&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3---reshaping-and-visualizations&#34;&gt;3 - Reshaping and visualizations&lt;/h2&gt;
&lt;p&gt;The output of the &lt;a href=&#34;https://corrr.tidymodels.org/reference/correlate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;correlate()&lt;/code&gt;&lt;/a&gt; function can also be piped to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&#34;https://corrr.tidymodels.org/reference/focus.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;focus()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://corrr.tidymodels.org/reference/stretch.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;stretch()&lt;/code&gt;&lt;/a&gt; functions to reshape the structure&lt;/li&gt;
&lt;li&gt;And the &lt;a href=&#34;https://corrr.tidymodels.org/reference/rplot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;rplot()&lt;/code&gt;&lt;/a&gt;, and &lt;a href=&#34;https://corrr.tidymodels.org/reference/network_plot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;network_plot()&lt;/code&gt;&lt;/a&gt; for visualizations.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Reshape structure&lt;/em&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&#34;https://corrr.tidymodels.org/reference/focus.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;focus()&lt;/code&gt;&lt;/a&gt; function select columns or rows based on the variable specified.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&#34;https://corrr.tidymodels.org/reference/stretch.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;stretch()&lt;/code&gt;&lt;/a&gt; converts correction results from a tibble into a long format.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Visualizations&lt;/em&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The &lt;a href=&#34;https://corrr.tidymodels.org/reference/rplot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;rplot()&lt;/code&gt;&lt;/a&gt; function plots correlation results&lt;/li&gt;
&lt;li&gt;The &lt;a href=&#34;https://corrr.tidymodels.org/reference/network_plot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;network_plot()&lt;/code&gt;&lt;/a&gt; function plots a point for each variable, joined by paths for correlations&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let use the &lt;a href=&#34;https://corrr.tidymodels.org/reference/stretch.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;stretch()&lt;/code&gt;&lt;/a&gt; function to convert our correlation results &lt;code&gt;penguins_cor&lt;/code&gt; into a long format:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_cor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/stretch.html&#39;&gt;stretch&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 16 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    x                 y                      r&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; bill_length_mm    bill_length_mm    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; bill_length_mm    bill_depth_mm     -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.235&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; bill_length_mm    flipper_length_mm  0.656&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; bill_length_mm    body_mass_g        0.595&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; bill_depth_mm     bill_length_mm    -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.235&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; bill_depth_mm     bill_depth_mm     &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; bill_depth_mm     flipper_length_mm -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.584&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; bill_depth_mm     body_mass_g       -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.472&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; flipper_length_mm bill_length_mm     0.656&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; flipper_length_mm bill_depth_mm     -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.584&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;11&lt;/span&gt; flipper_length_mm flipper_length_mm &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;12&lt;/span&gt; flipper_length_mm body_mass_g        0.871&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;13&lt;/span&gt; body_mass_g       bill_length_mm     0.595&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;14&lt;/span&gt; body_mass_g       bill_depth_mm     -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.472&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;15&lt;/span&gt; body_mass_g       flipper_length_mm  0.871&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;16&lt;/span&gt; body_mass_g       body_mass_g       &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can see that the results are coverted into a long format.&lt;/p&gt;
&lt;p&gt;We can also select a column we are interested in. Let us select only correlation between &amp;ldquo;bill_depth_mm&amp;rdquo; and the rest of the variables.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_cor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/focus.html&#39;&gt;focus&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   term              bill_depth_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; bill_length_mm           -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.235&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; flipper_length_mm        -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.584&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; body_mass_g              -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.472&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can see that we selected only the correlations between &lt;code&gt;bill_depth_mm&lt;/code&gt; and other variables.&lt;/p&gt;
&lt;p&gt;We can now visualize the results:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_cor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/rearrange.html&#39;&gt;rearrange&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Rearrange based on correlation strengths&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/rplot.html&#39;&gt;rplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;           &lt;span class=&#39;c&#39;&gt;# Plot&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Don&#39;t know how to automatically pick scale for object of type noquote. Defaulting to continuous.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-15-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;We plotted based on correlation strengths.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h2 id=&#34;breakout-session-2&#34;&gt;Breakout session 2&lt;/h2&gt;
&lt;p&gt;Use the dataframe (&lt;code&gt;penguins_biscoe&lt;/code&gt;) you created in Breakout session 1 to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Calculate correlations among the variables, and present the results in a long format&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Select the correlations that include &lt;code&gt;year&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Plot a correlation graph based on correlation strengths&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;biscoe_cor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_biscoe&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/correlate.html&#39;&gt;correlate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Correlation method: &#39;pearson&#39;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Missing treated using: &#39;pairwise.complete.obs&#39;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;biscoe_cor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/stretch.html&#39;&gt;stretch&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 16 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    x                 y                       r&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; bill_length_mm    bill_length_mm    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; bill_length_mm    bill_depth_mm     -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.444&lt;/span&gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; bill_length_mm    flipper_length_mm  0.866 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; bill_length_mm    year               0.096&lt;span style=&#39;text-decoration: underline;&#39;&gt;8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; bill_depth_mm     bill_length_mm    -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.444&lt;/span&gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; bill_depth_mm     bill_depth_mm     &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; bill_depth_mm     flipper_length_mm -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.579&lt;/span&gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; bill_depth_mm     year               0.138 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; flipper_length_mm bill_length_mm     0.866 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; flipper_length_mm bill_depth_mm     -&lt;span style=&#39;color: #BB0000;&#39;&gt;0.579&lt;/span&gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;11&lt;/span&gt; flipper_length_mm flipper_length_mm &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;12&lt;/span&gt; flipper_length_mm year               0.105 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;13&lt;/span&gt; year              bill_length_mm     0.096&lt;span style=&#39;text-decoration: underline;&#39;&gt;8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;14&lt;/span&gt; year              bill_depth_mm      0.138 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;15&lt;/span&gt; year              flipper_length_mm  0.105 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;16&lt;/span&gt; year              year              &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can see that results are in a long format.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;biscoe_cor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
   &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/focus.html&#39;&gt;focus&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   term                year&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; bill_length_mm    0.096&lt;span style=&#39;text-decoration: underline;&#39;&gt;8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; bill_depth_mm     0.138 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; flipper_length_mm 0.105&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Correlations with &lt;code&gt;year&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;biscoe_cor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/rearrange.html&#39;&gt;rearrange&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://corrr.tidymodels.org/reference/rplot.html&#39;&gt;rplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Don&#39;t know how to automatically pick scale for object of type noquote. Defaulting to continuous.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-18-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
</description>
    </item>
    
    <item>
      <title>S03E03: Principal Component Analysis (PCA)</title>
      <link>https://biodash.github.io/codeclub/s03e03_pca/</link>
      <pubDate>Tue, 08 Feb 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s03e03_pca/</guid>
      <description>&lt;figure&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=PCA.png width=&#34;75%&#34;&gt;
&lt;figcaption&gt;
A PCA of genetic variation among Europeans, from &lt;a href=&#34;https://www.nature.com/articles/nature07331&#34;&gt;Novembre et al 2008&lt;/a&gt;: &#34;Genes mirror geography within Europe&#34;
&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;hr&gt;
&lt;h2 id=&#34;housekeeping&#34;&gt;Housekeeping&lt;/h2&gt;
&lt;h4 id=&#34;new-to-code-club&#34;&gt;New to Code Club?&lt;/h4&gt;
&lt;p&gt;Check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio. A few related Code Club sessions include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e01_ttests/&#34;&gt;S03E01&lt;/a&gt;: T-tests&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e02_anova/&#34;&gt;S03E02&lt;/a&gt;: ANOVA&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e06_ggplot2/&#34;&gt;S02E06&lt;/a&gt;: Intro to &lt;em&gt;ggplot2&lt;/em&gt;, part I&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e07_ggplot2_part2/&#34;&gt;S02E07&lt;/a&gt;: Intro to &lt;em&gt;ggplot2&lt;/em&gt;, part II&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;session-goals&#34;&gt;Session goals&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Learn &lt;strong&gt;how to perform a PCA&lt;/strong&gt; in R using the &lt;a href=&#34;https://rdrr.io/r/stats/prcomp.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;prcomp()&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Understand what is represented by the &lt;strong&gt;different components of the output&lt;/strong&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Learn about &lt;strong&gt;three kinds of plots&lt;/strong&gt; commonly used to visualize PCA results, and how to create them.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;r-packages-we-will-use&#34;&gt;R packages we will use&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;palmerpenguins&lt;/em&gt; &amp;ndash; A data package containing the data we will explore&lt;/li&gt;
&lt;li&gt;&lt;em&gt;tidyverse&lt;/em&gt; &amp;ndash; A metapackage that includes &lt;em&gt;ggplot2&lt;/em&gt; which we&amp;rsquo;ll use for plotting, access to the &lt;code&gt;%&amp;gt;%&lt;/code&gt; pipe, etc.&lt;/li&gt;
&lt;li&gt;&lt;em&gt;broom&lt;/em&gt; &amp;ndash; We&amp;rsquo;ll again use the &lt;a href=&#34;https://generics.r-lib.org/reference/tidy.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tidy()&lt;/code&gt;&lt;/a&gt; function in &lt;em&gt;broom&lt;/em&gt; to create tidy dataframes from untidy statistical function output&lt;/li&gt;
&lt;li&gt;&lt;em&gt;glue&lt;/em&gt; &amp;ndash; For pasting strings with variables&lt;/li&gt;
&lt;li&gt;&lt;em&gt;factoextra&lt;/em&gt; &amp;ndash; For easily creating a PCA biplot (and other PCA plots)&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;getting-set-up&#34;&gt;Getting set up&lt;/h4&gt;
&lt;p&gt;&lt;em&gt;If you plan to just listen during the first part,&lt;/em&gt; &lt;em&gt;you can wait until the Breakout Rooms to do the following.&lt;/em&gt; &lt;em&gt;Also, instead of copying-and-pasting code, you could download this&lt;/em&gt; &lt;em&gt;&lt;a href=&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/S03E03_PCA/S03E03_PCA.R&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R script&lt;/a&gt;&lt;/em&gt; &lt;em&gt;with today&amp;rsquo;s code.&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Open a new R script in RStudio (&lt;code&gt;File&lt;/code&gt; =&amp;gt; &lt;code&gt;New File&lt;/code&gt; =&amp;gt; &lt;code&gt;R Script&lt;/code&gt;)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Save the script, as something along the lines of &lt;code&gt;codeclub_S03E03_PCA.R&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Copy the following code into the script, for installing packages where needed:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## `require(glue)` returns FALSE if glue isn&#39;t installed; therefore,&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## these lines will only try to install packages that aren&#39;t already installed.&lt;/span&gt;
  &lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://broom.tidymodels.org/&#39;&gt;broom&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;broom&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidyverse/glue&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;glue&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://www.sthda.com/english/rpkgs/factoextra&#39;&gt;factoextra&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;factoextra&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Also copy the following code to load the packages into your R session:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://broom.tidymodels.org/&#39;&gt;broom&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidyverse/glue&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://www.sthda.com/english/rpkgs/factoextra&#39;&gt;factoextra&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run the code above in the R console.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---a-brief-intro-to-pca&#34;&gt;1 - A brief intro to PCA&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Principal Component Analysis (PCA)&lt;/strong&gt; is a popular method that creates &lt;em&gt;&amp;ldquo;summary variables&amp;rdquo; (Principal Components)&lt;/em&gt; which represent as much of the information as possible from a high-dimensional dataset.&lt;/p&gt;
&lt;p&gt;A &lt;em&gt;high-dimensional dataset&lt;/em&gt; is a dataset with measurements for many variables, such as expression levels for thousands of genes.&lt;/p&gt;
&lt;p&gt;PCA and similar methods like PCoA and nMDS (see box below) are also called &amp;ldquo;&lt;strong&gt;dimension reduction&lt;/strong&gt;&amp;rdquo; or &amp;ldquo;&lt;strong&gt;ordination&lt;/strong&gt;&amp;rdquo; methods, and can be classified as a type of &lt;em&gt;unsupervised learning&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;PCA is most commonly used for &lt;strong&gt;exploratory data visualization&lt;/strong&gt; to see overall patterns in datasets, though you could also use the resulting Principal Components as response variables in a statistical model.&lt;/p&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;glossary&#34;&gt;Glossary&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Principal Components (PCs)&lt;/strong&gt; &amp;ndash; the summary variables that a PCA produces.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Loadings&lt;/strong&gt; (&lt;em&gt;rotations&lt;/em&gt;) &amp;ndash; Loadings apply to the &lt;em&gt;original variables&lt;/em&gt;. They are the contributions of variables to PCs, which form the &amp;ldquo;recipes&amp;rdquo; used to create the PCs.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Scores&lt;/strong&gt; (&lt;em&gt;coordinates&lt;/em&gt;) &amp;ndash; Scores apply to the &lt;em&gt;samples&lt;/em&gt;. These scores, for each PC, are coordinates that can be used to create a score plot which is the &amp;ldquo;classic&amp;rdquo; PCA plot.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Eigenvalue&lt;/strong&gt; &amp;ndash; The variance (amount of variation) explained by a PC.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;similar-ordination-methods&#34;&gt;Similar ordination methods&lt;/h4&gt;
&lt;p&gt;Besides PCA, other commonly used ordination methods that are also unconstrained (i.e., with no response variable) include the following:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Principal Coordinate Analysis&lt;/em&gt; (&lt;strong&gt;PCoA&lt;/strong&gt;) is also known as &lt;em&gt;Metric Multidimensional Scaling&lt;/em&gt; (&lt;strong&gt;MDS&lt;/strong&gt; / mMDS). PCoA allows you to use distance measures other than Euclidean distance and can be run e.g. with &lt;a href=&#34;https://rdrr.io/r/stats/cmdscale.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;stats::cmdscale()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Non-metric Multidimensional Scaling&lt;/em&gt; (&lt;strong&gt;nMDS&lt;/strong&gt;) is a non-metric method with quite different inner workings from PCA and PCoA that is especially suitable when your distance values are imprecise. It can be run e.g. with &lt;a href=&#34;https://rdrr.io/pkg/vegan/man/metaMDS.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;vegan::metaMDS()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you&amp;rsquo;re struggling to pick a suitable ordination approach for your data, take a look at &lt;a href=&#34;https://journals.plos.org/ploscompbiol/article/figure?id=10.1371/journal.pcbi.1006907.t001&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Table 1&lt;/a&gt; in &lt;a href=&#34;https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1006907&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Nguyen &amp;amp; Holmes 2019&lt;/a&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2---prcomp-scaling-and-centering&#34;&gt;2 - &lt;code&gt;prcomp()&lt;/code&gt;, scaling, and centering&lt;/h2&gt;
&lt;p&gt;To perform a PCA analysis in R, there are two functions that can be used without the need to load any packages: &lt;a href=&#34;https://rdrr.io/r/stats/prcomp.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;prcomp()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://rdrr.io/r/stats/princomp.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;princomp()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;(Like last week&amp;rsquo;s &lt;a href=&#34;https://rdrr.io/r/stats/aov.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;aov()&lt;/code&gt;&lt;/a&gt; function, these functions are in the &lt;em&gt;stats&lt;/em&gt; package, which is loaded into your R session by default. More PCA functions are available in other packages but these tend to be very similar and/or simply wrap the two base R functions.)&lt;/p&gt;
&lt;p&gt;We will use &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/stats/prcomp.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;prcomp()&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;, which is preferred among these two due to its slightly better accuracy&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;h4 id=&#34;two-important-data-pre-processing-steps&#34;&gt;Two important data pre-processing steps&amp;hellip;&lt;/h4&gt;
&lt;p&gt;&amp;hellip;need to be done for many PCA analyses. Luckily, these can be done alongside the PCA computation in a single call to &lt;a href=&#34;https://rdrr.io/r/stats/prcomp.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;prcomp()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Centering the data&lt;/strong&gt; &amp;ndash; &lt;em&gt;Centering&lt;/em&gt; the data around the origin (subtracting the mean of variables) is basically always advisable and is controlled by the &lt;code&gt;center&lt;/code&gt; argument of &lt;a href=&#34;https://rdrr.io/r/stats/prcomp.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;prcomp()&lt;/code&gt;&lt;/a&gt;, which is &lt;em&gt;set to &lt;code&gt;TRUE&lt;/code&gt; by default&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Scaling the data&lt;/strong&gt; &amp;ndash; Standardizing the standard deviation across the variables in the data (i.e., scaling) is advisable when variables are in different units or on different scales but is generally not recommended when all variables are of the same type and in the same units (e.g., gene counts&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;). Whether or not to scale the data is controlled by the &lt;code&gt;scale.&lt;/code&gt; argument of &lt;a href=&#34;https://rdrr.io/r/stats/prcomp.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;prcomp()&lt;/code&gt;&lt;/a&gt;, which is &lt;em&gt;set to &lt;code&gt;FALSE&lt;/code&gt; by default&lt;/em&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3---our-first-pca&#34;&gt;3 - Our first PCA&lt;/h2&gt;
&lt;p&gt;As a simple example, we want to &lt;em&gt;run a PCA summarizing the four numerical measurements taken for each penguin&lt;/em&gt; (bill length, bill depth, flipper length, and body mass) in the &lt;em&gt;palmerpenguins&lt;/em&gt; dataset.&lt;/p&gt;
&lt;p&gt;First, we&amp;rsquo;ll subset the &lt;code&gt;penguins&lt;/code&gt; dataframe to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Remove rows with &lt;code&gt;NA&lt;/code&gt;s (&lt;a href=&#34;https://rdrr.io/r/stats/prcomp.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;prcomp()&lt;/code&gt;&lt;/a&gt; will return an error if any of our variables contain &lt;code&gt;NA&lt;/code&gt;s)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Select only the columns that we want to include in the PCA&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Remove rows with NAs&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Select columns&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_for_pca&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s take a look at the resulting dataframe:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_for_pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;           39.1          18.7               181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;750&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;           39.5          17.4               186        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;800&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;           40.3          18                 195        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;250&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;           36.7          19.3               193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;450&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;           39.3          20.6               190        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;650&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;           38.9          17.8               181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;625&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_for_pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 333   4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id=&#34;run-the-pca&#34;&gt;Run the PCA!&lt;/h4&gt;
&lt;p&gt;Now, we are ready to run the PCA:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/prcomp.html&#39;&gt;prcomp&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_for_pca&lt;/span&gt;, scale &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# (Because `center = TRUE` by default, we don&#39;t have to include that.)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Scaling is desirable here because as we saw above, the variables we use in our PCA are in different units (&lt;code&gt;mm&lt;/code&gt; and &lt;code&gt;g&lt;/code&gt;).&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;More on scaling&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Because our variables are in different units, standard deviations for those variables may differ dramatically. This would lead the PCA to put more weight on variables with a higher standard deviation, which we don&amp;rsquo;t want if those differences are merely a consequence of different units.&lt;/p&gt;
&lt;p&gt;If we check the standard deviations in our dataset, we can indeed see large differences:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;map&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_for_pca&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;sd&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $bill_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5.468668&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $bill_depth_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1.969235&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $flipper_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 14.01577&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 805.2158&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4---exploring-the-output-i&#34;&gt;4 - Exploring the output I&lt;/h2&gt;
&lt;p&gt;Like with objects returned by the statistical tests we saw in the previous weeks, the object returned by &lt;a href=&#34;https://rdrr.io/r/stats/prcomp.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;prcomp()&lt;/code&gt;&lt;/a&gt; is not just a dataframe or even a regular list&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;prcomp&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&amp;hellip; and trying to print the object to screen will only give you a summary of sorts:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Standard deviations (1, .., p=4):&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1.6569115 0.8821095 0.6071594 0.3284579&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rotation (n x k) = (4 x 4):&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                          PC1         PC2        PC3        PC4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; bill_length_mm     0.4537532 -0.60019490 -0.6424951  0.1451695&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; bill_depth_mm     -0.3990472 -0.79616951  0.4258004 -0.1599044&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; flipper_length_mm  0.5768250 -0.00578817  0.2360952 -0.7819837&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; body_mass_g        0.5496747 -0.07646366  0.5917374  0.5846861&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Like we saw last week with &lt;a href=&#34;https://rdrr.io/r/stats/aov.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;aov()&lt;/code&gt;&lt;/a&gt;, we can get a more useful summary of the results with the &lt;a href=&#34;https://rdrr.io/r/base/summary.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summary()&lt;/code&gt;&lt;/a&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/summary.html&#39;&gt;summary&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Importance of components:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                           PC1    PC2     PC3     PC4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Standard deviation     1.6569 0.8821 0.60716 0.32846&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Proportion of Variance 0.6863 0.1945 0.09216 0.02697&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Cumulative Proportion  0.6863 0.8809 0.97303 1.00000&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This shows us the &amp;ldquo;importance&amp;rdquo; of the 4 principal components that our PCA returned, i.e. the amount of variation they explain.&lt;/p&gt;
&lt;h4 id=&#34;seeing-all-elements-with-str&#34;&gt;Seeing all elements with &lt;code&gt;str()&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;These summaries are nice and all, but like we saw in previous weeks, they don&amp;rsquo;t make it obvious where and how to access &lt;em&gt;all&lt;/em&gt; the information contained in the object.&lt;/p&gt;
&lt;p&gt;Running the &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; function is a good start for getting to the raw contents of the object, even though the information printed isn&amp;rsquo;t easy to look at:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ sdev    : num [1:4] 1.657 0.882 0.607 0.328&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ rotation: num [1:4, 1:4] 0.454 -0.399 0.577 0.55 -0.6 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;dimnames&#34;)=List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ : chr [1:4] &#34;bill_length_mm&#34; &#34;bill_depth_mm&#34; &#34;flipper_length_mm&#34; &#34;body_mass_g&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ : chr [1:4] &#34;PC1&#34; &#34;PC2&#34; &#34;PC3&#34; &#34;PC4&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ center  : Named num [1:4] 44 17.2 201 4207.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr [1:4] &#34;bill_length_mm&#34; &#34;bill_depth_mm&#34; &#34;flipper_length_mm&#34; &#34;body_mass_g&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ scale   : Named num [1:4] 5.47 1.97 14.02 805.22&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr [1:4] &#34;bill_length_mm&#34; &#34;bill_depth_mm&#34; &#34;flipper_length_mm&#34; &#34;body_mass_g&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ x       : num [1:333, 1:4] -1.85 -1.31 -1.37 -1.88 -1.92 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;dimnames&#34;)=List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ : NULL&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ : chr [1:4] &#34;PC1&#34; &#34;PC2&#34; &#34;PC3&#34; &#34;PC4&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  - attr(*, &#34;class&#34;)= chr &#34;prcomp&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In the first breakout room session, you&amp;rsquo;ll explore the contents of our &lt;code&gt;pca&lt;/code&gt; object a bit more.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-i&#34;&gt;Breakout Rooms I&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;If you didn&amp;rsquo;t do so already, get set up for the remaining exercises. Either &lt;a href=&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/S03E03_PCA/S03E03_PCA.R&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;download this R script&lt;/a&gt;, open it in RStudio, and run the code, or:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Open a new R script in RStudio (&lt;code&gt;File&lt;/code&gt; =&amp;gt; &lt;code&gt;New File&lt;/code&gt; =&amp;gt; &lt;code&gt;R Script&lt;/code&gt;)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Save the script, as something along the lines of &lt;code&gt;codeclub_S03E03_PCA.R&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Copy the following code into the script and then run it in the R console:&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Install packages if needed&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;## (`require(glue)` returns FALSE if glue isn&#39;t installed; therefore,&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;##  these lines will only try to install packages that aren&#39;t already installed.)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://broom.tidymodels.org/&#39;&gt;broom&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;broom&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidyverse/glue&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;glue&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;require&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://www.sthda.com/english/rpkgs/factoextra&#39;&gt;factoextra&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;factoextra&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Load the packages into your R session&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://broom.tidymodels.org/&#39;&gt;broom&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidyverse/glue&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://www.sthda.com/english/rpkgs/factoextra&#39;&gt;factoextra&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Prep the penguin data for the PCA&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_for_pca&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Run the PCA&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/prcomp.html&#39;&gt;prcomp&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_for_pca&lt;/span&gt;, scale &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;p&gt;How can you access the different components in the &lt;code&gt;List of 5&lt;/code&gt; that is summarized when running &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str(pca)&lt;/code&gt;&lt;/a&gt;? For example, say you wanted to see the &lt;code&gt;rotation&lt;/code&gt; element in its entirety, how could you do this?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;The &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Extract.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;$&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; (dollar sign) operator can be used to access the different elements (as implied by the dollar signs shown in front of the names of the elements).&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;To see the &lt;code&gt;rotation&lt;/code&gt; element, type &lt;strong&gt;&lt;code&gt;pca$rotation&lt;/code&gt;&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rotation&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                          PC1         PC2        PC3        PC4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; bill_length_mm     0.4537532 -0.60019490 -0.6424951  0.1451695&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; bill_depth_mm     -0.3990472 -0.79616951  0.4258004 -0.1599044&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; flipper_length_mm  0.5768250 -0.00578817  0.2360952 -0.7819837&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; body_mass_g        0.5496747 -0.07646366  0.5917374  0.5846861&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-3-bonus&#34;&gt;Exercise 3 (bonus)&lt;/h3&gt;
&lt;p&gt;Take a look at the contents of all five elements in the &lt;code&gt;pca&lt;/code&gt; object. Do you have a (rough) understanding of what each represents?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Take a look at the &lt;a href=&#34;#glossary&#34;&gt;Glossary&lt;/a&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;All elements of the output are explained in the next section of this page.&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;5---exploring-the-output-ii&#34;&gt;5 - Exploring the output II&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s take a quick look together at the three most important elements in the object returned by &lt;a href=&#34;https://rdrr.io/r/stats/prcomp.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;prcomp()&lt;/code&gt;&lt;/a&gt;, which we named &lt;code&gt;pca&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pca$sdev&lt;/code&gt;&lt;/strong&gt; is a vector of standard deviations associated with each principal component (PC), i.e. it is the &lt;strong&gt;amount of variation explained by each PC&lt;/strong&gt;. We also saw this information when running &lt;a href=&#34;https://rdrr.io/r/base/summary.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summary(pca)&lt;/code&gt;&lt;/a&gt; and we&amp;rsquo;ll use it to create the &lt;em&gt;scree plot&lt;/em&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sdev&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1.6569115 0.8821095 0.6071594 0.3284579&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pca$x&lt;/code&gt;&lt;/strong&gt; is the most-used part of the output: a matrix containing the &lt;strong&gt;scores (or coordinates)&lt;/strong&gt; for each sample for each PC, used to create a &lt;em&gt;score plot&lt;/em&gt; and part of the &lt;em&gt;biplot&lt;/em&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt;            PC1         PC2         PC3        PC4&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt; [1,] -1.850808 -0.03202119  0.23454869  0.5276026&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt; [2,] -1.314276  0.44286031  0.02742880  0.4011230&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt; [3,] -1.374537  0.16098821 -0.18940423 -0.5278675&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt; [4,] -1.882455  0.01233268  0.62792772 -0.4721826&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt; [5,] -1.917096 -0.81636958  0.69999797 -0.1961213&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt; [6,] -1.770356  0.36567266 -0.02841769  0.5046092&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pca$rotation&lt;/code&gt;&lt;/strong&gt; is a matrix that contains the &lt;strong&gt;loadings&lt;/strong&gt; for each variable in each PC. These are the &amp;ldquo;recipes&amp;rdquo; for creating each PC, with &lt;em&gt;higher absolute values&lt;/em&gt; indicating a larger effect of the variable on the PC. The &lt;em&gt;sign&lt;/em&gt; (- or +) matters too: in PC1, larger values of &lt;code&gt;bill_depth_mm&lt;/code&gt; lower the PC value, and vice versa for the other three variables. This matrix will be used in creating the &lt;em&gt;biplot&lt;/em&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rotation&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt;                          PC1         PC2        PC3        PC4&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt; bill_length_mm     0.4537532 -0.60019490 -0.6424951  0.1451695&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt; bill_depth_mm     -0.3990472 -0.79616951  0.4258004 -0.1599044&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt; flipper_length_mm  0.5768250 -0.00578817  0.2360952 -0.7819837&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt; body_mass_g        0.5496747 -0.07646366  0.5917374  0.5846861&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;...And the remaining two elements&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pca$center&lt;/code&gt;&lt;/strong&gt; is a vector containing the means for each variable, which was subsequently used for centering the data (this would contain just &lt;code&gt;FALSE&lt;/code&gt; if the data wasn&amp;rsquo;t centered).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;center&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt;    bill_length_mm     bill_depth_mm flipper_length_mm       body_mass_g &lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt;          43.99279          17.16486         200.96697        4207.05706&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;pca$scale&lt;/code&gt;&lt;/strong&gt; similarly is a vector containing the scaling constant for each variable (column) in the data, and would be &lt;code&gt;FALSE&lt;/code&gt; if the data wasn&amp;rsquo;t scaled.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;scale&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt;    bill_length_mm     bill_depth_mm flipper_length_mm       body_mass_g &lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#&amp;gt;          5.468668          1.969235         14.015765        805.215802&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;6---scree-plot&#34;&gt;6 - Scree plot&lt;/h2&gt;
&lt;p&gt;A &amp;ldquo;scree plot&amp;rdquo;&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt; is a barplot that shows the &lt;strong&gt;amount of variation explained by each PC.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll make a base R version of this plot (gasp!) because it is so quick to make, and we don&amp;rsquo;t need this figure to be fancy:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/plot.default.html&#39;&gt;plot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-18-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In this scree plot, we show the variance (i.e. the &lt;em&gt;eigenvalue&lt;/em&gt;) associated with each PC (these are the square roots of the standard deviations in &lt;code&gt;pca$sdev&lt;/code&gt;.)&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;interpretation&#34;&gt;Interpretation&lt;/h4&gt;
&lt;p&gt;This gives us a quick visual overview of the importance of the PCs: PC1 is &lt;em&gt;by far&lt;/em&gt; the most important, and PC4 doesn&amp;rsquo;t do much at all. (PCs are always ordered by the amount of variation they explain, with PC1 explaining most.)&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;7---score-classic-pca-plot&#34;&gt;7 - Score (classic PCA) plot&lt;/h2&gt;
&lt;p&gt;A &amp;ldquo;score plot&amp;rdquo; shows &lt;strong&gt;the scores (coordinates) for each sample along two PCs&lt;/strong&gt;, typically the first two.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;re going to need a dataframe to plot. But if we were to &lt;a href=&#34;https://generics.r-lib.org/reference/tidy.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;broom::tidy()&lt;/code&gt;&lt;/a&gt; the scores matrix (&lt;code&gt;pca$x&lt;/code&gt;), akin to what we&amp;rsquo;ve done with t-test and ANOVA output in previous weeks, we would get a dataframe with all PCs in one column that wouldn&amp;rsquo;t be that easy to plot.&lt;/p&gt;
&lt;p&gt;So in this case, we&amp;rsquo;ll just manipulate &lt;code&gt;pca$x&lt;/code&gt; ourselves &amp;ndash; in particular, we want to add the source &lt;code&gt;penguins_noNA&lt;/code&gt; dataframe back to it, which will allow us to color the points by, say, &lt;code&gt;species&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Column-bind (= put side-by-side) the scores and the source dataframe&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pca_scores&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;bind_cols&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca_scores&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;         PC1         PC2         PC3        PC4 species    island bill_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 -1.850808 -0.03202119  0.23454869  0.5276026  Adelie Torgersen           39.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 -1.314276  0.44286031  0.02742880  0.4011230  Adelie Torgersen           39.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3 -1.374537  0.16098821 -0.18940423 -0.5278675  Adelie Torgersen           40.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4 -1.882455  0.01233268  0.62792772 -0.4721826  Adelie Torgersen           36.7&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5 -1.917096 -0.81636958  0.69999797 -0.1961213  Adelie Torgersen           39.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6 -1.770356  0.36567266 -0.02841769  0.5046092  Adelie Torgersen           38.9&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   bill_depth_mm flipper_length_mm body_mass_g    sex year&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1          18.7               181        3750   male 2007&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2          17.4               186        3800 female 2007&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3          18.0               195        3250 female 2007&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4          19.3               193        3450 female 2007&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5          20.6               190        3650   male 2007&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6          17.8               181        3625 female 2007&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now we&amp;rsquo;re ready to create the plot:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;score_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca_scores&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;PC1&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;PC2&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;score_plot&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-20-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;interpretation-1&#34;&gt;Interpretation&lt;/h4&gt;
&lt;p&gt;Across these four measurements, Gentoo Penguins can be very clearly distinguished from the other two species, whereas among Adelie and Chinstrap Penguins, there are average differences but they are not fully separable.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;a-better-aspect-ratio&#34;&gt;A better aspect ratio&lt;/h3&gt;
&lt;p&gt;One way to improve our plot is to set the aspect ratio (the proportional relationship between the height and the width) according to the relative percentages of variation explained by the two plotted PCs: because PC1 on the x-axis explains more variation, we want the plot to be wide.&lt;/p&gt;
&lt;p&gt;To get the percentages in a dataframe, now we &lt;em&gt;will&lt;/em&gt; use the &lt;a href=&#34;https://generics.r-lib.org/reference/tidy.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tidy()&lt;/code&gt;&lt;/a&gt; function. But because the output of &lt;a href=&#34;https://rdrr.io/r/stats/prcomp.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;prcomp()&lt;/code&gt;&lt;/a&gt; contains multiple elements, we&amp;rsquo;ll have to point &lt;a href=&#34;https://generics.r-lib.org/reference/tidy.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tidy()&lt;/code&gt;&lt;/a&gt; to the &lt;code&gt;$sdev&lt;/code&gt; element using the &lt;code&gt;matrix&lt;/code&gt; argument (see the &lt;a href=&#34;%28https://broom.tidymodels.org/reference/tidy.prcomp.html%29&#34;&gt;docs&lt;/a&gt;):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pca_eigen&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://generics.r-lib.org/reference/tidy.html&#39;&gt;tidy&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;, matrix &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;eigenvalues&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pca_eigen&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 4 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      PC std.dev percent cumulative&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;     1   1.66   0.686       0.686&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;     2   0.882  0.195       0.881&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;     3   0.607  0.092&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;      0.973&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;     4   0.328  0.027&lt;span style=&#39;text-decoration: underline;&#39;&gt;0&lt;/span&gt;      1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now, we&amp;rsquo;ll store the percentages explained by the first two PCs (rounded to one decimal):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# (Note: pca_eigen$percent contains proportions, not percentages...)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;PC1_percent&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Round.html&#39;&gt;round&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca_eigen&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;percent&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;PC2_percent&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Round.html&#39;&gt;round&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca_eigen&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;percent&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;PC1_percent&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 68.6&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;PC2_percent&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 19.5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Finally, we can modify the aspect ratio, which is expressed as &lt;code&gt;height / width&lt;/code&gt; &amp;ndash; and we&amp;rsquo;ll also move the legend to the top, and add the percentages to the axis titles:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;score_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;score_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;aspect.ratio &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;PC2_percent&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;PC1_percent&lt;/span&gt;,
        legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;top&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;PC1 (&amp;#123;PC1_percent&amp;#125;%)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;PC2 (&amp;#123;PC2_percent&amp;#125;%)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;score_plot&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-23-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;8---biplot&#34;&gt;8 - Biplot&lt;/h2&gt;
&lt;p&gt;A &amp;ldquo;biplot&amp;rdquo; shows the &lt;strong&gt;scores of samples for two PCs &lt;em&gt;and&lt;/em&gt; the loadings for the original variables&lt;/strong&gt; along the two PCs.&lt;/p&gt;
&lt;p&gt;Because biplots are more complicated to make &amp;ldquo;from scratch&amp;rdquo; using &lt;em&gt;ggplot2&lt;/em&gt;, we will turn to the package &lt;em&gt;factoextra&lt;/em&gt;, which has a convenient function for making biplots, &lt;a href=&#34;https://rdrr.io/pkg/factoextra/man/fviz_pca.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fviz_pca()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/factoextra/man/fviz_pca.html&#39;&gt;fviz_pca&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;,
         label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;var&#34;&lt;/span&gt;,                       &lt;span class=&#39;c&#39;&gt;# Show labels for variables only&lt;/span&gt;
         habillage &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# color by / shape by&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;top&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-24-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;While this plot can certainly be improved upon, &lt;em&gt;biplots are by their nature a little unwieldy&lt;/em&gt;.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;interpretation-2&#34;&gt;Interpretation&lt;/h4&gt;
&lt;p&gt;Biplots can be especially useful when you have a modest number of original variables, like here. Some information we can glean from this particular biplot:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Flipper length and body mass are highly correlated among individuals, even across species. So flipper length relative to body mass is similar across species.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Gentoo penguins are larger and with narrower bills than the other two species.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;While we made a scree plot with base R and a score plot with &amp;ldquo;base &lt;em&gt;ggplot2&lt;/em&gt;&amp;rdquo;, there are also &lt;em&gt;factoextra&lt;/em&gt; functions for these and for other PCA plots:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/pkg/factoextra/man/eigenvalue.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fviz_eig()&lt;/code&gt;&lt;/a&gt; &amp;ndash; scree plots&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/pkg/factoextra/man/fviz_pca.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fviz_pca_ind()&lt;/code&gt;&lt;/a&gt; &amp;ndash; score plots&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/pkg/factoextra/man/fviz_pca.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fviz_pca_var()&lt;/code&gt;&lt;/a&gt; &amp;ndash; &amp;ldquo;correlation circles&amp;rdquo;; plots showing loadings only (&lt;a href=&#34;https://journals.plos.org/ploscompbiol/article/figure?id=10.1371/journal.pcbi.1006907.g003&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;example&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/pkg/factoextra/man/fviz_contrib.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fviz_contrib()&lt;/code&gt;&lt;/a&gt; &amp;ndash; a barplot with the contribution of variables to 1 PC (&lt;a href=&#34;https://journals.plos.org/ploscompbiol/article/figure?id=10.1371/journal.pcbi.1006907.g003&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;example&lt;/a&gt;).&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Or, to create a biplot from scratch...&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;First, let&amp;rsquo;s save the loadings in a dataframe:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pca_loadings&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rotation&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;rownames_to_column&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;var&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Next, we start with the score plot object &lt;code&gt;score_plot&lt;/code&gt; we created above.&lt;/p&gt;
&lt;p&gt;What we need to add are the variable loading, which we&amp;rsquo;ll do with &lt;code&gt;geom_segment()&lt;/code&gt; to draw arrows, and &lt;code&gt;geom_text()&lt;/code&gt; to add text labels near the tips of the arrows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## To make the arrows longer (all by the same amount),&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;## just to improve the visualization, we use a multiplication factor:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mult&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2.5&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;score_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## geom_segment draws lines&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_segment&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pca_loadings&lt;/span&gt;,
               &lt;span class=&#39;c&#39;&gt;## The lines should start from the origin:&lt;/span&gt;
               &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, xend &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;PC1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mult&lt;/span&gt;, yend &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;PC2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mult&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
               &lt;span class=&#39;c&#39;&gt;## We turn the line into an arrow:&lt;/span&gt;
               arrow &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;arrow&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
               &lt;span class=&#39;c&#39;&gt;## A gray-tone might work better than black:&lt;/span&gt;
               color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;grey40&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pca_loadings&lt;/span&gt;,
            &lt;span class=&#39;c&#39;&gt;## The text labels go at the end of the arrows:&lt;/span&gt;
            &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;PC1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mult&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;PC2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mult&lt;/span&gt;, label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;var&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
            &lt;span class=&#39;c&#39;&gt;## We left-align (hjust = 0) and lower (vjust = 1) the labels&lt;/span&gt;
            hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, vjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,
            &lt;span class=&#39;c&#39;&gt;## Again, we use a gray color:&lt;/span&gt;
            color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;grey40&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-26-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-ii&#34;&gt;Breakout Rooms II&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;p&gt;Above, we plotted the scores for the first two PCs (PC1 and PC2) in our score plot and biplot. Now, create a biplot with another combination of two PCs.&lt;/p&gt;
&lt;p&gt;Take a look at the help for the &lt;a href=&#34;https://rdrr.io/pkg/factoextra/man/fviz_pca.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fviz_pca()&lt;/code&gt;&lt;/a&gt; function by typing&lt;br&gt;
&lt;a href=&#34;https://rdrr.io/pkg/factoextra/man/fviz_pca.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;?fviz_pca&lt;/code&gt;&lt;/a&gt; to find out how you might be able to plot different PCs.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The &lt;code&gt;axes&lt;/code&gt; argument to &lt;a href=&#34;https://rdrr.io/pkg/factoextra/man/fviz_pca.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fviz_pca()&lt;/code&gt;&lt;/a&gt; controls which axes will be plotted; this argument accepts a vector of two numbers.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Do you think it would be worth plotting PC4, which explains &amp;lt;3% of the variation? Would plotting PC3 with one of the PCs we already plotted be informative?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;To plot PC1 &amp;amp; PC3 (which may be a better choice than including PC4 because it explains so little variation):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/factoextra/man/fviz_pca.html&#39;&gt;fviz_pca&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;,
         axes &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
         label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;var&#34;&lt;/span&gt;,
         habillage &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;top&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-27-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Behold, now we can distinguish much better between Adelie and Chinstrap Penguins!&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-5&#34;&gt;Exercise 5&lt;/h3&gt;
&lt;p&gt;Run the PCA for just one of the three penguin species.&lt;/p&gt;
&lt;p&gt;Then, make a biplot of the results, in which you color the points by something else than &lt;code&gt;species&lt;/code&gt;, e.g. by &lt;code&gt;sex&lt;/code&gt;. (If you want, also make a scree plot and/or a score plot.)&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use the &lt;em&gt;dplyr&lt;/em&gt; function &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; on the &lt;code&gt;penguins_noNA&lt;/code&gt; object to select rows corresponding to one penguin species.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After that, the code will be nearly identical to that used before; just make sure to refer to the correct objects if you copy-and-paste code.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;This example solution runs a PCA for &lt;em&gt;Gentoo Penguins only&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;First, select rows corresponding to our focal penguin species, and run the PCA:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## (Save this object rather than using one pipeline,&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;## because you&#39;ll need it color the biplot by a factor)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;onepenguin_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Gentoo&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;onepenguin_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/prcomp.html&#39;&gt;prcomp&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;scale &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Next, we create the biplot:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/factoextra/man/fviz_pca.html&#39;&gt;fviz_pca&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;,
         label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;var&#34;&lt;/span&gt;,
         habillage &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;onepenguin_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;top&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-29-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;To create a scree plot:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/graphics/plot.default.html&#39;&gt;plot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-30-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Or a scree plot with &lt;a href=&#34;https://rdrr.io/pkg/factoextra/man/eigenvalue.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fviz_eig()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/factoextra/man/eigenvalue.html&#39;&gt;fviz_eig&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-31-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;To create a quick score plot (no aspect ratio manipulation):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;bind_cols&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;onepenguin_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;PC1&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;PC2&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-32-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Or a score plot with &lt;a href=&#34;https://rdrr.io/pkg/factoextra/man/fviz_pca.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fviz_pca_ind()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/factoextra/man/fviz_pca.html&#39;&gt;fviz_pca_ind&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca&lt;/span&gt;, geom &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;point&#34;&lt;/span&gt;, habillage &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;onepenguin_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-33-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-6-bonus&#34;&gt;Exercise 6 (bonus)&lt;/h3&gt;
&lt;p&gt;Make a scree plot of our original PCA results with &lt;em&gt;ggplot2&lt;/em&gt; instead of base R.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use the &lt;code&gt;pca_eigen&lt;/code&gt; dataframe that we created above for plotting, and use the geom &lt;code&gt;geom_col()&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Think about what exactly you want to plot on the y-axis. The variance, like in the base R scree plot? Or the proportion/percentage of the variance explained?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;There are a couple of different things that could reasonably be put on the y-axis, but perhaps the clearest option is to put the proportion or percentage of variation (=variance) explained, like below:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pca_eigen&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;PC&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;percent&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_col&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Proportion of the variation explained&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-34-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;(Note once again that the column in &lt;code&gt;pca_eigen&lt;/code&gt; is called &lt;code&gt;percent&lt;/code&gt;, but it actually contains proportions.)&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;further-watching--reading&#34;&gt;Further watching &amp;amp; reading&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&amp;ldquo;StatQuest&amp;rdquo; videos on:
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://www.youtube.com/watch?v=FgakZw6K1QQ&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;PCA (22 minutes)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.youtube.com/watch?v=oRvgq966yZg&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;PCA follow-up: practical tips (8 minutes)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.youtube.com/watch?v=GEn-_dAyYME&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;MDS and PCoA&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://web.stanford.edu/class/bios221/book/Chap-Multivariate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Chapter on Multivariate Analysis from the book &amp;ldquo;Modern Statistics for Modern Biology&amp;rdquo;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1006907&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Nguyen &amp;amp; Holmes 2019: &amp;ldquo;Ten quick tips for effective dimensionality reduction&amp;rdquo;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Crawley 2012 &amp;ndash; &amp;ldquo;The R Book&amp;rdquo; &amp;ndash; &lt;a href=&#34;https://www.cs.upc.edu/~robert/teaching/estadistica/TheRBook.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;pdf&lt;/a&gt; &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;However, high-throughput sequencing results such as gene counts do need to be normalized by sample sequencing depth (&amp;ldquo;library size&amp;rdquo;) and subjected to a variance stabilizing normalization. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;As &amp;ldquo;The R Book&amp;rdquo; (Crawley 2012) explains: &amp;ldquo;&lt;em&gt;This is called a scree plot in PCA because it is supposed to look like a cliff face on a mountainside (on the left), with a scree slope below it (the tail on the right).&lt;/em&gt;&amp;rdquo; &lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>S03E04: ANOVA 2</title>
      <link>https://biodash.github.io/codeclub/s03e04_anova2/</link>
      <pubDate>Thu, 03 Feb 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s03e04_anova2/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;prep-homework&#34;&gt;Prep homework&lt;/h2&gt;
&lt;h4 id=&#34;basic-computer-setup&#34;&gt;Basic computer setup&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/04_ggplot2/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll help you troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;new-to-ggplot&#34;&gt;New to ggplot?&lt;/h4&gt;
&lt;p&gt;This isn&amp;rsquo;t a ggplot specific session, though we will be using it a bit. Check out the past Code Club sessions covering &lt;code&gt;ggplot2&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/04_ggplot2/&#34;&gt;S01E04&lt;/a&gt;: intro to ggplot2&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/05_ggplot-round-2/&#34;&gt;S01E05&lt;/a&gt;: intro to ggplot2 round 2&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/10_faceting-animating/&#34;&gt;S01E10&lt;/a&gt;: faceting and animating&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e06_ggplot2/&#34;&gt;S02E06&lt;/a&gt;: another intro to ggplot2&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e07_ggplot2_part2/&#34;&gt;S02E07&lt;/a&gt;: a second intro to ggplot2 round 2&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e08_multiple_plots/&#34;&gt;S02E08&lt;/a&gt;: combining plots using faceting&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e09_multiple_plots_part2/&#34;&gt;S02E09&lt;/a&gt;: combining plots using faceting and patchwork&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e10_ggpubr/&#34;&gt;S02E10&lt;/a&gt;: adding statistics to plots&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e12_plotly/&#34;&gt;S02E11&lt;/a&gt;: making interactive plots with plotly&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you&amp;rsquo;ve never used &lt;code&gt;ggplot2&lt;/code&gt; before (or even if you have), you may find &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this cheat sheet&lt;/a&gt; useful.&lt;/p&gt;
&lt;h4 id=&#34;adding-statistics-to-plots&#34;&gt;Adding statistics to plots&lt;/h4&gt;
&lt;p&gt;We had a previous session &lt;a href=&#34;https://biodash.github.io/codeclub/s02e10_ggpubr/&#34;&gt;S02E10&lt;/a&gt; developed by Daniel Quiroz that covers the package &lt;code&gt;ggpubr&lt;/code&gt; and adding statistics to ggplots.&lt;/p&gt;
&lt;h4 id=&#34;we-already-did-t-tests-and-anova-part-1&#34;&gt;We already did t-tests and ANOVA part 1&lt;/h4&gt;
&lt;p&gt;Mike Sovic covered in code club &lt;a href=&#34;https://biodash.github.io/codeclub/s03e01_ttests/&#34;&gt;S03E01&lt;/a&gt; how to run t-tests in R. I covered ANOVA two weeks ago &lt;a href=&#34;https://biodash.github.io/codeclub/s03e02_anova/&#34;&gt;S03E02&lt;/a&gt; and we will be building off that session today.&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;getting-an-r-markdown&#34;&gt;Getting an R Markdown&lt;/h4&gt;
&lt;details&gt;
&lt;summary&gt;
Click here to get an Rmd (optional)
&lt;/summary&gt;
&lt;h4 id=&#34;rmarkdown-for-today&#34;&gt;RMarkdown for today&lt;/h4&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# directory &lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S03E04&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# directory for our RMarkdown&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# (&#34;recursive&#34; to create two levels at once.)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S03E04/Rmd/&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# save the url location for today&#39;s script&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;todays_Rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#39;s&#39;&gt;&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/S03E04_anova2/anova2.Rmd&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# indicate the name of the new Rmd&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;S03E04_Rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;S03E04/Rmd/S03E04_anova2.Rmd&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# go get that file! &lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;todays_Rmd&lt;/span&gt;,
              destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;S03E04_Rmd&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;We have gone through a first pass of running ANOVAs in &lt;a href=&#34;https://biodash.github.io/codeclub/content/S03E02_anova/&#34;&gt;Code Club a couple weeks ago&lt;/a&gt; but didn&amp;rsquo;t have the time to go through all of the content. We are going to re-visit that material today.&lt;/p&gt;
&lt;p&gt;Often people are first introduced to the R programming language when they are wanting to conduct statistical analyses. My experience is that beginners are often able to conduct the analysis they want, and print their results to the console. But, the process of locating and then using the output of their analysis tends to be more complex.&lt;/p&gt;
&lt;p&gt;Today, we are going to go over how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;test if our data is suitable for running ANOVA&lt;/li&gt;
&lt;li&gt;run an ANOVA (parametric) or Kruskal Wallis (non-parametric) test&lt;/li&gt;
&lt;li&gt;run posthoc tests to understand group differences&lt;/li&gt;
&lt;li&gt;use the ANOVA data output object as a means to understand R data structure.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you are looking for a good statistics class, I would recommend Dr. Kristin Mercer&amp;rsquo;s &lt;a href=&#34;https://hcs.osu.edu/courses/hcs-8887&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;HCS 8887 Experimental Design&lt;/a&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h4 id=&#34;load-packages-get-data&#34;&gt;Load packages, get data&lt;/h4&gt;
&lt;p&gt;We are going to start with our favorite dataset &lt;code&gt;palmerpenguins&lt;/code&gt; to provide the input data for our analysis.&lt;/p&gt;
&lt;p&gt;If you don&amp;rsquo;t have any of the packages below, use &lt;a href=&#34;https://rdrr.io/r/utils/install.packages.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;install.packages()&lt;/code&gt;&lt;/a&gt; to download them.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for data&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/&#39;&gt;rstatix&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for testing assumptions and running tests&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;agricolae&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for post-hoc comparison of groups&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---getting-acclimated&#34;&gt;1 - Getting acclimated&lt;/h2&gt;
&lt;p&gt;Some words on syntax: the dataset &lt;code&gt;penguins&lt;/code&gt; is an object within the &lt;code&gt;palmerpenguins&lt;/code&gt; package. If you call the object &lt;code&gt;penguins&lt;/code&gt; (after executing &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library(palmerpenguins)&lt;/code&gt;&lt;/a&gt;), you will be able to see what is contained within that dataframe.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 344 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species island    bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Adelie  Torgersen           39.1          18.7               181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;750&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Adelie  Torgersen           39.5          17.4               186        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;800&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Adelie  Torgersen           40.3          18                 195        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;250&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Adelie  Torgersen           &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;                  &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Adelie  Torgersen           36.7          19.3               193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;450&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Adelie  Torgersen           39.3          20.6               190        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;650&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Adelie  Torgersen           38.9          17.8               181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;625&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Adelie  Torgersen           39.2          19.6               195        &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;675&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Adelie  Torgersen           34.1          18.1               193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;475&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Adelie  Torgersen           42            20.2               190        &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;250&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 334 more rows, and 2 more variables: sex &amp;lt;fct&amp;gt;, year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;However, &lt;code&gt;penguins&lt;/code&gt; will not be in your environment tab because it is not in your local environment. You can use it without it being in your local environment, but if you are bothered by this, you can save a copy in your local environment such it shows up in that top right pane.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What is within this dataset?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 344&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ island            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Torgersen, Torgersen, Torgersen, Torgersen, Torgerse…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_length_mm    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_depth_mm     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ flipper_length_mm &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ body_mass_g       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sex               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; male, female, female, NA, female, male, female, male…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=palmerpenguins_hex.png width=&#34;30%&#34; alt=&#34;a cute hexagon image of three penguins as a part of the palmer penguins package&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Illustration by &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/articles/art.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2-testing-assumptions&#34;&gt;2. Testing assumptions&lt;/h2&gt;
&lt;p&gt;I&amp;rsquo;d be remiss if I didn&amp;rsquo;t show you how to test that you aren&amp;rsquo;t violating any of the assumptions needed to conduct an ANOVA. We went over this a little bit back in the session put together by Daniel Quiroz on &lt;a href=&#34;https://biodash.github.io/codeclub/s02e10_ggpubr/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ggpubr&lt;/a&gt; and adding statistical results to ggplots.&lt;/p&gt;
&lt;p&gt;Briefly, in order to use parametric procedures (like ANOVA), we need to be sure our data meets the assumptions for 1) normality and 2) constant variance. This can be done in a few different ways.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=featured.png width=&#34;70%&#34; alt=&#34;a cartoon of two distributions, one is normal (bell shaped curve) and one is not (dimodal, two peaks, with the one on the right being higher&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Illustration by &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/articles/art.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;h4 id=&#34;shapiro-wilk-test-for-normality&#34;&gt;Shapiro-Wilk test for normality&lt;/h4&gt;
&lt;p&gt;We are going to use the Shapiro-Wilk test (using the function &lt;a href=&#34;https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;shapiro_test()&lt;/code&gt;&lt;/a&gt; which is in the package &lt;code&gt;rstatix&lt;/code&gt; to determine normality, but will do it groupwise. This function is a pipe-friendly wrapper for the function &lt;a href=&#34;https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/shapiro.test&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;shapiro.test()&lt;/code&gt;&lt;/a&gt;, which just means you can use it with pipes.&lt;/p&gt;
&lt;p&gt;Our question is:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Does &lt;code&gt;bill_length_mm&lt;/code&gt; vary by &lt;code&gt;species&lt;/code&gt; in female penguins?&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=culmen_depth.png width=&#34;50%&#34; alt=&#34;a cute image showing the bill length as the horizontal (sticking out from the face) length of the penguin bill, and the bill depth as the vertical (perpendicular to the ground) bill depth&#34;&gt;
&lt;figcaption&gt;
Illustration by &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/articles/art.html&#34;&gt;Allison Horst&lt;/a&gt;
&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
Caputuring some descriptive statistics
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;female&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# Groups:   species [3]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species       n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie       73&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap    34&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo       58&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# testing for all female penguins together&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;female&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;rstatix&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html&#39;&gt;shapiro_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   variable       statistic         p&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; bill_length_mm     0.950 0.000&lt;span style=&#39;text-decoration: underline;&#39;&gt;014&lt;/span&gt;0&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# testing by species&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;female&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;rstatix&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html&#39;&gt;shapiro_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   variable       statistic       p&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie    bill_length_mm     0.991 0.895  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap bill_length_mm     0.883 0.001&lt;span style=&#39;text-decoration: underline;&#39;&gt;70&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo    bill_length_mm     0.989 0.895&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note that if we test all the penguins together, it looks like we do not have normal data. If we test by species, we see that two speces have normal data distribution and one (Chinstrap) does not.&lt;/p&gt;
&lt;p&gt;Can we visualize normality in another way?&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s quickly make a new dataframe that includes only the female penguins, and drop missing values, so that we don&amp;rsquo;t have to keep including the &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://tidyr.tidyverse.org/reference/drop_na.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;drop_na()&lt;/code&gt;&lt;/a&gt; statements.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;female&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Visualizing with a histogram by &lt;code&gt;species&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_histogram&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_grid&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-9-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;We can see here too that the Chinstrap penguins look maybe not that normal (and we saw earlier they have the fewest numbers of observations). This is consistent with the results from the Shapiro test.&lt;/p&gt;
&lt;h5 id=&#34;log-transforming&#34;&gt;Log transforming&lt;/h5&gt;
&lt;p&gt;Would our data look more normal if we log transformed it? Let&amp;rsquo;s see. We can use the function &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; to create a new column called &lt;code&gt;bill_length_mm_log2&lt;/code&gt; which will have the data from &lt;code&gt;bill_length_mm&lt;/code&gt; but log transformed using base 2 (using the base R function &lt;a href=&#34;https://www.rdocumentation.org/packages/SparkR/versions/2.1.2/topics/log2&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;log2()&lt;/code&gt;&lt;/a&gt;).&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=dplyr_mutate.png width=&#34;50%&#34; alt=&#34;Cartoon of cute fuzzy monsters dressed up as different X-men characters, working together to add a new column to an existing data frame. Stylized title text reads “dplyr::mutate - add columns, keep existing.&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Illustration by &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/articles/art.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The syntax of &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; is like this:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;mutate(new_variable = function(existing_variable))&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;log_female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;bill_length_mm_log2 &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Log.html&#39;&gt;log2&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Testing using &lt;a href=&#34;https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;shapiro_test()&lt;/code&gt;&lt;/a&gt; again.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;log_female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;c&#39;&gt;# don&#39;t need drop_na() because we already did that&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html&#39;&gt;shapiro_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm_log2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   variable            statistic       p&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie    bill_length_mm_log2     0.991 0.868  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap bill_length_mm_log2     0.911 0.009&lt;span style=&#39;text-decoration: underline;&#39;&gt;00&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo    bill_length_mm_log2     0.988 0.841&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Still not passing the test for normality. Let&amp;rsquo;s still look at this visually.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;log_female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm_log2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_histogram&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_grid&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Doesn&amp;rsquo;t look very different from the non-log2 transformed data. Ok, well we tried.&lt;/p&gt;
&lt;h4 id=&#34;equal-variance&#34;&gt;Equal variance&lt;/h4&gt;
&lt;p&gt;We can test for equal variance using Levene&amp;rsquo;s test, &lt;a href=&#34;https://www.rdocumentation.org/packages/rstatix/versions/0.7.0/topics/levene_test&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;levene_test()&lt;/code&gt;&lt;/a&gt; which is part of the &lt;code&gt;rstatix&lt;/code&gt; package. Again, this is a pipe-friendly wrapper for the function &lt;a href=&#34;https://www.rdocumentation.org/packages/lawstat/versions/3.4/topics/levene.test&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;levene.test()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/levene_test.html&#39;&gt;levene_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     df1   df2 statistic     p&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;     2   162     0.819 0.442&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Our data meets the assumption for equal variance, but not for normality, so we will need to be sure to select a test that does not have an assumption of normality.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3-kruskal-wallis-test&#34;&gt;3. Kruskal Wallis test&lt;/h2&gt;
&lt;p&gt;The Kruskal Wallis test is the non-parametric version of a one-way ANOVA. This non-parametric test tests whether samples are coming from the same distribution, but uses ranks instead of means.&lt;/p&gt;
&lt;p&gt;We want to see if there are any differences in bill length (&lt;code&gt;bill_length_mm&lt;/code&gt;) in penguins by &lt;code&gt;species&lt;/code&gt;. Since our data violates the assumptions of normality, we should do this using a test that does not require normality, and we can use the &lt;a href=&#34;https://en.wikipedia.org/wiki/Kruskal%E2%80%93Wallis_one-way_analysis_of_variance&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Kruskal Wallis test&lt;/a&gt;. The Kruskal-Wallis test, can be run using the &lt;code&gt;rstatix&lt;/code&gt; function &lt;a href=&#34;https://www.rdocumentation.org/packages/rstatix/versions/0.7.0/topics/kruskal_test&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;kruskal_test()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;First let&amp;rsquo;s get some descriptive information about our data.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# Groups:   species [3]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species       n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie       73&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap    34&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo       58&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If we want to learn more about the function &lt;a href=&#34;https://rpkgs.datanovia.com/rstatix/reference/kruskal_test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;kruskal_test()&lt;/code&gt;&lt;/a&gt; we can do so using the code below. The help documentation will show up in the bottom right quadrant of your RStudio.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;?&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/kruskal_test.html&#39;&gt;kruskal_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can run a Kruskal-Wallis test by indicating our model.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_kruskal&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/kruskal_test.html&#39;&gt;kruskal_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The function &lt;a href=&#34;https://rpkgs.datanovia.com/rstatix/reference/kruskal_test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;kruskal_test()&lt;/code&gt;&lt;/a&gt; already puts the output of the function into a tidy format, so we can simply view it.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/View.html&#39;&gt;View&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_kruskal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&#34;text-align:left&#34;&gt;.y.&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;n&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;statistic&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;df&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;p&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;method&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;bill_length_mm&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;165&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;121.6214&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;2&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Kruskal-Wallis&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;We can also look at our data visually by plotting it, as below.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-19-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-1&#34;&gt;Breakout rooms 1&lt;/h2&gt;
&lt;p&gt;We want to know if there are any significant differences in &lt;code&gt;bill_depth_mm&lt;/code&gt; by &lt;code&gt;species&lt;/code&gt; in male penguins.&lt;/p&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Test your assumptions for normality to determine what would be the appropriate test to do to assess means separation.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Use the function &lt;a href=&#34;https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;shapiro_test()&lt;/code&gt;&lt;/a&gt; to test normality. If your data is non-normal, you can check to see if log transforming it makes it normal. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
Shapiro-Wilk Test
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# create df with male penguins and no NAs&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;male_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;male&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# run shapiro test&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;male_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;rstatix&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html&#39;&gt;shapiro_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   variable      statistic      p&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie    bill_depth_mm     0.964 0.033&lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap bill_depth_mm     0.983 0.863 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo    bill_depth_mm     0.980 0.401&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Visualize&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;male_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_histogram&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_grid&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-22-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;See if log-transforming your data would allow you to use parametric tests.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;log_male_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;male_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;bill_depth_mm_log2 &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Log.html&#39;&gt;log2&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Testing using &lt;a href=&#34;https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;shapiro_test()&lt;/code&gt;&lt;/a&gt; again.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;log_male_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;c&#39;&gt;# don&#39;t need drop_na() because we already did that&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html&#39;&gt;shapiro_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm_log2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   variable           statistic      p&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie    bill_depth_mm_log2     0.971 0.091&lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap bill_depth_mm_log2     0.981 0.814 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo    bill_depth_mm_log2     0.980 0.438&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Ok! We could use log2 transformed data&lt;/p&gt;
&lt;p&gt;Visualize.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;log_male_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm_log2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_histogram&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_grid&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-25-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Test your assumptions for equal variance to determine what would be the appropriate test to do to assess means separation.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;&amp;laquo;&amp;laquo;&amp;laquo;&amp;lt; HEAD
You can use the function &lt;a href=&#34;https://rpkgs.datanovia.com/rstatix/reference/levene_test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;levene_test()&lt;/code&gt;&lt;/a&gt; to test for equal variance.&lt;/p&gt;
&lt;br&gt;
=======
You can use the function [`levene_test()`](https://rpkgs.datanovia.com/rstatix/reference/levene_test.html) to test for equal variance. &lt;br&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; b4836320d0dbe7b28303489c3f695280e6d0c2a2
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
Equal variance
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;male_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/levene_test.html&#39;&gt;levene_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     df1   df2 statistic     p&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;     2   165      2.30 0.103&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Conduct your Kruskal-Wallis test or ANOVA to see if there is any overall significant effect of &lt;code&gt;species&lt;/code&gt; on &lt;code&gt;bill_depth_mm&lt;/code&gt; of male penguins.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Review the information in section 3 of this post. You could also use the package &lt;code&gt;ggpubr&lt;/code&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
Kruskal-Wallis
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_kruskal&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;male_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/kruskal_test.html&#39;&gt;kruskal_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/View.html&#39;&gt;View&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_kruskal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&#34;text-align:left&#34;&gt;.y.&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;n&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;statistic&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;df&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;p&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;method&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;bill_depth_mm&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;168&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;116.152&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;2&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Kruskal-Wallis&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;ANOVA - to use this you need to be using normal data (here, the log transformed data).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_anova&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/aov.html&#39;&gt;aov&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;log_male_penguins&lt;/span&gt;,
      formula &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm_log2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/summary.html&#39;&gt;summary&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_anova&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;              Df Sum Sq Mean Sq F value Pr(&amp;gt;F)    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; species       2 3.1221  1.5610   319.8 &amp;lt;2e-16 ***&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Residuals   165 0.8053  0.0049                   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ---&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Signif. codes:  0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4-posthoc-group-analysis&#34;&gt;4. Posthoc group analysis&lt;/h2&gt;
&lt;p&gt;Now that we&amp;rsquo;ve seen that &lt;code&gt;species&lt;/code&gt; are significant effectors of &lt;code&gt;bill_length_mm&lt;/code&gt;, our next logical question might be, which species specifically are different from each other? We can determine this by conducting a post-hoc test. We will do our post-hoc analysis using Dunn&amp;rsquo;s test (which is for specifically ranked data) and the function &lt;a href=&#34;https://rdrr.io/cran/rstatix/man/dunn_test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dunn_test()&lt;/code&gt;&lt;/a&gt; which is a part of &lt;code&gt;rstatix&lt;/code&gt;. In the example below, we are using the Benjamini Hochberg method of pvalue adjustment for multiple corrections.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dunn_bill_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/dunn_test.html&#39;&gt;dunn_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
            p.adjust.method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;BH&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# there are others too&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Like we did with t-tests, you can also look at the resulting &lt;a href=&#34;https://rpkgs.datanovia.com/rstatix/reference/dunn_test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dunn_test()&lt;/code&gt;&lt;/a&gt; object (here, &lt;code&gt;dunn_bill_length&lt;/code&gt;) in your environment pane.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/View.html&#39;&gt;View&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dunn_bill_length&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&#34;text-align:left&#34;&gt;.y.&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;group1&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;group2&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;n1&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;n2&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;statistic&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;p&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;p.adj&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;p.adj.signif&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;bill_length_mm&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Adelie&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Chinstrap&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;73&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;34&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;8.8609532&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.0000000&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.0000000&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;****&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;bill_length_mm&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Adelie&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Gentoo&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;73&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;58&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;9.4096815&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.0000000&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.0000000&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;****&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;bill_length_mm&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Chinstrap&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Gentoo&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;34&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;58&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;-0.8549426&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.3925829&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.3925829&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;ns&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;From this result, we can see that Adelie is significantly different than Chinstrap and Gentoo, but Chinstrap and Gentoo are not significantly different from each other.&lt;/p&gt;
&lt;p&gt;The structure of this resulting object &lt;code&gt;dunn_bill_length&lt;/code&gt; can be determined using the code below.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dunn_bill_length&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; rstatix_test [3 × 9] (S3: rstatix_test/dunn_test/tbl_df/tbl/data.frame)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ .y.         : chr [1:3] &#34;bill_length_mm&#34; &#34;bill_length_mm&#34; &#34;bill_length_mm&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ group1      : chr [1:3] &#34;Adelie&#34; &#34;Adelie&#34; &#34;Chinstrap&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ group2      : chr [1:3] &#34;Chinstrap&#34; &#34;Gentoo&#34; &#34;Gentoo&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ n1          : Named int [1:3] 73 73 34&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr [1:3] &#34;Adelie&#34; &#34;Adelie&#34; &#34;Chinstrap&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ n2          : Named int [1:3] 34 58 58&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr [1:3] &#34;Chinstrap&#34; &#34;Gentoo&#34; &#34;Gentoo&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ statistic   : num [1:3] 8.861 9.41 -0.855&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ p           : num [1:3] 7.93e-19 4.98e-21 3.93e-01&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ p.adj       : num [1:3] 1.19e-18 1.49e-20 3.93e-01&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ p.adj.signif: chr [1:3] &#34;****&#34; &#34;****&#34; &#34;ns&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  - attr(*, &#34;na.action&#34;)= &#39;omit&#39; Named int 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr &#34;3&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  - attr(*, &#34;args&#34;)=List of 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ data           : tibble [165 × 8] (S3: tbl_df/tbl/data.frame)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ species          : Factor w/ 3 levels &#34;Adelie&#34;,&#34;Chinstrap&#34;,..: 1 1 1 1 1 1 1 1 1 1 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ island           : Factor w/ 3 levels &#34;Biscoe&#34;,&#34;Dream&#34;,..: 3 3 3 3 3 3 3 3 1 1 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ bill_length_mm   : num [1:165] 39.5 40.3 36.7 38.9 41.1 36.6 38.7 34.4 37.8 35.9 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ bill_depth_mm    : num [1:165] 17.4 18 19.3 17.8 17.6 17.8 19 18.4 18.3 19.2 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ flipper_length_mm: int [1:165] 186 195 193 181 182 185 195 184 174 189 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ body_mass_g      : int [1:165] 3800 3250 3450 3625 3200 3700 3450 3325 3400 3800 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ sex              : Factor w/ 2 levels &#34;female&#34;,&#34;male&#34;: 1 1 1 1 1 1 1 1 1 1 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ year             : int [1:165] 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ formula        :Class &#39;formula&#39;  language bill_length_mm ~ species&lt;/span&gt;
&lt;&lt;&lt;&lt;&lt;&lt;&lt; HEAD
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..- attr(*, &#34;.Environment&#34;)=&amp;lt;environment: 0x55a775e9b4b8&amp;gt; &lt;/span&gt;
=======
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. .. ..- attr(*, &#34;.Environment&#34;)=&amp;lt;environment: 0x7fb80d5a2188&amp;gt; &lt;/span&gt;
&gt;&gt;&gt;&gt;&gt;&gt;&gt; b4836320d0dbe7b28303489c3f695280e6d0c2a2
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ p.adjust.method: chr &#34;BH&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ detailed       : logi FALSE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ method         : chr &#34;dunn_test&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This df does not have a &amp;lsquo;groups&amp;rsquo; column, but if we want to plot in the same way, we can make a new object which we use for plotting. I&amp;rsquo;m going to show you here how to do this manually.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dunn_for_plotting&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;species &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Chinstrap&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Gentoo&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                                groups &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;b&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;b&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;5-bringing-it-together-in-a-plot&#34;&gt;5. Bringing it together in a plot&lt;/h2&gt;
&lt;p&gt;We already looked at a first-pass plot, but let&amp;rsquo;s customize it now, and add our statistical info. Here is our base plot.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-37-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;First let&amp;rsquo;s make the plot more aesthetically pleasing.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# remove legend bc we don&#39;t need it&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Species&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill Length, in mm&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Culmen Bill Length Among Different Species&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data collected from Palmer LTER, Antarctica&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-38-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;We want to add the letters to this plot, so we can tell which groups of species by sex are significantly different. We are going to figure out what the maximum &lt;code&gt;bill_length_mm&lt;/code&gt; for each species by sex is, so it will help us determine where to put our letter labels. Then, we cna add our labels to be higher than the largest data point.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_max&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;female_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;max_bill_length_mm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_length_max&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   max_bill_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;                  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie                  42.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap               58  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo                  50.5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s add our &lt;code&gt;bill_length_max&lt;/code&gt; back to the df with our post-hoc groups &lt;code&gt;dunn_for_plotting&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_for_plotting&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;full_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dunn_for_plotting&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_length_max&lt;/span&gt;,
                               by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_for_plotting&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     species groups max_bill_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1    Adelie      a               42.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 Chinstrap      b               58.0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3    Gentoo      b               50.5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s plot.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_for_plotting&lt;/span&gt;,
            &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
                y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;max_bill_length_mm&lt;/span&gt;, 
                color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
                label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;groups&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Different letters indicate significant difference as determined by \na Kruskal-Wallis test with Dunn&#39;s post-hoc means separation&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-41-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Also remember Daniel showed us how we can do &lt;a href=&#34;https://biodash.github.io/codeclub/s02e10_ggpubr/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;somthing similar&lt;/a&gt; using the package &lt;code&gt;ggpubr&lt;/code&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-2&#34;&gt;Breakout rooms 2&lt;/h2&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Conduct a post-hoc analysis to understand which male penguin &lt;code&gt;species&lt;/code&gt; have significantly different &lt;code&gt;bill_depth_mm&lt;/code&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Using the results from your assumption testing in Exercise 3, pick an appropriate post-hoc test to answer your question. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
Dunn&#39;s test
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dunn_bill_depth&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;male_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/dunn_test.html&#39;&gt;dunn_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
            p.adjust.method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;BH&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/View.html&#39;&gt;View&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dunn_bill_depth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&#34;text-align:left&#34;&gt;.y.&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;group1&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;group2&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;n1&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;n2&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;statistic&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;p&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;p.adj&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;p.adj.signif&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;bill_depth_mm&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Adelie&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Chinstrap&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;73&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;34&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.9039517&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.366021&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.366021&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;ns&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;bill_depth_mm&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Adelie&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Gentoo&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;73&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;61&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;-9.5885513&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.000000&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.000000&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;****&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;bill_depth_mm&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Chinstrap&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Gentoo&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;34&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;61&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;-8.6487581&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.000000&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.000000&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;****&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;p&gt;Parametric post-hoc test&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bonferroni_bill_depth&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;agricolae&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/agricolae/man/LSD.test.html&#39;&gt;LSD.test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_anova&lt;/span&gt;, 
                                             trt &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;, 
                                             p.adj &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;bonferroni&#34;&lt;/span&gt;,
                                             console &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Study: bill_depth_anova ~ &#34;species&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; LSD t Test for bill_depth_mm_log2 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; P value adjustment method: bonferroni &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Mean Square Error:  0.004880851 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; species,  means and individual ( 95 %) CI&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;           bill_depth_mm_log2        std  r      LCL      UCL      Min      Max&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelie              4.251426 0.07632273 73 4.235282 4.267571 4.087463 4.426265&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chinstrap           4.265907 0.05726112 34 4.242250 4.289564 4.129283 4.378512&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Gentoo              3.972772 0.06803521 61 3.955110 3.990433 3.817623 4.112700&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Alpha: 0.05 ; DF Error: 165&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Critical Value of t: 2.418634 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Groups according to probability of means differences and alpha level( 0.05 )&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Treatments with the same letter are not significantly different.&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;           bill_depth_mm_log2 groups&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chinstrap           4.265907      a&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelie              4.251426      a&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Gentoo              3.972772      b&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-5&#34;&gt;Exercise 5&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Bring it all together in a plot.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Think about what you&amp;rsquo;d like to display and go back to section 5 for more help. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
Using Kruskal-Wallis and Dunn&#39;s post-hoc test
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_plot_kruskal&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;male_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# remove legend bc we don&#39;t need it&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Species&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill Depth, in mm&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Culmen Bill Depth Among Different Species&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data collected from Palmer LTER, Antarctica&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-46-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_max&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;male_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;max_bill_depth_mm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_depth_max&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   max_bill_depth_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;                 &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie                 21.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap              20.8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo                 17.3&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/View.html&#39;&gt;View&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dunn_bill_depth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&#34;text-align:left&#34;&gt;.y.&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;group1&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;group2&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;n1&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;n2&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;statistic&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;p&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;p.adj&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;p.adj.signif&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;bill_depth_mm&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Adelie&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Chinstrap&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;73&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;34&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.9039517&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.366021&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.366021&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;ns&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;bill_depth_mm&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Adelie&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Gentoo&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;73&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;61&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;-9.5885513&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.000000&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.000000&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;****&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;bill_depth_mm&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Chinstrap&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Gentoo&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;34&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;61&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;-8.6487581&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.000000&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.000000&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;****&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dunn_depth_for_plotting&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;species &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Chinstrap&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Gentoo&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                                groups &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;b&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;depth_for_plotting_kruskal&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;full_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dunn_depth_for_plotting&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_depth_max&lt;/span&gt;,
                               by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;depth_for_plotting_kruskal&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     species groups max_bill_depth_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1    Adelie      a              21.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 Chinstrap      a              20.8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3    Gentoo      b              17.3&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s plot.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_plot_kruskal&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;depth_for_plotting_kruskal&lt;/span&gt;,
            &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
                y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;max_bill_depth_mm&lt;/span&gt;, 
                color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
                label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;groups&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Different letters indicate significant difference as determined by \nthe Kruskal Wallis with Dunn&#39;s test for post-hoc means separation&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-51-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Using ANOVA and Bonferroni post-hoc test&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bonferroni_bill_depth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;groups&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;           bill_depth_mm_log2 groups&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chinstrap           4.265907      a&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelie              4.251426      a&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Gentoo              3.972772      b&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bonferroni_bill_depth_plotting&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bonferroni_bill_depth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;groups&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;rownames_to_column&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;var &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bonferroni_bill_depth_plotting&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     species bill_depth_mm_log2 groups&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 Chinstrap           4.265907      a&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2    Adelie           4.251426      a&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3    Gentoo           3.972772      b&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bonferroni_bill_depth_plotting&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;full_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bonferroni_bill_depth_plotting&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_depth_max&lt;/span&gt;,
                               by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bonferroni_bill_depth_plotting&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     species bill_depth_mm_log2 groups max_bill_depth_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 Chinstrap           4.265907      a              20.8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2    Adelie           4.251426      a              21.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3    Gentoo           3.972772      b              17.3&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_plot_bonf&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;male_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bonferroni_bill_depth_plotting&lt;/span&gt;,
            &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
                y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;max_bill_depth_mm&lt;/span&gt;, 
                color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
                label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;groups&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# remove legend bc we don&#39;t need it&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Species&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill Depth, in mm&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Culmen Bill Depth Among Different Species&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data collected from Palmer LTER, Antarctica&#34;&lt;/span&gt;,
       caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Different letters indicate significant difference as determined by \none-way ANOVA with Bonferroni post-hoc means separation&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-54-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>S03E02: ANOVA</title>
      <link>https://biodash.github.io/codeclub/s03e02_anova/</link>
      <pubDate>Thu, 20 Jan 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s03e02_anova/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;prep-homework&#34;&gt;Prep homework&lt;/h2&gt;
&lt;h3 id=&#34;basic-computer-setup&#34;&gt;Basic computer setup&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/04_ggplot2/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll help you troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;new-to-ggplot&#34;&gt;New to ggplot?&lt;/h3&gt;
&lt;p&gt;This isn&amp;rsquo;t a ggplot specific session, though we will be using it a bit. Check out the past Code Club sessions covering &lt;code&gt;ggplot2&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/04_ggplot2/&#34;&gt;S01E04&lt;/a&gt;: intro to ggplot2&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/05_ggplot-round-2/&#34;&gt;S01E05&lt;/a&gt;: intro to ggplot2 round 2&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/10_faceting-animating/&#34;&gt;S01E10&lt;/a&gt;: faceting and animating&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e06_ggplot2/&#34;&gt;S02E06&lt;/a&gt;: another intro to ggplot2&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e07_ggplot2_part2/&#34;&gt;S02E07&lt;/a&gt;: a second intro to ggplot2 round 2&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e08_multiple_plots/&#34;&gt;S02E08&lt;/a&gt;: combining plots using faceting&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e09_multiple_plots_part2/&#34;&gt;S02E09&lt;/a&gt;: combining plots using faceting and patchwork&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e10_ggpubr/&#34;&gt;S02E10&lt;/a&gt;: adding statistics to plots&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e12_plotly/&#34;&gt;S02E11&lt;/a&gt;: making interactive plots with plotly&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you&amp;rsquo;ve never used &lt;code&gt;ggplot2&lt;/code&gt; before (or even if you have), you may find &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this cheat sheet&lt;/a&gt; useful.&lt;/p&gt;
&lt;h3 id=&#34;adding-statistics-to-plots&#34;&gt;Adding statistics to plots&lt;/h3&gt;
&lt;p&gt;We had a previous session &lt;a href=&#34;https://biodash.github.io/codeclub/s02e10_ggpubr/&#34;&gt;S02E10&lt;/a&gt; developed by Daniel Quiroz that covers the package &lt;code&gt;ggpubr&lt;/code&gt; and adding statistics to ggplots.&lt;/p&gt;
&lt;h3 id=&#34;we-already-did-t-tests&#34;&gt;We already did t-tests&lt;/h3&gt;
&lt;p&gt;Mike Sovic covered in the last code club &lt;a href=&#34;https://biodash.github.io/codeclub/s03e01_ttests/&#34;&gt;S03E01&lt;/a&gt; how to run t-tests in R. We will be building on what we learned last week.&lt;/p&gt;
&lt;br&gt;
&lt;h2 id=&#34;getting-started&#34;&gt;Getting Started&lt;/h2&gt;
&lt;details&gt;
&lt;summary&gt;
Click here to get an Rmd (optional)
&lt;/summary&gt;
&lt;h3 id=&#34;rmarkdown-for-today&#34;&gt;RMarkdown for today&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# directory &lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S03E02&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# directory for our RMarkdown&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# (&#34;recursive&#34; to create two levels at once.)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S03E02/Rmd/&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# save the url location for today&#39;s script&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;todays_Rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#39;s&#39;&gt;&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/S03E02_anova/anova.Rmd&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# indicate the name of the new Rmd&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;S03E02_Rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;S03E02/Rmd/S03E02_anova.Rmd&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# go get that file! &lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;todays_Rmd&lt;/span&gt;,
              destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;S03E02_Rmd&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;introduction&#34;&gt;Introduction&lt;/h3&gt;
&lt;p&gt;Often people are first introduced to the R programming language when they are wanting to conduct statistical analyses. My experience is that beginners are often able to conduct the analysis they want, and print their results to the console. But, the process of locating and then using the output of their analysis tends to be more complex.&lt;/p&gt;
&lt;p&gt;Today, we are going to go over how to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;test if our data is suitable for running ANOVA&lt;/li&gt;
&lt;li&gt;run an ANOVA test&lt;/li&gt;
&lt;li&gt;run posthoc tests to understand group differences&lt;/li&gt;
&lt;li&gt;use the ANOVA data output object as a means to understand R data structure.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The purpose of today&amp;rsquo;s session is more to give you practical experience with running and retrieving ANOVA analysis output, than teaching about the assumptions and background of the test itself.&lt;/p&gt;
&lt;p&gt;If you are looking for a good statistics class, I would recommend Dr. Kristin Mercer&amp;rsquo;s &lt;a href=&#34;https://hcs.osu.edu/courses/hcs-8887&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;HCS 8887 Experimental Design&lt;/a&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h4 id=&#34;--load-libraries-get-data&#34;&gt;- Load libraries, get data&lt;/h4&gt;
&lt;p&gt;We are going to start with our favorite dataset &lt;code&gt;palmerpenguins&lt;/code&gt; to provide the input data for our analysis.&lt;/p&gt;
&lt;p&gt;If you don&amp;rsquo;t have any of the packages below, use &lt;a href=&#34;https://rdrr.io/r/utils/install.packages.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;install.packages()&lt;/code&gt;&lt;/a&gt; to download them.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for data&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/&#39;&gt;rstatix&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for testing assumptions&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;agricolae&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for post-hoc comparison of groups&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---getting-acclimated&#34;&gt;1 - Getting acclimated&lt;/h2&gt;
&lt;p&gt;Some words on syntax: the dataset &lt;code&gt;penguins&lt;/code&gt; is an object within the &lt;code&gt;palmerpenguins&lt;/code&gt; package. If you call the object &lt;code&gt;penguins&lt;/code&gt; (after executing &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library(palmerpenguins)&lt;/code&gt;&lt;/a&gt;), you will be able to see what is contained within that dataframe.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 344 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species island    bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Adelie  Torgersen           39.1          18.7               181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;750&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Adelie  Torgersen           39.5          17.4               186        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;800&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Adelie  Torgersen           40.3          18                 195        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;250&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Adelie  Torgersen           &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;                  &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Adelie  Torgersen           36.7          19.3               193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;450&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Adelie  Torgersen           39.3          20.6               190        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;650&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Adelie  Torgersen           38.9          17.8               181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;625&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Adelie  Torgersen           39.2          19.6               195        &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;675&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Adelie  Torgersen           34.1          18.1               193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;475&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Adelie  Torgersen           42            20.2               190        &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;250&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 334 more rows, and 2 more variables: sex &amp;lt;fct&amp;gt;, year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;However, &lt;code&gt;penguins&lt;/code&gt; will not be in your environment tab because it is not in your local environment. You can use it without it being in your local environment, but if you are bothered by this, you can save a copy in your local environment such it shows up in that top right pane.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What is within this dataset?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://pillar.r-lib.org/reference/glimpse.html&#39;&gt;glimpse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 344&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ island            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Torgersen, Torgersen, Torgersen, Torgersen, Torgerse…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_length_mm    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_depth_mm     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ flipper_length_mm &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ body_mass_g       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sex               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; male, female, female, NA, female, male, female, male…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=palmerpenguins_hex.png width=&#34;30%&#34; alt=&#34;a cute hexagon image of three penguins as a part of the palmer penguins package&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Illustration by &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/articles/art.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2-anova-function&#34;&gt;2. ANOVA function&lt;/h2&gt;
&lt;p&gt;We want to see if there are any differences in bill length (&lt;code&gt;bill_length_mm&lt;/code&gt;) in penguins by &lt;code&gt;sex&lt;/code&gt;, by &lt;code&gt;species&lt;/code&gt;, or by their interaction. We do this using ANOVA.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=lter_penguins.png width=&#34;50%&#34; alt=&#34;a cute image of three penguins, the species adelie, chinstrap, and gentoo as a part of the palmer penguins package&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Illustration by &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/articles/art.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;First let&amp;rsquo;s get some descriptive information about our data.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/count.html&#39;&gt;count&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# Groups:   species, sex [6]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   sex        n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie    female    73&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Adelie    male      73&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Chinstrap female    34&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Chinstrap male      34&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Gentoo    female    58&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Gentoo    male      61&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The most commonly used function to run ANOVA in R is called &lt;a href=&#34;https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/aov&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;aov()&lt;/code&gt;&lt;/a&gt; which is a part of the &lt;code&gt;stats&lt;/code&gt; package that is pre-loaded with base R. So no new packages need to be installed here.&lt;/p&gt;
&lt;p&gt;If we want to learn more about the function &lt;a href=&#34;https://rdrr.io/r/stats/aov.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;aov()&lt;/code&gt;&lt;/a&gt; we can do so using the code below. The help documentation will show up in the bottom right quadrant of your RStudio.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;?&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/aov.html&#39;&gt;aov&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can run an ANOVA by indicating our model, and here I&amp;rsquo;m also selecting to drop the NAs.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_anova&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/aov.html&#39;&gt;aov&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
      &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;*&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/summary.html&#39;&gt;summary&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_anova&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;              Df Sum Sq Mean Sq F value Pr(&amp;gt;F)    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; species       2   7015    3508 654.189 &amp;lt;2e-16 ***&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; sex           1   1136    1136 211.807 &amp;lt;2e-16 ***&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; species:sex   2     24      12   2.284  0.103    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Residuals   327   1753       5                   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ---&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Signif. codes:  0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=broom_package.png width=&#34;70%&#34; alt=&#34;an image of fuzzy monsters with the test broom: turns messy tables into tidy tibbles. the monsters going in are ragged and dirty, they get cleaned and come out sparkling &#34;&gt;
&lt;/p&gt;
&lt;p&gt;Illustration by &lt;a href=&#34;https://github.com/allisonhorst/stats-illustrations&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We can take the output of our ANOVA and use the function &lt;a href=&#34;https://generics.r-lib.org/reference/tidy.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tidy()&lt;/code&gt;&lt;/a&gt; within the &lt;code&gt;broom&lt;/code&gt; package to turn our output into a tidy table. Here, the notation &lt;a href=&#34;https://generics.r-lib.org/reference/tidy.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;broom::tidy()&lt;/code&gt;&lt;/a&gt; means I want to use the function &lt;a href=&#34;https://generics.r-lib.org/reference/tidy.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tidy()&lt;/code&gt;&lt;/a&gt; that is a part of the &lt;code&gt;broom&lt;/code&gt; package. This works even though I haven&amp;rsquo;t called &lt;a href=&#34;https://broom.tidymodels.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library(broom)&lt;/code&gt;&lt;/a&gt; at the beginning of my script.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tidy_anova&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;broom&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://generics.r-lib.org/reference/tidy.html&#39;&gt;tidy&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_anova&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tidy_anova&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 4 × 6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   term           df  sumsq  meansq statistic    p.value&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; species         2 &lt;span style=&#39;text-decoration: underline;&#39;&gt;7&lt;/span&gt;015.  &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;508.      654.    5.03&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-115&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; sex             1 &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;136.  &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;136.      212.    2.42&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;- 37&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; species:sex     2   24.5   12.2       2.28  1.03&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-  1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Residuals     327 &lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;753.     5.36     &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;    &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;span style=&#39;color: #555555;&#39;&gt; &lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can also look at our data by visually plotting it, as below.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-11-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&#34;3-posthoc-group-analysis&#34;&gt;3. Posthoc group analysis&lt;/h2&gt;
&lt;p&gt;Now that we&amp;rsquo;ve seen that &lt;code&gt;sex&lt;/code&gt; and &lt;code&gt;species&lt;/code&gt; are significant effectors of &lt;code&gt;bill_length_mm&lt;/code&gt;, our next logical question might be, which groups are different from each other? We can determine this by conducting post-hoc tests. We will do our post-hoc analysis using Tukey&amp;rsquo;s Honestly Significant Difference test and the function &lt;a href=&#34;https://www.rdocumentation.org/packages/agricolae/versions/1.3-5/topics/HSD.test&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;HSD.test()&lt;/code&gt;&lt;/a&gt; which is a part of the useful package &lt;code&gt;agricolae&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tukey_bill_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/agricolae/man/HSD.test.html&#39;&gt;HSD.test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_anova&lt;/span&gt;, 
                      trt &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;sex&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
                      console &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# prints the results to console&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Study: bill_length_anova ~ c(&#34;species&#34;, &#34;sex&#34;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; HSD Test for bill_length_mm &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Mean Square Error:  5.361892 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; species:sex,  means&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                  bill_length_mm      std  r  Min  Max&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelie:female          37.25753 2.028883 73 32.1 42.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelie:male            40.39041 2.277131 73 34.6 46.0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chinstrap:female       46.57353 3.108669 34 40.9 58.0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chinstrap:male         51.09412 1.564558 34 48.5 55.8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Gentoo:female          45.56379 2.051247 58 40.9 50.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Gentoo:male            49.47377 2.720594 61 44.4 59.6&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Alpha: 0.05 ; DF Error: 327 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Critical Value of Studentized Range: 4.054126 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Groups according to probability of means differences and alpha level( 0.05 )&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Treatments with the same letter are not significantly different.&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                  bill_length_mm groups&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chinstrap:male         51.09412      a&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Gentoo:male            49.47377      b&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chinstrap:female       46.57353      c&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Gentoo:female          45.56379      c&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelie:male            40.39041      d&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelie:female          37.25753      e&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Like we did with t-tests, you can also look at the resulting HSD.test object (here, &lt;code&gt;tukey_bill_length&lt;/code&gt;) in your environment pane.&lt;/p&gt;
&lt;p&gt;Here, instead of using the &lt;code&gt;broom&lt;/code&gt; package, you can convert the part of the &lt;code&gt;tukey_bill_length&lt;/code&gt; object that contains the post-hoc groupings into a dataframe using &lt;a href=&#34;https://rdrr.io/r/base/as.data.frame.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;as.data.frame()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tidy_tukey&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/as.data.frame.html&#39;&gt;as.data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tukey_bill_length&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;groups&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;tidy_tukey&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                  bill_length_mm groups&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chinstrap:male         51.09412      a&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Gentoo:male            49.47377      b&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chinstrap:female       46.57353      c&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Gentoo:female          45.56379      c&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelie:male            40.39041      d&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelie:female          37.25753      e&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4-bringing-it-together-in-a-plot&#34;&gt;4. Bringing it together in a plot&lt;/h2&gt;
&lt;p&gt;We already looked at a first-pass plot, but let&amp;rsquo;s customize it now, and add our statistical info. Here is our base plot.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;First let&amp;rsquo;s make the plot more aesthetically pleasing.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggtheme.html&#39;&gt;theme_classic&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/labs.html&#39;&gt;labs&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Species&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill Length, in mm&#34;&lt;/span&gt;,
       color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Sex&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Culmen Bill Length Among Different Species, and by Sex&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data collected from Palmer LTER, Antarctica&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-15-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;We want to add the letters to this plot, so we can tell which groups of species by sex are significantly different. We are going to figure out what the maximum &lt;code&gt;bill_length_mm&lt;/code&gt; for each species by sex is, so it will help us determine where to put our letter labels. Then, we can add our labels to be higher than the largest data point.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_max&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;max_bill_length_mm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` has grouped output by &#39;species&#39;. You can override using the `.groups` argument.&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_length_max&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# Groups:   species [3]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   sex    max_bill_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie    female               42.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Adelie    male                 46  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Chinstrap female               58  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Chinstrap male                 55.8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Gentoo    female               50.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Gentoo    male                 59.6&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s add our post-hoc group info to &lt;code&gt;bill_length_max&lt;/code&gt;, since those two dataframes are not in the same order. We are going to use the function &lt;a href=&#34;https://tidyr.tidyverse.org/reference/separate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;separate()&lt;/code&gt;&lt;/a&gt; which we used back in a &lt;a href=&#34;https://biodash.github.io/codeclub/20_cleaning-up/#5---separate-character-columns&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;previous code club&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tidier_tukey&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;tidy_tukey&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tibble.tidyverse.org/reference/rownames.html&#39;&gt;rownames_to_column&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/separate.html&#39;&gt;separate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;col &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rowname&lt;/span&gt;,
           into &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;sex&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
           sep &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;:&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  

&lt;span class=&#39;nv&#39;&gt;bill_for_plotting&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate-joins.html&#39;&gt;full_join&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tidier_tukey&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_length_max&lt;/span&gt;,
                               by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;sex&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s plot.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_text.html&#39;&gt;geom_text&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_for_plotting&lt;/span&gt;,
            &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
                y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;max_bill_length_mm&lt;/span&gt;, 
                color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;,
                label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;groups&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-18-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Almost there. We want the letters to be over the right box plot (coloring here by &lt;code&gt;sex&lt;/code&gt; helps us to see what is going on better). Let&amp;rsquo;s fix it.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_text.html&#39;&gt;geom_text&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_for_plotting&lt;/span&gt;,
            &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
                y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;max_bill_length_mm&lt;/span&gt;, 
                color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;,
                label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;groups&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
            position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/position_dodge.html&#39;&gt;position_dodge&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.75&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
            show.legend &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/labs.html&#39;&gt;labs&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Groups with different letters are statistically different using a\n two way ANOVA and Tukey&#39;s post-hoc test&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-19-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Also remember Daniel showed us how we can do &lt;a href=&#34;https://biodash.github.io/codeclub/s02e10_ggpubr/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;somthing similar&lt;/a&gt; using the package &lt;code&gt;ggpubr&lt;/code&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout rooms&lt;/h2&gt;
&lt;p&gt;We have investigated &lt;code&gt;bill_length_mm&lt;/code&gt; - but what about &lt;code&gt;bill_depth_mm&lt;/code&gt;? Let&amp;rsquo;s investigate only the male penguins.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g sex  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie  Torge…           39.1          18.7              181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;750 male &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Adelie  Torge…           39.5          17.4              186        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;800 fema…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Adelie  Torge…           40.3          18                195        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;250 fema…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Adelie  Torge…           &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;                 &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Adelie  Torge…           36.7          19.3              193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;450 fema…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Adelie  Torge…           39.3          20.6              190        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;650 male &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1 more variable: year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Conduct an ANOVA to see if there are significant differences in &lt;code&gt;bill_depth_mm&lt;/code&gt; in the Palmer penguins by by &lt;code&gt;species&lt;/code&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
Use the function [`aov()`](https://rdrr.io/r/stats/aov.html). Make sure you provide a model formula. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_anova&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/aov.html&#39;&gt;aov&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;male&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
      &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/summary.html&#39;&gt;summary&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_anova&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;              Df Sum Sq Mean Sq F value Pr(&amp;gt;F)    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; species       2  453.0  226.51   294.7 &amp;lt;2e-16 ***&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Residuals   165  126.8    0.77                   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ---&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Signif. codes:  0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Conduct post-hoc tests to see where significant differences exist between your &lt;code&gt;species&lt;/code&gt;. You can use any post-hoc test you like.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
Check out the function [`LSD.test`](https://www.rdocumentation.org/packages/agricolae/versions/1.3-5/topics/LSD.test) and the p-value adjustment procedures. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
Using a Bonferroni correction  
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bonferroni_bill_depth&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/agricolae/man/LSD.test.html&#39;&gt;LSD.test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_anova&lt;/span&gt;, 
                      trt &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;, 
                      p.adj &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;bonferroni&#34;&lt;/span&gt;,
                      console &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Study: bill_depth_anova ~ &#34;species&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; LSD t Test for bill_depth_mm &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; P value adjustment method: bonferroni &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Mean Square Error:  0.7686065 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; species,  means and individual ( 95 %) CI&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;           bill_depth_mm       std  r      LCL      UCL  Min  Max&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelie         19.07260 1.0188856 73 18.87000 19.27520 17.0 21.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chinstrap      19.25294 0.7612730 34 18.95608 19.54981 17.5 20.8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Gentoo         15.71803 0.7410596 61 15.49640 15.93966 14.1 17.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Alpha: 0.05 ; DF Error: 165&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Critical Value of t: 2.418634 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Groups according to probability of means differences and alpha level( 0.05 )&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Treatments with the same letter are not significantly different.&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;           bill_depth_mm groups&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chinstrap      19.25294      a&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelie         19.07260      a&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Gentoo         15.71803      b&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Using Tukey&amp;rsquo;s posthoc test&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tukey_bill_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/agricolae/man/HSD.test.html&#39;&gt;HSD.test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_anova&lt;/span&gt;, 
                      trt &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;, 
                      console &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# prints the results to console&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Study: bill_depth_anova ~ &#34;species&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; HSD Test for bill_depth_mm &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Mean Square Error:  0.7686065 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; species,  means&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;           bill_depth_mm       std  r  Min  Max&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelie         19.07260 1.0188856 73 17.0 21.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chinstrap      19.25294 0.7612730 34 17.5 20.8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Gentoo         15.71803 0.7410596 61 14.1 17.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Alpha: 0.05 ; DF Error: 165 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Critical Value of Studentized Range: 3.344694 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Groups according to probability of means differences and alpha level( 0.05 )&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Treatments with the same letter are not significantly different.&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;           bill_depth_mm groups&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chinstrap      19.25294      a&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Adelie         19.07260      a&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Gentoo         15.71803      b&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Make a plot to express your findings. I will leave it up to you to decide what this plot will look like. Add your statistical findings.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
Review the information in section 4 of this post. You could also use the package `ggpubr`. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
Preparing to plot.
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_max&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;male&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/summarise.html&#39;&gt;summarize&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;max_bill_depth_mm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_depth_max&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   max_bill_depth_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;                 &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie                 21.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap              20.8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo                 17.3&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# grab group information from bonferroni test&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# species is a rowname instead of column so lets change that&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bonferroni_bill_depth_groups&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/as.data.frame.html&#39;&gt;as.data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bonferroni_bill_depth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;groups&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
                                                &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tibble.tidyverse.org/reference/rownames.html&#39;&gt;rownames_to_column&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;var &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# join dfs&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_depth_for_plotting&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate-joins.html&#39;&gt;full_join&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_max&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bonferroni_bill_depth_groups&lt;/span&gt;,
                                     by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# check&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_depth_for_plotting&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   max_bill_depth_mm bill_depth_mm groups&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                 &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie                 21.5          19.1 a     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap              20.8          19.3 a     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo                 17.3          15.7 b&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;male&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_jitter.html&#39;&gt;geom_jitter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_text.html&#39;&gt;geom_text&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_for_plotting&lt;/span&gt;,
            &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;max_bill_depth_mm&lt;/span&gt;,
                label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;groups&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggtheme.html&#39;&gt;theme_classic&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/theme.html&#39;&gt;theme&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;,
        plot.caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/element.html&#39;&gt;element_text&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/labs.html&#39;&gt;labs&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Species&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill Depth, in mm&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Culmen Bill Depth Among Different Species&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data collected from Palmer LTER, Antarctica&#34;&lt;/span&gt;,
       caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Species significantly affects bill depth as determined by one-way ANOVA \nwith significantly different species using Bonferroni post-hoc test at P &amp;lt; 0.05 indicated with different letters.&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-26-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;extra-material&#34;&gt;Extra material&lt;/h2&gt;
&lt;p&gt;This session was getting a bit long so I&amp;rsquo;m putting a section about testing assumptions here. ### Testing assumptions&lt;/p&gt;
&lt;p&gt;I know I said we weren&amp;rsquo;t going to talk about this, but I thought I&amp;rsquo;d be remiss if I didn&amp;rsquo;t show you how to test that you aren&amp;rsquo;t violating any of the assumptions needed to conduct an ANOVA. We went over this a little bit back in the session put together by Daniel Quiroz on &lt;a href=&#34;https://biodash.github.io/codeclub/s02e10_ggpubr/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ggpubr&lt;/a&gt; and adding statistical results to ggplots.&lt;/p&gt;
&lt;p&gt;Briefly, in order to use parametric procedures (like ANOVA), we need to be sure our data meets the assumptions for 1) normality and 2) constant variance. This can be done in a few different ways.&lt;/p&gt;
&lt;h4 id=&#34;shapiro-wilk-test-for-normality&#34;&gt;Shapiro-Wilk test for normality&lt;/h4&gt;
&lt;p&gt;We are going to use the Shapiro-Wilk test (using the function &lt;a href=&#34;https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;shapiro_test()&lt;/code&gt;&lt;/a&gt; which is in the package &lt;code&gt;rstatix&lt;/code&gt; to determine normality, but will do it groupwise. This function is a pipe-friendly wrapper for the function &lt;a href=&#34;https://www.rdocumentation.org/packages/stats/versions/3.6.2/topics/shapiro.test&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;shapiro.test()&lt;/code&gt;&lt;/a&gt;, which just means you can use it with pipes.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;rstatix&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html&#39;&gt;shapiro_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   variable       statistic         p&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; bill_length_mm     0.974 0.000&lt;span style=&#39;text-decoration: underline;&#39;&gt;011&lt;/span&gt;9&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;rstatix&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html&#39;&gt;shapiro_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   sex    variable       statistic       p&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie    female bill_length_mm     0.991 0.895  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Adelie    male   bill_length_mm     0.986 0.607  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Chinstrap female bill_length_mm     0.883 0.001&lt;span style=&#39;text-decoration: underline;&#39;&gt;70&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Chinstrap male   bill_length_mm     0.955 0.177  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Gentoo    female bill_length_mm     0.989 0.895  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Gentoo    male   bill_length_mm     0.940 0.005&lt;span style=&#39;text-decoration: underline;&#39;&gt;11&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Can we visualize normality in another way?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_histogram.html&#39;&gt;geom_histogram&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/facet_grid.html&#39;&gt;facet_grid&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/vars.html&#39;&gt;vars&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             rows &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/vars.html&#39;&gt;vars&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-28-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h4 id=&#34;equal-variance&#34;&gt;Equal variance&lt;/h4&gt;
&lt;p&gt;We can test for equal variance using Levene&amp;rsquo;s test, &lt;a href=&#34;https://www.rdocumentation.org/packages/rstatix/versions/0.7.0/topics/levene_test&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;levene_test()&lt;/code&gt;&lt;/a&gt; which is part of the &lt;code&gt;rstatix&lt;/code&gt; package. Again, this is a pipe-friendly wrapper for the function &lt;a href=&#34;https://www.rdocumentation.org/packages/lawstat/versions/3.4/topics/levene.test&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;levene.test()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;rstatix&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/levene_test.html&#39;&gt;levene_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                       &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;*&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     df1   df2 statistic     p&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;     5   327      1.40 0.222&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h3 id=&#34;extra-exercise-1&#34;&gt;Extra exercise 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Test the assumptions used by ANOVA to see if it is an appropriate test for you to use in this case. If it is not, find out what the appropriate test to use is, and then use it!&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
Test for normality and equal variance using [`shapiro_test()`](https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html) and [`levene_test()`](https://rpkgs.datanovia.com/rstatix/reference/levene_test.html) respectively. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
Testing for normality:
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;male&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/group_by.html&#39;&gt;group_by&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;rstatix&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/shapiro_test.html&#39;&gt;shapiro_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   variable      statistic      p&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie    bill_depth_mm     0.964 0.033&lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap bill_depth_mm     0.983 0.863 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo    bill_depth_mm     0.980 0.401&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Testing for equal variance:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;rstatix&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/levene_test.html&#39;&gt;levene_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;male&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                       &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;*&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     df1   df2 statistic     p&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;     2   165      2.30 0.103&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We are finding non-normal distribution of the male, Adelie penguins. I will take this opportunity to show you how to run non-parametric tests as well.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;extra-exercise-2&#34;&gt;Extra exercise 2&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Conduct an non-parametric ANOVA to see if there are significant differences in &lt;code&gt;bill_depth_mm&lt;/code&gt; in the Palmer penguins by by &lt;code&gt;species&lt;/code&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
The non-parametric version of a one-way ANOVA is the Kruskal-Wallis test, and you can use the `rstatix` function [`kruskal_test()`](https://www.rdocumentation.org/packages/rstatix/versions/0.7.0/topics/kruskal_test). &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_kruskal&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/drop_na.html&#39;&gt;drop_na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;male&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/rstatix/reference/kruskal_test.html&#39;&gt;kruskal_test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_depth_kruskal&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .y.               n statistic    df     p method        &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;*&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;         &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; bill_depth_mm   168      116.     2 6&lt;span style=&#39;color: #555555;&#39;&gt;e&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;-26&lt;/span&gt; Kruskal-Wallis&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Code Club S03E01: t-tests In R</title>
      <link>https://biodash.github.io/codeclub/s03e01_ttests/</link>
      <pubDate>Wed, 12 Jan 2022 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s03e01_ttests/</guid>
      <description>&lt;br&gt;
&lt;h2 id=&#34;learning-objectives&#34;&gt;Learning objectives&lt;/h2&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Identify the types of data structures underlying the inputs and outputs of a basic t-test in R, with focus on vectors, lists, and data frames.&lt;/li&gt;
&lt;li&gt;Use the &amp;ldquo;broom&amp;rdquo; package to clean (tidy) up t-test results.&lt;/li&gt;
&lt;li&gt;Create some t-test-related visualizations.&lt;/li&gt;
&lt;li&gt;Practice with some basic tidyverse/dplyr functions (&lt;code&gt;select()&lt;/code&gt;, &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;h2 id=&#34;notes-for-beginners&#34;&gt;Notes For Beginners&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;re starting this new session of Code Club a bit differently than we&amp;rsquo;ve started previous major sessions in that we&amp;rsquo;re not easing in with basic R material, but instead assuming a bit of prior knowledge. But if you&amp;rsquo;re new to Code Club and/or R though, don&amp;rsquo;t worry - this section, and the rest of us in Code Club are here to help. Below I&amp;rsquo;ll give a very brief overview of R, with an emphasis on things that will be relevant for today&amp;rsquo;s session. Remember too that all previous Code Club material is available online, so feel free to check that out. And please don&amp;rsquo;t hesitate to ask questions during the session, whether in the main room or in Breakout rooms. Some highlights for today&amp;rsquo;s session&amp;hellip;&lt;/p&gt;
&lt;p&gt;In R there are objects and functions.&lt;/p&gt;
&lt;h3 id=&#34;objects&#34;&gt;Objects&lt;/h3&gt;
&lt;p&gt;Objects are things you assign a name to, and we do that with something called the assignment operator ( &amp;lt;- )&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#assign the value 5 to an object named &#34;my_object&#34;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;my_object&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#ask R to return that object&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;my_object&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You create lots of objects as you work in R. They persist until you remove them or until you close your R session.&lt;/p&gt;
&lt;p&gt;Each object is categorized into a type of data structure. Some common ones in R (and ones relevant for this session) include vectors, lists, and data frames.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Vectors: Have one dimension, meaning they can be characterized by their length. &amp;ldquo;my_object&amp;rdquo; that I created above is a vector of length 1. If vectors contain more than one entry, all the entries must be of the same type, or class, at least from R&amp;rsquo;s perspective. Numeric, character, and logical (TRUE/FALSE) are a few examples, and &amp;ldquo;my_object&amp;rdquo; is a numeric vector.&lt;/li&gt;
&lt;li&gt;Lists: A list is an object that can store multiple objects. Unlike vectors, the different objects stored in a list can be of different types. For example, a list could have three entries - 1.) a numeric vector of length 5 that stores the values 10:14, 2.) another list that itself stores several objects, and 3.) a character vector of length 3 that stores &amp;ldquo;red&amp;rdquo;, &amp;ldquo;blue&amp;rdquo;, &amp;ldquo;green&amp;rdquo;.&lt;/li&gt;
&lt;li&gt;Data Frames: Data frames store &amp;ldquo;rectangular data&amp;rdquo;, meaning datasets that are organized into colums and rows, and specifically those that have the same number of rows for each column. They are somewhat analgous to an Excel spreadsheet, assuming the data in that worksheet are perfectly rectangular.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;functions&#34;&gt;Functions&lt;/h3&gt;
&lt;p&gt;Functions in R usually have a descriptive name that gives you an idea of what they do, and they look like&amp;hellip; &lt;a href=&#34;https://rdrr.io/r/base/mean.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mean()&lt;/code&gt;&lt;/a&gt; &lt;a href=&#34;https://rdrr.io/r/base/sum.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sum()&lt;/code&gt;&lt;/a&gt; &lt;a href=&#34;https://rdrr.io/r/base/c.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;c()&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;The &lt;a href=&#34;https://rdrr.io/r/base/c.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;c()&lt;/code&gt;&lt;/a&gt; one might not be all that descriptive, but it stands for combine, and is a function that&amp;rsquo;s used a lot to combine items into vectors of length &amp;gt;1.&lt;/p&gt;
&lt;p&gt;Inside the parentheses you often specify one or more objects for the function to operate on, and also might give some function-specific directives that tweak its behavior.&lt;/p&gt;
&lt;h3 id=&#34;syntax&#34;&gt;Syntax&lt;/h3&gt;
&lt;p&gt;There are essentially two dialects in R - often referred to as &amp;ldquo;base R&amp;rdquo; and the &amp;ldquo;tidyverse&amp;rdquo;. You should be able to do most anything you want in R with either approach, and they can be mixed and matched. In general, base R tends to use more parentheses, square brackets, and $&amp;rsquo;s, while with the &amp;ldquo;tidyverse&amp;rdquo; you&amp;rsquo;ll see functions like &lt;code&gt;select()&lt;/code&gt; and &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; a lot, along with the pipe symbol ( %&amp;gt;% ) which takes results from one function and &amp;ldquo;pipes&amp;rdquo; them directly into a next function. Admittedly, essentially having two languages can lead to confusion, especially if you&amp;rsquo;re just getting started. We mostly stick with &amp;ldquo;tidy&amp;rdquo; code during Code Club, as it tends to be easier to follow/interpret.&lt;/p&gt;
&lt;h3 id=&#34;data-visualization&#34;&gt;Data Visualization&lt;/h3&gt;
&lt;p&gt;R is really useful for creating data visualizations. Again, there are &amp;ldquo;base R&amp;rdquo;&amp;quot; ways to plot data and &amp;ldquo;tidyverse&amp;rdquo; ways, which utilize functions that are part of a package named &amp;ldquo;ggplot2&amp;rdquo;. While ggplot is a bit harder to learn than the base R plotting functions, it&amp;rsquo;s also much more powerful, and in sticking with the &amp;ldquo;tidy&amp;rdquo; theme, we generally use it. Plots in ggplot are built by adding one or more layers to a plot, and data are specified with aesthetics, which link aspects of the plot (like the x and y axes, colors for points or lines on the plot, etc) to columns of a data frame that store the data.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1----intro&#34;&gt;1 &amp;ndash; Intro&lt;/h2&gt;
&lt;p&gt;Starting today, the upcoming block of Code Club sessions will center around performing some common statistical tests in R. We don&amp;rsquo;t plan to dive in to a lot of statistical details, but will instead focus on practical aspects of running the tests/analyses. We&amp;rsquo;ll pay particular attention to things like the types/classes of data that need to go in to each test, the structure of the results that come out, and since R is so good with visualization, we&amp;rsquo;ll probably do a fair amount of plotting along the way too. Let&amp;rsquo;s go ahead and load the tidyverse before we get started&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In this session we&amp;rsquo;ll do t-tests with the &lt;a href=&#34;https://rdrr.io/r/stats/t.test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;t.test()&lt;/code&gt;&lt;/a&gt; function. First I&amp;rsquo;m going to use the &lt;a href=&#34;https://rdrr.io/r/stats/Normal.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;rnorm()&lt;/code&gt;&lt;/a&gt; function to get some example data to work with by generating random samples (N=20) for each of two populations from a normal distribution with a mean of 10 and standard deviation of 3.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#generate a sample for population 1&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pop1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;, mean &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, sd &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#view the population 1 data&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pop1&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 10.154661  7.498932  3.426916  7.597499 11.533421 16.520010  9.607716&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [8] 13.356270  5.174309 13.373562  9.085778  6.630155  6.513986 11.570739&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [15] 15.113513  9.793049 11.512667 11.191199 14.772047  5.842280&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#generate a sample for population 2&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pop2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;, mean &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, sd &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#view the population 2 data&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pop2&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  9.356629 13.664574 12.295782 16.459519 14.261572  9.605285  8.537716&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [8]  9.808906  7.465455 13.998645 11.770977 14.035046  4.744950 14.298506&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [15]  9.867982  8.149314  5.317449 12.199504  9.139201  9.280096&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;A t-test is a good choice here if we want to use our samples to draw inference around whether the true means of these two populations are different. First we can check the means of the samples&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pop1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 10.01344&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pop2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 10.71286&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The sample means are a bit different, but given they&amp;rsquo;re random samples, that&amp;rsquo;s not surprising even if they were drawn from the same population. The question is whether the observed difference in the means is large enough that, at some given level of confidence, we can infer that the true population means are different. Let&amp;rsquo;s take a look at the documentation for the &lt;a href=&#34;https://rdrr.io/r/stats/t.test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;t.test()&lt;/code&gt;&lt;/a&gt; function&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;?&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;t.test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;img src=&#34;images/ttest1.png&#34; alt=&#34;ttest help&#34;&gt;&lt;/p&gt;
&lt;p&gt;Like documentation for all R functions, this gives us some information on how to use &lt;a href=&#34;https://rdrr.io/r/stats/t.test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;t.test()&lt;/code&gt;&lt;/a&gt;. In its most basic form, the only thing that has to be provided is the &amp;lsquo;x&amp;rsquo; argument, though since we have a two-sample test, we&amp;rsquo;ll need to provide both &amp;lsquo;x&amp;rsquo; and &amp;lsquo;y&amp;rsquo;. According to the documentation, these need to be numeric vectors. Let&amp;rsquo;s check that they are&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/numeric.html&#39;&gt;is.numeric&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pop1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/vector.html&#39;&gt;is.vector&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pop1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/numeric.html&#39;&gt;is.numeric&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pop2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/vector.html&#39;&gt;is.vector&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pop2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Looks like our two sets of data are in the right format, so we can run the t-test&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#run the t-test&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/t.test.html&#39;&gt;t.test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop1&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Welch Two Sample t-test&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; data:  pop1 and pop2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; t = -0.65482, df = 37.453, p-value = 0.5166&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; alternative hypothesis: true difference in means is not equal to 0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 95 percent confidence interval:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  -2.862735  1.463895&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; sample estimates:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; mean of x mean of y &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  10.01344  10.71286&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This result gives us several pieces of information. If it&amp;rsquo;s not immediately apparent, we can again get some information about these results from the help, where the &amp;ldquo;Value&amp;rdquo; section tells us about what&amp;rsquo;s returned by the function&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;images/ttest2.png&#34; alt=&#34;ttest help2&#34;&gt;&lt;/p&gt;
&lt;p&gt;It says the result is a list, which is a flexible data structure in R that allows you to store multiple items of different types. This particular list has 10 entries. We can see details with the &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; command. First we&amp;rsquo;ll rerun &lt;a href=&#34;https://rdrr.io/r/stats/t.test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;t.test()&lt;/code&gt;&lt;/a&gt; and this time save the results as an object named &lt;em&gt;tresult&lt;/em&gt;&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#run t.test and save output to &#39;tresult&#39;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/t.test.html&#39;&gt;t.test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop1&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#get the structure of &#39;tresult&#39;&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 10&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ statistic  : Named num -0.655&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr &#34;t&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ parameter  : Named num 37.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr &#34;df&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ p.value    : num 0.517&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ conf.int   : num [1:2] -2.86 1.46&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;conf.level&#34;)= num 0.95&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ estimate   : Named num [1:2] 10 10.7&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr [1:2] &#34;mean of x&#34; &#34;mean of y&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ null.value : Named num 0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;names&#34;)= chr &#34;difference in means&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ stderr     : num 1.07&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ alternative: chr &#34;two.sided&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ method     : chr &#34;Welch Two Sample t-test&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ data.name  : chr &#34;pop1 and pop2&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  - attr(*, &#34;class&#34;)= chr &#34;htest&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Another (arguably better, or at least cleaner) way to view this list is by simply clicking on &lt;em&gt;tresult&lt;/em&gt; in the Environment window (usually top right on screen). Doing so allows us to view the object itself&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;images/ttest_res.png&#34; alt=&#34;ttest_result&#34;&gt;&lt;/p&gt;
&lt;p&gt;From this we see that the list of 10 items consists of a mixture of numerics and characters. Each of the list entries has a name, and the &amp;lsquo;$&amp;rsquo; can be used with the name of the entry to extract an item from the list (this applies to lists in general in R - not just this one). Alternatively, the square bracket notation can be used to index (pull out) items from the list. Let&amp;rsquo;s try several options for pulling out the pvalue, which is the 3rd entry&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p.value&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.5165855&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; $p.value&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.5165855&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.5165855&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We&amp;rsquo;ve talked in a number of previous Code Club sessions about working with tidy data - this list doesn&amp;rsquo;t fall in to that category, but can be converted to a tidy object with the &lt;code&gt;tidy()&lt;/code&gt; function from the broom package, which is installed as part of the tidyverse (though not loaded).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tidytresult&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;broom&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/generics/man/tidy.html&#39;&gt;tidy&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tresult&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;tidytresult&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 x 10&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   estimate estimate1 estimate2 statistic p.value parameter conf.low conf.high&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt;   -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.699&lt;/span&gt;&lt;span&gt;      10.0      10.7    -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.655&lt;/span&gt;&lt;span&gt;   0.517      37.5    -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;2.86&lt;/span&gt;&lt;span&gt;      1.46&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 2 more variables: method &amp;lt;chr&amp;gt;, alternative &amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;tidy()&lt;/code&gt; function from broom takes results from a number of base R functions and makes them tidy. Now instead of a list we have a data frame (which actually is just a special kind of list) with 10 columns (though note they don&amp;rsquo;t correspond directly to the 10 entries of the original list).&lt;/p&gt;
&lt;p&gt;Having results in this tidy format allows you to use the tidy approaches we&amp;rsquo;ve worked with in the past. Let&amp;rsquo;s try plotting the means of the two samples as a simple bar (column) plot. The two sample means are in the &lt;em&gt;estimate1&lt;/em&gt; and &lt;em&gt;estimate2&lt;/em&gt; columns. First we&amp;rsquo;ll create a separate data frame that stores those means in long format (the values in one column and associated labels in a separate column).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#get popualation 1 mean&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pop1_mean&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;tidytresult&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;estimate1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unlist.html&#39;&gt;unlist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#view population 1 mean&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pop1_mean&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; estimate1 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  10.01344&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#get popualation 1 mean&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pop2_mean&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;tidytresult&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;estimate2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unlist.html&#39;&gt;unlist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#view population 2 mean&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pop2_mean&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; estimate2 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  10.71286&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;means_to_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;mean&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pop1_mean&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;pop2_mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                            &lt;span class=&#39;s&#39;&gt;&#34;sample&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Population 1&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Population 2&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
&lt;span class=&#39;nv&#39;&gt;means_to_plot&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;               mean       sample&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; estimate1 10.01344 Population 1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; estimate2 10.71286 Population 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now we can use that data frame to create the plot with &lt;em&gt;ggplot2&lt;/em&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#get a basic plot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;means_to_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sample&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_col&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;And we can do a little customization&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#customize the plot a bit&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;means_to_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sample&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_col&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Mean Values From Random Samples&#34;&lt;/span&gt;, 
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Mean Value&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now let&amp;rsquo;s work with some real data. R has a small example dataset named &lt;em&gt;mtcars&lt;/em&gt; already built in. It&amp;rsquo;s a data frame with data on different models of car. It can be called with &lt;code&gt;mtcars&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;                      mpg cyl  disp  hp drat    wt  qsec vs am gear carb&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Mazda RX4           21.0   6 160.0 110 3.90 2.620 16.46  0  1    4    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Mazda RX4 Wag       21.0   6 160.0 110 3.90 2.875 17.02  0  1    4    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Datsun 710          22.8   4 108.0  93 3.85 2.320 18.61  1  1    4    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Hornet 4 Drive      21.4   6 258.0 110 3.08 3.215 19.44  1  0    3    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Hornet Sportabout   18.7   8 360.0 175 3.15 3.440 17.02  0  0    3    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Valiant             18.1   6 225.0 105 2.76 3.460 20.22  1  0    3    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Duster 360          14.3   8 360.0 245 3.21 3.570 15.84  0  0    3    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 240D           24.4   4 146.7  62 3.69 3.190 20.00  1  0    4    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 230            22.8   4 140.8  95 3.92 3.150 22.90  1  0    4    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 280            19.2   6 167.6 123 3.92 3.440 18.30  1  0    4    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 280C           17.8   6 167.6 123 3.92 3.440 18.90  1  0    4    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 450SE          16.4   8 275.8 180 3.07 4.070 17.40  0  0    3    3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 450SL          17.3   8 275.8 180 3.07 3.730 17.60  0  0    3    3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 450SLC         15.2   8 275.8 180 3.07 3.780 18.00  0  0    3    3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Cadillac Fleetwood  10.4   8 472.0 205 2.93 5.250 17.98  0  0    3    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Lincoln Continental 10.4   8 460.0 215 3.00 5.424 17.82  0  0    3    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chrysler Imperial   14.7   8 440.0 230 3.23 5.345 17.42  0  0    3    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Fiat 128            32.4   4  78.7  66 4.08 2.200 19.47  1  1    4    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Honda Civic         30.4   4  75.7  52 4.93 1.615 18.52  1  1    4    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Toyota Corolla      33.9   4  71.1  65 4.22 1.835 19.90  1  1    4    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Toyota Corona       21.5   4 120.1  97 3.70 2.465 20.01  1  0    3    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Dodge Challenger    15.5   8 318.0 150 2.76 3.520 16.87  0  0    3    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; AMC Javelin         15.2   8 304.0 150 3.15 3.435 17.30  0  0    3    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Camaro Z28          13.3   8 350.0 245 3.73 3.840 15.41  0  0    3    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Pontiac Firebird    19.2   8 400.0 175 3.08 3.845 17.05  0  0    3    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Fiat X1-9           27.3   4  79.0  66 4.08 1.935 18.90  1  1    4    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Porsche 914-2       26.0   4 120.3  91 4.43 2.140 16.70  0  1    5    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Lotus Europa        30.4   4  95.1 113 3.77 1.513 16.90  1  1    5    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Ford Pantera L      15.8   8 351.0 264 4.22 3.170 14.50  0  1    5    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Ferrari Dino        19.7   6 145.0 175 3.62 2.770 15.50  0  1    5    6&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Maserati Bora       15.0   8 301.0 335 3.54 3.570 14.60  0  1    5    8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Volvo 142E          21.4   4 121.0 109 4.11 2.780 18.60  1  1    4    2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As a quick reminder, &lt;code&gt;select()&lt;/code&gt; allows you to choose columns of a data frame by name, while &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; allows you to select rows based on one or more logical (True/False) expressions.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#example of &#34;select()&#34;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mpg&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;disp&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;carb&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;                      mpg  disp carb&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Mazda RX4           21.0 160.0    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Mazda RX4 Wag       21.0 160.0    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Datsun 710          22.8 108.0    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Hornet 4 Drive      21.4 258.0    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Hornet Sportabout   18.7 360.0    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Valiant             18.1 225.0    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Duster 360          14.3 360.0    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 240D           24.4 146.7    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 230            22.8 140.8    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 280            19.2 167.6    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 280C           17.8 167.6    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 450SE          16.4 275.8    3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 450SL          17.3 275.8    3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 450SLC         15.2 275.8    3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Cadillac Fleetwood  10.4 472.0    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Lincoln Continental 10.4 460.0    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chrysler Imperial   14.7 440.0    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Fiat 128            32.4  78.7    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Honda Civic         30.4  75.7    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Toyota Corolla      33.9  71.1    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Toyota Corona       21.5 120.1    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Dodge Challenger    15.5 318.0    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; AMC Javelin         15.2 304.0    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Camaro Z28          13.3 350.0    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Pontiac Firebird    19.2 400.0    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Fiat X1-9           27.3  79.0    1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Porsche 914-2       26.0 120.3    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Lotus Europa        30.4  95.1    2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Ford Pantera L      15.8 351.0    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Ferrari Dino        19.7 145.0    6&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Maserati Bora       15.0 301.0    8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Volvo 142E          21.4 121.0    2&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#example of &#34;filter()&#34;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;wt&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;                      mpg cyl  disp  hp drat    wt  qsec vs am gear carb&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Merc 450SE          16.4   8 275.8 180 3.07 4.070 17.40  0  0    3    3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Cadillac Fleetwood  10.4   8 472.0 205 2.93 5.250 17.98  0  0    3    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Lincoln Continental 10.4   8 460.0 215 3.00 5.424 17.82  0  0    3    4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Chrysler Imperial   14.7   8 440.0 230 3.23 5.345 17.42  0  0    3    4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We&amp;rsquo;ll focus on just a couple of the variables in this dataset: Horsepower (hp) and 1/4 mile time in seconds (qsec). Note that in some cases I&amp;rsquo;ve provided a couple equivalent solutions that represent a tidy way of doing things (generally preferred) and a non-tidy (aka base R) way of doing things, just so you can see the difference if you are interested. If this is likely to confuse you, feel free to ignore the alternative (non-tidy) parts.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;breakout-room-does-average-14-mile-speed-differ-for-high-and-low-horsepower-cars&#34;&gt;Breakout Room: Does Average 1/4-mile Speed Differ For High And Low Horsepower Cars?&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;We&amp;rsquo;ll define &amp;ldquo;low&amp;rdquo; horsepower cars as those with &amp;lt;120 hp, and &amp;ldquo;high&amp;rdquo; horsepower cars as &amp;gt;=120 hp. First let&amp;rsquo;s get the average 1/4-mile times (qsec) for each of these groups. Save these mean times as the objects &amp;lsquo;low_hp_time&amp;rsquo; and &amp;lsquo;high_hp_time&amp;rsquo;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt;, &lt;code&gt;select()&lt;/code&gt;, and &lt;a href=&#34;https://rdrr.io/r/base/unlist.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;unlist()&lt;/code&gt;&lt;/a&gt; to pull out the appropriate sets of numeric values for each group, and then &lt;a href=&#34;https://rdrr.io/r/base/mean.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mean()&lt;/code&gt;&lt;/a&gt; to get the averages. Note that &lt;a href=&#34;https://rdrr.io/r/base/unlist.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;unlist()&lt;/code&gt;&lt;/a&gt; takes a list or data frame object and &amp;ldquo;flattens&amp;rdquo; it, or in other words, simplifies it down to, in this case, a numeric vector. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution 1 (tidy)&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;low_hp_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;hp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;120&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;qsec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unlist.html&#39;&gt;unlist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;low_hp_time&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 18.91&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;high_hp_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;hp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;120&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;qsec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unlist.html&#39;&gt;unlist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;high_hp_time&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 16.91235&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution 2 (not tidy) &lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;low_hp_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;qsec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;hp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;120&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;span class=&#39;nv&#39;&gt;low_hp_time&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 18.91&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;high_hp_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;qsec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;hp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;120&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;high_hp_time&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 16.91235&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;br&gt;
&lt;p&gt;Now let&amp;rsquo;s plot those mean values with a bar plot (&lt;code&gt;geom_col()&lt;/code&gt;).&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; All ggplots (&lt;code&gt;geom_col()&lt;/code&gt; is a ggplot function) need input data from a data frame (or tibble, which is just a special data frame). First create a data frame named &amp;ldquo;time_df&amp;rdquo; that has a column named &amp;ldquo;time&amp;rdquo; that stores the average qsec values and a column named &amp;ldquo;hp_class&amp;rdquo; that indicates whether the corresponding time is for &amp;ldquo;High HP&amp;rdquo; or &amp;ldquo;Low HP&amp;rdquo; cars. Then map the ggplot &amp;ldquo;x&amp;rdquo; aesthetic to the &amp;ldquo;hp_class&amp;rdquo; column and the &amp;ldquo;y&amp;rdquo; aesthetic to the &amp;ldquo;time&amp;rdquo; column and add a &lt;code&gt;geom_col()&lt;/code&gt; layer.&lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;time_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;time&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;low_hp_time&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;high_hp_time&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                      &lt;span class=&#39;s&#39;&gt;&#34;hp_class&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Low HP&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;High HP&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;time_df&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;       time hp_class&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 18.91000   Low HP&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 16.91235  High HP&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;time_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;hp_class&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;time&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_col&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-18-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;br&gt;
&lt;p&gt;So, do these data provide evidence for true differences in 1/4 mile speed between high and low horsepower cars? Try running a t-test to test for differences in the two groups of 1/4 mile times, and save the pvalue as an object named &lt;em&gt;speed_p&lt;/em&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use the &lt;a href=&#34;https://rdrr.io/r/stats/t.test.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;t.test()&lt;/code&gt;&lt;/a&gt; function. Remember that the &amp;ldquo;x&amp;rdquo; and &amp;ldquo;y&amp;rdquo; arguments each need to be numeric vectors. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution 1 (tidy)&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#get the values for low-horsepower cars&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;low_hp_vals&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;hp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;120&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;qsec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unlist.html&#39;&gt;unlist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#get the values for high-horsepower cars&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;high_hp_vals&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;hp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;120&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;qsec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unlist.html&#39;&gt;unlist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#run the t-test and save the results&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;speed_res&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/t.test.html&#39;&gt;t.test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;low_hp_vals&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;high_hp_vals&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;speed_p&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;speed_res&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p.value&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;speed_p&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.001007059&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution 2 (not tidy)&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#get the values for low-horsepower cars&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;low_hp_vals&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;qsec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;hp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;120&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#get the values for high-horsepower cars&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;high_hp_vals&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;qsec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;hp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;120&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#run the t-test and save the results&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;speed_res&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/t.test.html&#39;&gt;t.test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;low_hp_vals&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;high_hp_vals&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;speed_p&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;speed_res&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p.value&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;speed_p&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.001007059&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;br&gt;
&lt;p&gt;Try running the same test as above, but this time, do it as a one-sided test, with the alternative hypothesis that the 1/4-mile time for the high-horsepower group will be lower than that for the low-horsepower group. How does the p-value from this test compare to the previous (two-sided) test?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Check out the &lt;em&gt;alternative&lt;/em&gt; argument on the t.test help page, along with information in the &lt;strong&gt;Details&lt;/strong&gt; section of that same page. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#run the t-test and save the results&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;speed_res&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/t.test.html&#39;&gt;t.test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;low_hp_vals&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;high_hp_vals&lt;/span&gt;, alternative &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;greater&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;speed_p&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;speed_res&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p.value&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;speed_p&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.0005035295&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus&#34;&gt;Bonus&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;br&gt;
&lt;p&gt;Let&amp;rsquo;s visualize the data in a different way. This time, try plotting the distribution of values in each of the samples together on a single plot. See if you can recreate the plot below&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-22-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; First obtain a long data frame with the raw values for both groups in one column, and an identifier (high-hp, low-hp) in another column. You can do this by hand, using similar methods as we used in exercises above, or you can go back to the original &lt;em&gt;mtcars&lt;/em&gt; data frame and use &lt;code&gt;mutate()&lt;/code&gt; in combination with either &lt;a href=&#34;https://rdrr.io/r/base/ifelse.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ifelse()&lt;/code&gt;&lt;/a&gt; or &lt;code&gt;case_when()&lt;/code&gt; to add the identifier column. Then use &lt;code&gt;geom_histogram()&lt;/code&gt;, adjusting the &lt;em&gt;alpha&lt;/em&gt; and &lt;em&gt;position&lt;/em&gt; arguments, and customize the theme and the labels. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;hp_class&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/ifelse.html&#39;&gt;ifelse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;hp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;120&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Low_HP&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;High_HP&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;qsec&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;hp_class&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_histogram&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.7&lt;/span&gt;, position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;identity&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Time (seconds)&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Count&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Distribution of 1/4 Mile Times By Horsepower Class&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-23-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>S02E12: Plotly</title>
      <link>https://biodash.github.io/codeclub/s02e12_plotly/</link>
      <pubDate>Thu, 09 Dec 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s02e12_plotly/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;prep-homework&#34;&gt;Prep homework&lt;/h2&gt;
&lt;h3 id=&#34;basic-computer-setup&#34;&gt;Basic computer setup&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/04_ggplot2/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll help you troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;new-to-ggplot&#34;&gt;New to ggplot?&lt;/h3&gt;
&lt;p&gt;Check out the PAST Code Club sessions covering &lt;code&gt;ggplot2&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/04_ggplot2/&#34;&gt;S01E04&lt;/a&gt;: intro to ggplot2&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/05_ggplot-round-2/&#34;&gt;S01E05&lt;/a&gt;: intro to ggplot2 round 2&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/10_faceting-animating/&#34;&gt;S01E10&lt;/a&gt;: faceting and animating&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e06_ggplot2/&#34;&gt;S02E06&lt;/a&gt;: another intro to ggplot2&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e07_ggplot2_part2/&#34;&gt;S02E07&lt;/a&gt;: a second intro to ggplot2 round 2&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e08_multiple_plots/&#34;&gt;S02E08&lt;/a&gt;: combining plots using faceting&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e09_multiple_plots_part2/&#34;&gt;S02E09&lt;/a&gt;: combining plots using faceting and patchwork&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e10_ggpubr/&#34;&gt;S02E10&lt;/a&gt;: adding statistics to plots&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you&amp;rsquo;ve never used &lt;code&gt;ggplot2&lt;/code&gt; before (or even if you have), you may find &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this cheat sheet&lt;/a&gt; useful.&lt;/p&gt;
&lt;br&gt;
&lt;h2 id=&#34;getting-started&#34;&gt;Getting Started&lt;/h2&gt;
&lt;h3 id=&#34;rmarkdown-for-todays-session&#34;&gt;RMarkdown for today&amp;rsquo;s session&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# directory for Code Club Session 15:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S02E12&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# directory for our RMarkdown&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# (&#34;recursive&#34; to create two levels at once.)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S02E12/Rmd/&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# save the url location for today&#39;s script&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;todays_Rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#39;s&#39;&gt;&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/S02E12_plotly/plotly.Rmd&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# indicate the name of the new Rmd&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;S02E12_Rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;S02E12/Rmd/S02E12_plotly.Rmd&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# go get that file! &lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;todays_Rmd&lt;/span&gt;,
              destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;S02E12_Rmd&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---what-is-plotly&#34;&gt;1 - What is plotly?&lt;/h2&gt;
&lt;p&gt;Today we are going to talk about making interactive plots using &lt;a href=&#34;https://plotly.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Plotly&lt;/a&gt;. Plotly exists in a variety of programming languages, but today we will be just talking about using it in &lt;a href=&#34;https://plotly.com/r/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R&lt;/a&gt;. All of the plotly documentation can be found &lt;a href=&#34;https://cran.r-project.org/web/packages/plotly/plotly.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you have never used &lt;code&gt;plotly&lt;/code&gt; before, install it with the code below.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;plotly&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here are some useful links to find info about using &lt;code&gt;ggplotly&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://plotly.com/ggplot2/#layout-options&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Basic ggplot2 charts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://plotly.com/r/plotly-fundamentals/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Plotly R library fundamentals&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://plotly-r.com/overview.html#intro-ggplotly&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Intro to &lt;code&gt;ggplotly()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://plotly.com/r/reference/layout/#&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Using &lt;code&gt;layout()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://plotly-r.com/controlling-tooltips.html#tooltip-text-ggplotly&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplotly()&lt;/code&gt; tooltips&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Before we start, there are two basic ways to use plot in R using plotly:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Using &lt;a href=&#34;https://www.rdocumentation.org/packages/plotly/versions/4.9.3/topics/ggplotly&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplotly()&lt;/code&gt;&lt;/a&gt; - this is what we will go over today because it has the same syntax as &lt;code&gt;ggplot()&lt;/code&gt; which we have already learned&lt;/li&gt;
&lt;li&gt;Using &lt;a href=&#34;https://www.rdocumentation.org/packages/plotly/versions/4.9.3/topics/plot_ly&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;plot_ly()&lt;/code&gt;&lt;/a&gt; - there is slightly more functionality in this function, but the syntax is all new, so I&amp;rsquo;d suggest if you can do what you want with &lt;a href=&#34;https://rdrr.io/pkg/plotly/man/ggplotly.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplotly()&lt;/code&gt;&lt;/a&gt;, do that. The syntax is not particularly hard so don&amp;rsquo;t be scared to use it if interactive plots are something you&amp;rsquo;re very interested in.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When you are googling about using plotly, you will find a combination of &lt;a href=&#34;https://rdrr.io/pkg/plotly/man/ggplotly.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplotly()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://rdrr.io/pkg/plotly/man/plot_ly.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;plot_ly()&lt;/code&gt;&lt;/a&gt; approaches, and some parts of the code are interchangable. The easiesy way to see which parts are, is to try.&lt;/p&gt;
&lt;p&gt;Also note, Google gets a bit confused when googling &amp;ldquo;ggplotly&amp;rdquo; and often returns information about just ggplot, so read extra carefully when problem solving.&lt;/p&gt;
&lt;p&gt;This is an example of work from my group where we have found plotly to be particularly useful.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-536289741&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./apples.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-536289741&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt; Data from &lt;a href=&#34;https://pubmed.ncbi.nlm.nih.gov/34472097/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Bilbrey et al., New Phytologist 2021&lt;/a&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2---load-libraries-get-data&#34;&gt;2 - Load libraries, get data&lt;/h2&gt;
&lt;p&gt;Lets load the libraries we are using for today.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://plotly-r.com&#39;&gt;plotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for making interactive plots&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/tidyverse/glue&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for easy pasting&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/ramnathv/htmlwidgets&#39;&gt;htmlwidgets&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for saving html files&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We are going to continue to use the pumpkins data we downloaded last week when we were learning about &lt;a href=&#34;https://biodash.github.io/codeclub/S02E11_shiny_intro/&#34;&gt;Shiny&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_csv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-10-19/pumpkins.csv&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Rows: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;28065&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Columns: &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;14&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;──&lt;/span&gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Column specification&lt;/span&gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;────────────────────────────────────────────────────────&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;font-weight: bold;&#39;&gt;Delimiter:&lt;/span&gt; &#34;,&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;chr&lt;/span&gt; (14): id, place, weight_lbs, grower_name, city, state_prov, country, gpc...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Use &lt;span style=&#39;color: #000000; background-color: #BBBBBB;&#39;&gt;`spec()`&lt;/span&gt; to retrieve the full column specification for this data.&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;ℹ&lt;/span&gt; Specify the column types or set &lt;span style=&#39;color: #000000; background-color: #BBBBBB;&#39;&gt;`show_col_types = FALSE`&lt;/span&gt; to quiet this message.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We will start with the wrangling that Matt shared with us last week, and then go from there.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;# separate the year column&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;separate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;col &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;id&lt;/span&gt;, into &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;vegetable&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, sep &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;-&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;# find and tag the rows that do not have data&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;delete &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;str_detect&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;place&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\d*\\s*Entries&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;# filter out the rows that do not have data&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;delete&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;==&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;# remove the tagging column&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;delete&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# rename the vegetables to their actual names&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;str_replace&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;^F$&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Field Pumpkin&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;str_replace&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;^P$&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Giant Pumpkin&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;str_replace&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;^S$&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Giant Squash&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;str_replace&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;^W$&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Giant Watermelon&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;str_replace&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;^L$&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Long Gourd&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;str_replace&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;^T$&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Tomato&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# get rid of commas in the weight_lbs column&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/numeric.html&#39;&gt;as.numeric&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/grep.html&#39;&gt;gsub&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;,&#34;&lt;/span&gt;,&lt;span class=&#39;s&#39;&gt;&#34;&#34;&lt;/span&gt;,&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Lets look at our data structure.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 28,011&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 15&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;2013&#34;, &#34;2013&#34;, &#34;2013&#34;, &#34;2013&#34;, &#34;2013&#34;, &#34;2013&#34;, &#34;201…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ vegetable         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Field Pumpkin&#34;, &#34;Field Pumpkin&#34;, &#34;Field Pumpkin&#34;, &#34;…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ place             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;1&#34;, &#34;2&#34;, &#34;3&#34;, &#34;4&#34;, &#34;5&#34;, &#34;5&#34;, &#34;7&#34;, &#34;8&#34;, &#34;9&#34;, &#34;10&#34;, &#34;…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ weight_lbs        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 154.5, 146.5, 145.0, 140.8, 139.0, 139.0, 136.5, 136…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ grower_name       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Ellenbecker, Todd &amp;amp; Sequoia&#34;, &#34;Razo, Steve&#34;, &#34;Ellen…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ city              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Gleason&#34;, &#34;New Middletown&#34;, &#34;Glenson&#34;, &#34;Combined Lo…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ state_prov        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Wisconsin&#34;, &#34;Ohio&#34;, &#34;Wisconsin&#34;, &#34;Wisconsin&#34;, &#34;Wisc…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ country           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;United States&#34;, &#34;United States&#34;, &#34;United States&#34;, &#34;…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ gpc_site          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Nekoosa Giant Pumpkin Fest&#34;, &#34;Ohio Valley Giant Pum…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ seed_mother       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;209 Werner&#34;, &#34;150.5 Snyder&#34;, &#34;209 Werner&#34;, &#34;109 Mar…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ pollinator_father &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Self&#34;, NA, &#34;103 Mackinnon&#34;, &#34;209 Werner &#39;12&#34;, &#34;open…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ ott               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;184.0&#34;, &#34;194.0&#34;, &#34;177.0&#34;, &#34;194.0&#34;, &#34;0.0&#34;, &#34;190.0&#34;, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ est_weight        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;129.00&#34;, &#34;151.00&#34;, &#34;115.00&#34;, &#34;151.00&#34;, &#34;0.00&#34;, &#34;141…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ pct_chart         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;20.0&#34;, &#34;-3.0&#34;, &#34;26.0&#34;, &#34;-7.0&#34;, &#34;0.0&#34;, &#34;-1.0&#34;, &#34;-4.0…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ variety           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note that all of the columns have the class &amp;ldquo;character&amp;rdquo; except &lt;code&gt;weight_lbs&lt;/code&gt; which is numeric. We could just fix this now, but I&amp;rsquo;m going to show you an alternative way to handle this in a minute.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3---create-base-ggplot-object&#34;&gt;3 - Create base ggplot object&lt;/h2&gt;
&lt;p&gt;Using the &lt;code&gt;pumpkins&lt;/code&gt; dataset lets work towards creating a plot that shows the distribution of weights of tomatoes by country. I will show you here how you can use &lt;code&gt;dplyr&lt;/code&gt; functions within your &lt;code&gt;ggplot2&lt;/code&gt; call.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Tomato&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;, 
             y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, 
             color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-7-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;We have a plot, its not horrible but it has a number of issues.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The country names are getting cut off because some are too long, and there are enough of them that we are having overlapping.&lt;/li&gt;
&lt;li&gt;We have an &lt;a href=&#34;https://www.displayr.com/what-is-overplotting/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;overplotting&lt;/a&gt; problem&lt;/li&gt;
&lt;li&gt;The x-axis countries are ordered alphabetically. We will order our axis based on something more meaningful, like a characteristic of our data (more about this later).&lt;/li&gt;
&lt;li&gt;The aesthetics need some adjustment for a more beautiful plot&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;We will work on making our plot a bit better, and then we will make it interactive, such that you can hover your mouse over each datapoint, and learn more about that datapoint than what is directly visualized in the plot.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4---optimize-our-base-plot&#34;&gt;4 - Optimize our base plot&lt;/h2&gt;
&lt;h3 id=&#34;1-prevent-country-name-overlap&#34;&gt;1. Prevent country name overlap&lt;/h3&gt;
&lt;p&gt;We can do this using by using &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/guide_axis.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;guide_axis()&lt;/code&gt;&lt;/a&gt; within a &lt;code&gt;scale&lt;/code&gt; function, here, &lt;code&gt;scale_x_discrete()&lt;/code&gt;. To learn more about ggplot scales, click &lt;a href=&#34;https://ggplot2-book.org/scales-guides.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Tomato&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;, 
             y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, 
             color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;scale_x_discrete&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;guide &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;guide_axis&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;n.dodge &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# dodge every other name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-8-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Wow that was easy. We still have some overlapping, though we have a big figure legend that is in this case, not necessary. Lets remove it.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Tomato&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;, 
             y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, 
             color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;scale_x_discrete&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;guide &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;guide_axis&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;n.dodge &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-9-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This is not the only way to fix the plot to avoid label overlap. Instead, you could put the x-axis country labels on an angle by using &lt;code&gt;theme(axis.text.x = element_text(angle = 45))&lt;/code&gt;.&lt;/p&gt;
&lt;h3 id=&#34;2-reduce-overplotting&#34;&gt;2. Reduce overplotting&lt;/h3&gt;
&lt;p&gt;For the countries that have a lot of tomato entries, its hard to see some individual data points because there are just so many of them. We can add some transparency to the datapoints such that its easier to see them. I am also playing around with &lt;code&gt;color&lt;/code&gt;, &lt;code&gt;fill&lt;/code&gt;, and point &lt;code&gt;shape&lt;/code&gt; so you can see what changing those values does to the plot.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Tomato&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;, 
             y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, 
             fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;21&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;,
        axis.text.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;angle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;45&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-10-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;We still have overplotting but I think this is an improvement.&lt;/p&gt;
&lt;h3 id=&#34;3-reorder-x-axis-to-something-meaningful&#34;&gt;3. Reorder x-axis to something meaningful&lt;/h3&gt;
&lt;p&gt;Our x-axis is currently ordered alphabetically. This is really a meaningless ordering - instead lets order our data by some characteristic of the data that we want to communicate to our viewer. For example, we could order by increasing mean tomato weight. This would tell us, just by looking at the order of the x-axis, which country has on average, the biggest tomatoes. This is something that is hard to see with the data in its current form.&lt;/p&gt;
&lt;p&gt;Remember before we saw that each of the columns except for &lt;code&gt;weight_lbs&lt;/code&gt; was of the class &amp;ldquo;character.&amp;rdquo; To allow reordering, we need to change &lt;code&gt;country&lt;/code&gt; to be a factor. We can do this directly in the &lt;code&gt;pumpkins&lt;/code&gt; dataframe, or we can do it within the ggplot call using the pipe &lt;a href=&#34;https://magrittr.tidyverse.org/reference/pipe.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;%&amp;gt;%&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;We will use &lt;a href=&#34;https://forcats.tidyverse.org/reference/fct_reorder.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fct_reorder()&lt;/code&gt;&lt;/a&gt; to do this, where we provide the the column we want to reorder (here, &lt;code&gt;country&lt;/code&gt;), and what we want to reorder based on (here, &lt;code&gt;weight_lbs&lt;/code&gt;), and what function to use for the reordering (here, &lt;code&gt;.fun = mean&lt;/code&gt;).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Tomato&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;country &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/factor.html&#39;&gt;as.factor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;fct_reorder&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, .fun &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
             y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, 
             fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;21&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;,
        axis.text.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;angle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;45&lt;/span&gt;, hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-11-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now we can see easily that Switzerland has the heaviest tomatoes on average entered into this competition.&lt;/p&gt;
&lt;h3 id=&#34;4-pretty-it-up&#34;&gt;4. Pretty it up&lt;/h3&gt;
&lt;p&gt;Let&amp;rsquo;s fix up the aesthetics of the plot, and adjust the axis labels, and add a title. Note, in the title, adding &lt;code&gt;\n&lt;/code&gt; into your title inserts a line break.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tomato_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Tomato&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;country &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/factor.html&#39;&gt;as.factor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;fct_reorder&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, .fun &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
             y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, 
             fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;21&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;,
        axis.text.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;angle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;45&lt;/span&gt;, hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Country&#34;&lt;/span&gt;,
        y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Weight (in lbs)&#34;&lt;/span&gt;,
        title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Weights of Tomatoes by Country Entered \nin the Great Pumpkin Commonwealth Competition&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;tomato_plot&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&#34;5---make-it-interactive-with-ggplotly&#34;&gt;5 - Make it interactive with &lt;code&gt;ggplotly()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;You can learn more about the &lt;a href=&#34;https://rdrr.io/pkg/plotly/man/ggplotly.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplotly()&lt;/code&gt;&lt;/a&gt; function, including its arguments &lt;a href=&#34;https://www.rdocumentation.org/packages/plotly/versions/4.9.3/topics/ggplotly&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/plotly/man/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tomato_plot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-846725139&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./tomato1.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-846725139&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Wow that was easy! Note that when you hover over a data point you see the information mapped in your &lt;code&gt;aes()&lt;/code&gt; statement &amp;ndash; this is the default. We will go over ways to change this.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;6---using-tooltip&#34;&gt;6 - Using tooltip&lt;/h2&gt;
&lt;p&gt;Using tooltip helps you to indicate what appears when you hover over different parts of your plot. You can learn more about controlling &lt;code&gt;tooltip&lt;/code&gt; &lt;a href=&#34;https://plotly-r.com/controlling-tooltips.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;What if we want to hover over each point and be able to tell who grew that tomato?&lt;/p&gt;
&lt;p&gt;To do this, we indicate what we want to hover with using &lt;code&gt;text =&lt;/code&gt; in our aesthetic mappings. Then, we indicate &lt;code&gt;tooltip = &amp;quot;text&amp;quot;&lt;/code&gt; to tell &lt;a href=&#34;https://rdrr.io/pkg/plotly/man/ggplotly.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplotly()&lt;/code&gt;&lt;/a&gt; what we want to hover.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tomato_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Tomato&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;country &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/factor.html&#39;&gt;as.factor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;fct_reorder&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, .fun &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
             y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, 
             fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;,
             text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;grower_name&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;21&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;,
        axis.text.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;angle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;45&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Country&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Weight (in lbs)&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Weights of Tomatoes by Country Entered \nin the Great Pumpkin Commonwealth Competition&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/plotly/man/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tomato_plot&lt;/span&gt;,
         tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-394258176&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./tomato2.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-394258176&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You can play around a lot with tooltip to get it to be exactly how you want, and you can include multiple things in your hover text.&lt;/p&gt;
&lt;p&gt;You can add multiple items to &lt;code&gt;text&lt;/code&gt;, and also use the function &lt;a href=&#34;https://glue.tidyverse.org/reference/glue.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;glue()&lt;/code&gt;&lt;/a&gt; which allows more intuitive pasting to get your hover text to in your preferred format.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tomato_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Tomato&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;country &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/factor.html&#39;&gt;as.factor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;fct_reorder&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, .fun &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
             y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, 
             fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;,
             text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Grown by &amp;#123;grower_name&amp;#125;
                         From &amp;#123;city&amp;#125;, &amp;#123;state_prov&amp;#125;&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;21&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;,
        axis.text.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;angle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;45&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Country&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Weight (in lbs)&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Weights of Tomatoes by Country Entered \nin the Great Pumpkin Commonwealth Competition&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/plotly/man/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tomato_plot&lt;/span&gt;,
         tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-684259371&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./tomato3.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-684259371&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;7---hover-label-aesthetics&#34;&gt;7 - Hover label aesthetics&lt;/h2&gt;
&lt;p&gt;You might not like the default hover text aesthetics, and can change them! You can do this using &lt;code&gt;style&lt;/code&gt; and &lt;code&gt;layout&lt;/code&gt; and adding these functions using the pipe &lt;a href=&#34;https://magrittr.tidyverse.org/reference/pipe.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;%&amp;gt;%&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# setting fonts for the plot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;font&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  family &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Calibri&#34;&lt;/span&gt;,
  size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;15&lt;/span&gt;,
  color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# setting hover label specs&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;label&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  bgcolor &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;#FF0000&#34;&lt;/span&gt;,
  bordercolor &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;transparent&#34;&lt;/span&gt;,
  font &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;font&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# we can do this bc we already set font&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# amending our ggplotly call to include new fonts and hover label specs&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/plotly/man/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tomato_plot&lt;/span&gt;, tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/plotly/man/style.html&#39;&gt;style&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hoverlabel &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;label&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/plotly/man/layout.html&#39;&gt;layout&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;font &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;font&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-698213574&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./tomato4.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-698213574&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;8---saving-your-plots&#34;&gt;8 - Saving your plots&lt;/h2&gt;
&lt;p&gt;Now that you&amp;rsquo;ve made a beautiful interactive plot, you probably want to save it.&lt;/p&gt;
&lt;p&gt;Assign the plot you want to save to an object, and use the function &lt;a href=&#34;https://rdrr.io/pkg/htmlwidgets/man/saveWidget.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;saveWidget()&lt;/code&gt;&lt;/a&gt; to save it. You can find the documentation &lt;a href=&#34;https://www.rdocumentation.org/packages/htmlwidgets/versions/1.5.3/topics/saveWidget&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# assign ggplotly plot to an object&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;ggplotly_to_save&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/plotly/man/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tomato_plot&lt;/span&gt;,
                             tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
                      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/plotly/man/style.html&#39;&gt;style&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hoverlabel &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;label&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
                      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/plotly/man/layout.html&#39;&gt;layout&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;font &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;font&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# save&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/htmlwidgets/man/saveWidget.html&#39;&gt;saveWidget&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;widget &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ggplotly_to_save&lt;/span&gt;,
           file &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ggplotlying.html&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout rooms&lt;/h2&gt;
&lt;p&gt;We are going to use the &lt;code&gt;palmerpenguins&lt;/code&gt; dataset called &lt;code&gt;penguins&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g sex  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie  Torge…           39.1          18.7              181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;750 male &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Adelie  Torge…           39.5          17.4              186        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;800 fema…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Adelie  Torge…           40.3          18                195        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;250 fema…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Adelie  Torge…           &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;                 &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Adelie  Torge…           36.7          19.3              193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;450 fema…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Adelie  Torge…           39.3          20.6              190        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;650 male &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1 more variable: year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Using the &lt;code&gt;penguins&lt;/code&gt; dataset and make a base scatter plot with bill length on the y, and bill depth on the x. Remove any observations with missing data.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
You can use `drop_na()` to remove NAs. The helper `any_of()` is useful for removing NAs only from certain variables. You can also just remove any NAs, it doesn&#39;t really matter here. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;any_of&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;bill_length_mm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-25-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Add appropriate x and y-axis labels, and a title to your plot.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
You can add labels for x, y, and a title using `labs().` &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;any_of&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;bill_length_mm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Culmen Depth (mm)&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Culmen Length (mm)&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Exploration of penguin bill length and depth relationships&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-26-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Make your plot interactive such that when you hover over a point, it tell you what island the penguin is from.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
Specify what you want your &#34;tooltip&#34; to be by using `text` within your `aes()` statement. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;any_of&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;bill_length_mm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Culmen Depth (mm)&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Culmen Length (mm)&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Exploration of penguin bill length and depth relationships&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/plotly/man/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;,
         tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-391285476&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./penguins1.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-391285476&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Add the sex of the penguin to the hover text, change the hover text so that the background color is red, and make all the fonts for the plot something other than the default.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
You can set fonts either within your `ggplot()` call, or setting `font` within [`layout()`](https://rdrr.io/pkg/plotly/man/layout.html). You can customize the hover label with [`style()`](https://rdrr.io/pkg/plotly/man/style.html). Use [`glue()`](https://glue.tidyverse.org/reference/glue.html) to paste in some information that helps your reader know what your hover text is referring to. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# setting fonts for the plot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_font&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  family &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Proxima Nova&#34;&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# this is the official OSU font&lt;/span&gt;
  size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;15&lt;/span&gt;,
  color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# setting hover label specs&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_label&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  bgcolor &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;blue&#34;&lt;/span&gt;,
  bordercolor &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;transparent&#34;&lt;/span&gt;,
  font &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_font&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# we can do this bc we already set font&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;any_of&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;bill_length_mm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, 
             text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://glue.tidyverse.org/reference/glue.html&#39;&gt;glue&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Island: &amp;#123;island&amp;#125;
                         Sex: &amp;#123;sex&amp;#125;&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Culmen Depth (mm)&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Culmen Length (mm)&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Exploration of penguin bill length and depth relationships&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# amending our ggplotly call to include new fonts and hover label specs&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/plotly/man/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;, tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/plotly/man/style.html&#39;&gt;style&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hoverlabel &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_label&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/plotly/man/layout.html&#39;&gt;layout&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;font &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_font&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-872365941&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./penguins2.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-872365941&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Code Club S02E11: Shiny Bright Like a Diamond</title>
      <link>https://biodash.github.io/codeclub/s02e11_shiny_intro/</link>
      <pubDate>Tue, 30 Nov 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s02e11_shiny_intro/</guid>
      <description>&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;&lt;strong&gt;What will we go over today&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What is Shiny, and why would I want to use it?&lt;/li&gt;
&lt;li&gt;Understanding the principles of user interfaces and servers&lt;/li&gt;
&lt;li&gt;The structure of a basic Shiny app&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;interactive-applications-with-r&#34;&gt;Interactive Applications with R&lt;/h2&gt;
&lt;p&gt;Shiny is a package that builds interactive html-based applications using the R coding language and capabilities.&lt;/p&gt;
&lt;p&gt;The goal of this session is to provide a basic introduction to the structure of simple Shiny apps. For more detailed information as you work to build more complicated apps, I recommend you reference the &lt;a href=&#34;https://shiny.rstudio.com/tutorial/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Shiny tutorial page&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The code for a Shiny app contains three main parts.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;A section defining the user interface (UI)&lt;/li&gt;
&lt;li&gt;A section defining the server&lt;/li&gt;
&lt;li&gt;A piece of code that combines the UI and server sections&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Let&amp;rsquo;s talk through some examples to illustrate what a UI and server are.&lt;/p&gt;
&lt;h3 id=&#34;a-conceptual-example&#34;&gt;A Conceptual Example&lt;/h3&gt;
&lt;p&gt;Imagine you are in need for directions from Columbus, OH to Wooster, OH.&lt;/p&gt;
&lt;p&gt;You decide to use a website such as Google maps to give you precise directions for the quickest route.&lt;/p&gt;
&lt;p&gt;You, the user, type in your location (Columbus) and your destination (Wooster), and as if by magic, turn-by-turn directions pop up on your screen.&lt;/p&gt;
&lt;p&gt;Everything you have just interacted with and experienced is the &lt;strong&gt;User Interface&lt;/strong&gt; of the maps application. Think of this as the front-end of the application.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;Server&lt;/strong&gt; is everything going on behind the scenes- the lines of code and calculations- invisible to the user- that take the user input and produce the results that are then presented back to the user.&lt;/p&gt;
&lt;h3 id=&#34;a-more-grounded-example&#34;&gt;A more grounded example&lt;/h3&gt;
&lt;p&gt;The OSU Infectious Disease Institute maintains a webapp that tracked COVID-19 statistics in Ohio from March 2020 to March 2021. Click or navigate to: &lt;a href=&#34;https://covidmap.osu.edu/&#34;&gt;https://covidmap.osu.edu/&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;This is a nice demonstration of a &amp;ldquo;data dashboard&amp;rdquo;, which is a very common use of the Shiny package.&lt;/p&gt;
&lt;p&gt;It provides a way for a user of virtually any skill level to interact with their COVID-19 data set. It may look very fancy, but it was all put together using Shiny and many R commands you already know.&lt;/p&gt;
&lt;p&gt;What function would the app use to pair down the data to the selected date range? What R package are they using the plot the daily counts of new cases?&lt;/p&gt;
&lt;p&gt;You can apply what you have already learned in code club to make a fancy, interactive web app for your own data sets!&lt;/p&gt;
&lt;p&gt;We just need to learn how to code R within the Shiny environment.&lt;/p&gt;
&lt;h3 id=&#34;lets-start-with-a-simple-shiny-app&#34;&gt;Let&amp;rsquo;s start with a simple Shiny app&lt;/h3&gt;
&lt;p&gt;First, take a second to install Shiny, and for the purpose of our demonstration today, I recommend you also pre-load the tidyverse (I am assuming you already have that installed)&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;shiny&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://shiny.rstudio.com/&#39;&gt;shiny&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can use a common structure to set up the basic parts of almost any shiny app. Below you will see that we are creating an object for the UI, another for the server, and then we combine them with the &lt;code&gt;shinyApp&lt;/code&gt; call. Before we start building the app, we need to tell it where to live on our computer.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;...&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/shinyApp.html&#39;&gt;shinyApp&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;ui &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt;, server &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Inside your directory for code club, create a folder for this week. In this folder, save a new R script with the name app.R&lt;/p&gt;
&lt;p&gt;Shiny uses the directory as a sort of bundle to run your app from. The name of your directory is the name of the app, the app.R file is the code, and there are other file types (with specific names) that you can add to the directory later as your app gets more complicated.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S02E12&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;lets-make-an-app&#34;&gt;Let&amp;rsquo;s make an app!&lt;/h2&gt;
&lt;p&gt;We are going to start simple, using a data set about large pumpkins, squashes, and tomatoes.&lt;/p&gt;
&lt;p&gt;First, let&amp;rsquo;s download the data and do a little cleanup.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#download the dataframe from github. This data can also be found in the `tidytuesdayR` package. &lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;readr&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_csv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-10-19/pumpkins.csv&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#the year and type of crop are combined into a single column, separated by a &#34;-&#34;. Need to split.&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#also, there are some rows in the data frame that contain information about the number of entries&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#need to remove these interceding rows&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#separate the year column&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyr.tidyverse.org/reference/separate.html&#39;&gt;separate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;col &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;id&lt;/span&gt;, into &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;vegetable&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, sep &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;-&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#find and tag the rows that do not have data&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/mutate.html&#39;&gt;mutate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;delete &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://stringr.tidyverse.org/reference/str_detect.html&#39;&gt;str_detect&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;place&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\d*\\s*Entries&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#filter out the rows that do not have data&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;delete&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;==&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#remove the tagging column&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;delete&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#Rename the vegetables to their actual names&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://stringr.tidyverse.org/reference/str_replace.html&#39;&gt;str_replace&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;^F$&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Field Pumpkin&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://stringr.tidyverse.org/reference/str_replace.html&#39;&gt;str_replace&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;^P$&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Giant Pumpkin&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://stringr.tidyverse.org/reference/str_replace.html&#39;&gt;str_replace&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;^S$&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Giant Squash&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://stringr.tidyverse.org/reference/str_replace.html&#39;&gt;str_replace&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;^W$&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Giant Watermelon&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://stringr.tidyverse.org/reference/str_replace.html&#39;&gt;str_replace&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;^L$&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Long Gourd&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://stringr.tidyverse.org/reference/str_replace.html&#39;&gt;str_replace&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;^T$&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Tomato&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#get rid of commas in the weight_lbs column&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/numeric.html&#39;&gt;as.numeric&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/grep.html&#39;&gt;gsub&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;,&#34;&lt;/span&gt;,&lt;span class=&#39;s&#39;&gt;&#34;&#34;&lt;/span&gt;,&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
&lt;span class=&#39;c&#39;&gt;#look at the data structure&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;user-interface&#34;&gt;User Interface&lt;/h3&gt;
&lt;p&gt;Now that we have our data sorted out, let&amp;rsquo;s start building out our user interface&lt;/p&gt;
&lt;p&gt;The UI portion of your code is where you will define the appearance and physical layout of your app, and in Shiny, layouts are commonly defined using &lt;a href=&#34;https://rdrr.io/pkg/shiny/man/fluidPage.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fluidPage()&lt;/code&gt;&lt;/a&gt;. Fluid pages scale to fill the available window size of your browser, and are formatted to a grid with 12 equally spaced columns and as many rows of equal height that you need for your app. Within the `fluidPage()&#39; command, you define how different components of your app physically fit within the browser window.&lt;/p&gt;
&lt;p&gt;There are some handy pre-sets that we can use to build an app more quickly, but just know that the interface you build is &lt;em&gt;very&lt;/em&gt; customizable with enough effort. For the purpose of this demonstration, we will use the preset commands that define a &lt;code&gt;sidebarPanel()&lt;/code&gt; for user inputs and a `mainPanel()&#39; for data output.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/fluidPage.html&#39;&gt;fluidPage&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;sidebarPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;mainPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;input&lt;/span&gt;,&lt;span class=&#39;nv&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/shinyApp.html&#39;&gt;shinyApp&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;ui&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt;,server&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This is the basic layout of our app. It may read a little funny because I am leaving space to put in different components.&lt;/p&gt;
&lt;p&gt;Now, back to our example dataset. The World Pumpkin Committee is very interested in being able to view the weight distribution of each vegetable by year. Let&amp;rsquo;s make them an app for that!&lt;/p&gt;
&lt;p&gt;We will add a place for them to select the year in &lt;a href=&#34;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sidebarPanel()&lt;/code&gt;&lt;/a&gt; Shiny has a number of data input options. The one you pick, will depend on what information you want to get from the user. No matter the input, you will need to specify the &lt;code&gt;InputID&lt;/code&gt;. This piece of information is very important, as it is how the server references the inputs in the UI.&lt;/p&gt;
&lt;p&gt;For this example, we have a defined set of inputs (this competition has only been going on for a set number of years), so we will use &lt;a href=&#34;https://rdrr.io/pkg/shiny/man/selectInput.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;selectInput()&lt;/code&gt;&lt;/a&gt;. We will also define the choices as the years avilable in our dataset.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/fluidPage.html&#39;&gt;fluidPage&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;sidebarPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#here we are naming the input as &#39;year&#39;, the box will display &#39;Select Year&#39;, and &lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#the user will choose from the competition years as referenced from the &lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#pumpkins dataframe&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/selectInput.html&#39;&gt;selectInput&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;inputId &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;, label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Select Year&#34;&lt;/span&gt;, choices &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;mainPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;input&lt;/span&gt;,&lt;span class=&#39;nv&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/shinyApp.html&#39;&gt;shinyApp&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;ui&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt;,server&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We now have the input side of our UI, but we also need to define what and where our output will be by essentially adding a placeholder for our output. There are many options in Shiny, but we will be using a &lt;a href=&#34;https://rdrr.io/pkg/shiny/man/plotOutput.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;plotOutput()&lt;/code&gt;&lt;/a&gt; for this example. The main thing that needs to be set is the &lt;code&gt;OutputID&lt;/code&gt;. Similar to the &lt;code&gt;InputID&lt;/code&gt;, this tells the server where to place our results.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/fluidPage.html&#39;&gt;fluidPage&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;sidebarPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#here we are naming the input as &#39;year&#39;, the box will display &#39;Select Year&#39;, and &lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#the user will choose from the competition years as referenced from the &lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#pumpkins dataframe&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/selectInput.html&#39;&gt;selectInput&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;inputId &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;, label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Select Year&#34;&lt;/span&gt;, choices &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;mainPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#placeholder for a plot to generate&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/plotOutput.html&#39;&gt;plotOutput&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outputId &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;weight_distribution&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;input&lt;/span&gt;,&lt;span class=&#39;nv&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/shinyApp.html&#39;&gt;shinyApp&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;ui&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt;,server&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Run this whole chunk of code. Notice you will create a &lt;code&gt;ui&lt;/code&gt; object and a &lt;code&gt;server&lt;/code&gt; function that are combined with &lt;code&gt;shinyApp&lt;/code&gt;. Once you run that last piece, a built in web browser will appear and run your app.&lt;/p&gt;
&lt;p&gt;When you are not using the app, be sure to fully exit the browser window, otherwise it will keep running in the background.&lt;/p&gt;
&lt;h3 id=&#34;server&#34;&gt;Server&lt;/h3&gt;
&lt;p&gt;Now that we have our UI built, let&amp;rsquo;s move on to the server. This is where you will code what R should do with inputs from the UI side and how results should be presented to the user.&lt;/p&gt;
&lt;p&gt;Notice the server is built as a &lt;code&gt;function()&lt;/code&gt; with &lt;code&gt;input&lt;/code&gt; and &lt;code&gt;output&lt;/code&gt; objects.&lt;/p&gt;
&lt;p&gt;For our example. we basically want to use the &lt;code&gt;inputID&lt;/code&gt; &amp;ldquo;year&amp;rdquo; to filter our list, then we want to plot the weight distribution of each vegetable.This is done using code you are likely already familiar with.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/fluidPage.html&#39;&gt;fluidPage&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;sidebarPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#here we are naming the input as &#39;year&#39;, the box will display &#39;Select year&#39;, and &lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#the user will choose from the competition years as referenced from the &lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#pumpkins dataframe&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/selectInput.html&#39;&gt;selectInput&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;inputId &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;, label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Select Year&#34;&lt;/span&gt;, choices &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;mainPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
     &lt;span class=&#39;c&#39;&gt;#placeholder for a plot to generate&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/plotOutput.html&#39;&gt;plotOutput&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outputId &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;weight_distribution&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;input&lt;/span&gt;,&lt;span class=&#39;nv&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#notice the callback to our outputID&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;weight_distribution&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/renderPlot.html&#39;&gt;renderPlot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;==&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;input&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/shinyApp.html&#39;&gt;shinyApp&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;ui&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt;,server&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice how the &lt;code&gt;outputID&lt;/code&gt; from the &lt;code&gt;ui&lt;/code&gt; section is referenced as &lt;code&gt;output$weight_distribution&lt;/code&gt; on the server side. Do you see where our &lt;code&gt;inputID&lt;/code&gt; is referenced on the server side?&lt;/p&gt;
&lt;p&gt;Also notice how the code is wrapped within a &lt;code&gt;renderPlot&lt;/code&gt; command. This is a special Shiny command specific to plot outputs. There are other commands for other types of outputs, such as &lt;code&gt;renderTable&lt;/code&gt; for table outputs.&lt;/p&gt;
&lt;p&gt;These commands are also special because they are &amp;ldquo;reactive&amp;rdquo;, meaning they react to changes in user inputs and re-execute the code when those changes occur. This is a simple explanation of a somewhat complex topic. For a more in-depth explanation, see &lt;a href=&#34;https://shiny.rstudio.com/articles/understanding-reactivity.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this explanation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Re-run the code, and you should now see a plot that will respond to changes in the year input box.&lt;/p&gt;
&lt;h2 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h2&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now it is your turn to add on to the app. The World Pumpkin Committee would like to also have the app generate a table that contains the weight, grower name, city, and state/province of each first place vegetable for the year selected in the input.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Bonus&lt;/strong&gt; Explore &lt;code&gt;renderTable&lt;/code&gt; to see how you can change the number of significant figures displayed.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Focus on the server side of the app, you already have the input from the UI that you need. Use &lt;a href=&#34;https://rdrr.io/pkg/shiny/man/renderTable.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;renderTable()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/fluidPage.html&#39;&gt;fluidPage&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;sidebarPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#here we are naming the input as &#39;year&#39;, the box will display &#39;Select year&#39;, and &lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#the user will choose from the competition years as referenced from the &lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#pumpkins dataframe&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/selectInput.html&#39;&gt;selectInput&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;inputId &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt;, label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Select Year&#34;&lt;/span&gt;, choices &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;mainPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
     &lt;span class=&#39;c&#39;&gt;#placeholder for a plot to generate&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/plotOutput.html&#39;&gt;plotOutput&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outputId &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;weight_distribution&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/tableOutput.html&#39;&gt;tableOutput&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outputId &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;winner_table&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;input&lt;/span&gt;,&lt;span class=&#39;nv&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#notice the callback to our outputID&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;weight_distribution&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/renderPlot.html&#39;&gt;renderPlot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;==&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;input&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#39;&gt;geom_boxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;#create the output for the table using renderTable&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;winner_table&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/renderTable.html&#39;&gt;renderTable&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;nv&#39;&gt;pumpkins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;==&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;input&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;place&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;1&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/select.html&#39;&gt;select&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vegetable&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;grower_name&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;city&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;state_prov&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&lt;a href=&#39;https://magrittr.tidyverse.org/reference/pipe.html&#39;&gt;%&amp;gt;%&lt;/a&gt;&lt;/span&gt;
      &lt;span class=&#39;c&#39;&gt;#I just wanted to rename the columns to look nicer&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/rename.html&#39;&gt;rename&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;weight (lbs)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;weight_lbs&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;grower name&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;grower_name&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;state/provice&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;state_prov&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
    &lt;span class=&#39;c&#39;&gt;#setting significant figures as an option under renderTable&lt;/span&gt;
    digits &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,
    &lt;span class=&#39;c&#39;&gt;#adding a caption to be fancy&lt;/span&gt;
    caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Table of Winners&#34;&lt;/span&gt;,
    caption.placement &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;top&#34;&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/shinyApp.html&#39;&gt;shinyApp&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;ui&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt;,server&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h2&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Create a new app that allows a user to visualize how changing the value of &amp;ldquo;m&amp;rdquo; in y=mx+b affects the slope of a line.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; You will need to define the values of x. You can do this within the server function (i.e. &lt;code&gt;a &amp;lt;- tibble(a=-100:100)&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Also note that changing the slope of a line may not be so noticable because plots will automatically adjust to the scale of the data. Consider locking your coordinates so you notice changing slopes more easily.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/fluidPage.html&#39;&gt;fluidPage&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;sidebarPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;c&#39;&gt;#I chose sliderInput here, you can choose another input type&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sliderInput.html&#39;&gt;sliderInput&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;inputId &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;slope&#34;&lt;/span&gt;, min &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, max &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, value &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Slope&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;mainPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/plotOutput.html&#39;&gt;plotOutput&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outputId &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;graph&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;input&lt;/span&gt;,&lt;span class=&#39;nv&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tibble.tidyverse.org/reference/tibble.html&#39;&gt;tibble&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;a&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;nv&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;graph&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/renderPlot.html&#39;&gt;renderPlot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;input&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;slope&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;*&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_path.html&#39;&gt;geom_line&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/coord_cartesian.html&#39;&gt;coord_cartesian&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;xlim &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;25&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;25&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, ylim &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/shinyApp.html&#39;&gt;shinyApp&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;ui&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt;,server&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h2&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Add on to your app from Exercise 2 by providing another input for user to adjust the y-intercept.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/fluidPage.html&#39;&gt;fluidPage&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;sidebarPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sliderInput.html&#39;&gt;sliderInput&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;inputId &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;slope&#34;&lt;/span&gt;, min &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, max &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, value &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Slope&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sliderInput.html&#39;&gt;sliderInput&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;inputId &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;intercept&#34;&lt;/span&gt;, min &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, max &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, value &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Y-Intercept&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/sidebarLayout.html&#39;&gt;mainPanel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/plotOutput.html&#39;&gt;plotOutput&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outputId &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;graph&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;input&lt;/span&gt;,&lt;span class=&#39;nv&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tibble.tidyverse.org/reference/tibble.html&#39;&gt;tibble&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;a&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;nv&#39;&gt;output&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;graph&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/renderPlot.html&#39;&gt;renderPlot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/ggplot.html&#39;&gt;ggplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;input&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;slope&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;*&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;input&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;intercept&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/geom_path.html&#39;&gt;geom_line&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/coord_cartesian.html&#39;&gt;coord_cartesian&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;xlim &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;25&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;25&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, ylim &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/shiny/man/shinyApp.html&#39;&gt;shinyApp&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;ui&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ui&lt;/span&gt;,server&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;server&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Code Club S02E10: An introduction to ggpubr</title>
      <link>https://biodash.github.io/codeclub/s02e10_ggpubr/</link>
      <pubDate>Wed, 03 Nov 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s02e10_ggpubr/</guid>
      <description>&lt;br&gt;
&lt;h1 id=&#34;learning-objectives&#34;&gt;Learning objectives&lt;/h1&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Understand what is a &lt;em&gt;ggplot&lt;/em&gt; extension&lt;/li&gt;
&lt;li&gt;Define what is &lt;em&gt;ggpubr&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Recognize the advantages and drawback of &lt;em&gt;ggpubr&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Create a density plot with &lt;em&gt;ggpubr&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Add statistical results to density plots&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;understand-what-is-a-ggplot-extension&#34;&gt;Understand what is a &lt;em&gt;ggplot&lt;/em&gt; extension&lt;/h2&gt;
&lt;p&gt;A &lt;em&gt;ggplot&lt;/em&gt; extension is a set of functions that helps in the automation of a given task. In the case of &lt;em&gt;ggplot&lt;/em&gt; extensions, there are 102 registered extensions up today.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;ggplot&lt;/em&gt;&amp;rsquo;s extensions are developed based on the core of &lt;em&gt;ggplot&lt;/em&gt; and help to create a customized plot with certain features such as animation, specific color scales, or to produce a ready to publish figure.&lt;/p&gt;
&lt;p&gt;The &lt;a href=&#34;https://exts.ggplot2.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;ggplot&lt;/em&gt; extensions website&lt;/a&gt; has an overview of the available extensions:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;iframe src=&#34;https://exts.ggplot2.tidyverse.org/gallery/&#34; width=&#34;100%&#34; height=&#34;400px&#34; data-external=&#34;1&#34;&gt;
&lt;/iframe&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;define-what-is-ggpubr&#34;&gt;Define what is &lt;em&gt;ggpubr&lt;/em&gt;&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;ggpubr&lt;/em&gt; is an R package that produces ggplot-based plots with a more elegant aesthetic. Although &lt;em&gt;ggpubr&lt;/em&gt; has default figures themes, plots usually require some formatting before sending them for publication.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;getting-everything-ready&#34;&gt;Getting everything ready&lt;/h2&gt;
&lt;p&gt;First, we can take a look at the data that we are going to use. In this case, since we are already familiar with &lt;em&gt;palmerpenguins&lt;/em&gt; dataset, we are going to continue using this data.&lt;/p&gt;
&lt;p&gt;To remember the data structure, we can use the &lt;code&gt;glimpse&lt;/code&gt; function.&lt;/p&gt;
&lt;div class=&#34;alert alert-warning&#34;&gt;
&lt;div&gt;
&lt;p&gt;If you do not have installed the palmergenguins library, you can do it with this line. If you already have it, skip this line.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To install the ggpubr package for the first time, you can use this command.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;ggpubr&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;loading-all-required-packages&#34;&gt;Loading all required packages&lt;/h3&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;A good programming style is to load all necessary packages at the very beginning of the script.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;      &lt;span class=&#39;c&#39;&gt;# To load all packages including in the tidyverse&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# Load the example data&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/&#39;&gt;ggpubr&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;         &lt;span class=&#39;c&#39;&gt;# Create ready to publish figures&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;remembering-the-palmer-penguins-data&#34;&gt;Remembering the palmer penguins data&lt;/h3&gt;
&lt;p&gt;&lt;img src=&#34;./culmen_depth.png&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 344&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ island            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Torgersen, Torgersen, Torgersen, Torgersen, Torgerse…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_length_mm    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_depth_mm     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ flipper_length_mm &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ body_mass_g       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sex               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; male, female, female, NA, female, male, female, male…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;For the downstream example, we are going to contrast the bill depth of the female vs male penguins of the Adelie species found on the island of Biscoe.&lt;/p&gt;
&lt;p&gt;Therefore, we need to filter based on &lt;code&gt;species == Adelie&lt;/code&gt; and &lt;code&gt;island == Biscoe&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Filter by species and island&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_filtered&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Biscoe&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Count the occurence of the factors levels of sex, species and island&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_filtered&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 2 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   sex    species island     n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; female Adelie  Biscoe    22&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; male   Adelie  Biscoe    22&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;creating-the-plot-with-ggplot&#34;&gt;Creating the plot with ggplot&lt;/h3&gt;
&lt;p&gt;One of the main differences between &lt;em&gt;ggplot&lt;/em&gt; and &lt;em&gt;ggpubr&lt;/em&gt; is the syntax to create the base plot. In the case of &lt;em&gt;ggplot&lt;/em&gt;, it is a layer based syntax, while in &lt;em&gt;ggpubr&lt;/em&gt;, the syntax is embedded in a single function.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_filtered&lt;/span&gt;,
       &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-7-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now, since &lt;em&gt;ggpubr&lt;/em&gt; has its own built-in geoms, we can use the &lt;a href=&#34;https://rpkgs.datanovia.com/ggpubr/reference/ggboxplot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggboxplot()&lt;/code&gt;&lt;/a&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;base_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/ggboxplot.html&#39;&gt;ggboxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_filtered&lt;/span&gt;,
                       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;sex&#34;&lt;/span&gt;,
                       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt;,
                       fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;sex&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;base_plot&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-8-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;Since &lt;em&gt;ggpubr&lt;/em&gt; creates plots based on &lt;em&gt;ggplot&lt;/em&gt; syntax, you can treat these plots as another &lt;em&gt;ggplot&lt;/em&gt; figure and use the same functions that you would use to format base &lt;em&gt;ggplot&lt;/em&gt; plots.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;base_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/ggboxplot.html&#39;&gt;ggboxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_filtered&lt;/span&gt;,
                       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;sex&#34;&lt;/span&gt;,
                       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt;,
                       fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;sex&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Comparison between Adelie penguins by sex&#34;&lt;/span&gt;,
       fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Sex:&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Sex&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill depth (mm)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;base_plot&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-9-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;add-statistical-results-to-the-density-plot&#34;&gt;Add statistical results to the density plot&lt;/h2&gt;
&lt;p&gt;When hypotheses testing is brought to the table, we need to consider which type of stats we can and cannot apply to our data. Briefly, if our data fits the assumptions of being normally distributed and having variance homogeneity, we can apply parametric tests. On the other hand, if our data does not fit the assumptions, we need to apply a nonparametric test to the data.&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Comparison&lt;/th&gt;
&lt;th&gt;Parametric&lt;/th&gt;
&lt;th&gt;Nonparametric&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;2 groups&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;t-test&lt;/td&gt;
&lt;td&gt;Wilcoxon test&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&amp;gt;2 groups&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;one-way anova&lt;/td&gt;
&lt;td&gt;Krustal-Wallis test&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;checking-assumptions&#34;&gt;Checking assumptions&lt;/h3&gt;
&lt;p&gt;If we would like to conduct a hypotheses test, we need first to check assumptions (homogeneity of variance and and normality):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/bartlett.test.html&#39;&gt;bartlett.test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;, data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_filtered&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Bartlett test of homogeneity of variances&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; data:  bill_depth_mm by sex&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Bartlett&#39;s K-squared = 0.94576, df = 1, p-value = 0.3308&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;exploring-the-stat_compare_means-function&#34;&gt;Exploring the &lt;code&gt;stat_compare_means()&lt;/code&gt; function&lt;/h3&gt;
&lt;p&gt;We can use the function &lt;a href=&#34;https://rpkgs.datanovia.com/ggpubr/reference/stat_compare_means.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;stat_compare_means()&lt;/code&gt;&lt;/a&gt; to annotate the plot with the results of a statistical test comparing group means:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;base_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/stat_compare_means.html&#39;&gt;stat_compare_means&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-11-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In order to be 100% sure about the computed p-value, we can compute the Wilcoxon test in the console:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/wilcox.test.html&#39;&gt;wilcox.test&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;~&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;, data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_filtered&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Wilcoxon rank sum test with continuity correction&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; data:  bill_depth_mm by sex&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; W = 72, p-value = 6.79e-05&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; alternative hypothesis: true location shift is not equal to 0&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;using-ggplot-to-recreate-the-plot&#34;&gt;Using &lt;em&gt;ggplot&lt;/em&gt; to recreate the plot&lt;/h3&gt;
&lt;p&gt;Above, we created the base plot using &lt;em&gt;ggpubr&lt;/em&gt; syntax, but we don&amp;rsquo;t need to do this. The following code would create a very similar plot using &lt;em&gt;ggplot&lt;/em&gt; syntax and then only adding the &lt;a href=&#34;https://rpkgs.datanovia.com/ggpubr/reference/stat_compare_means.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;stat_compare_means()&lt;/code&gt;&lt;/a&gt; at the end:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_filtered&lt;/span&gt;,
       &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_bw&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/stat_compare_means.html&#39;&gt;stat_compare_means&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h3 id=&#34;breakout-rooms-i-10-min&#34;&gt;Breakout Rooms I (10 min)&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Filter the penguins data in order to have only the observations (rows) from the Chinstrap species from Dream island.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a boxplot using the &lt;em&gt;ggpubr&lt;/em&gt; package or using base &lt;em&gt;ggplot&lt;/em&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use &lt;em&gt;stat_compare_means()&lt;/em&gt; function to add a p-value.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Use the &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; function to filter rows&lt;/li&gt;
&lt;li&gt;Filter using &lt;code&gt;species == Chinstrap&lt;/code&gt; and &lt;code&gt;island == Dream&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;If you want to use the &lt;em&gt;ggpubr&lt;/em&gt; package to create the boxplot, use the &lt;a href=&#34;https://rpkgs.datanovia.com/ggpubr/reference/ggboxplot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggboxplot()&lt;/code&gt;&lt;/a&gt; function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Using ggpubr&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Filter by species and island&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_exc1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Chinstrap&#34;&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Dream&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Create the plot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;exc1_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/ggboxplot.html&#39;&gt;ggboxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_exc1&lt;/span&gt;,
                       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;sex&#34;&lt;/span&gt;,
                       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt;,
                       fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;sex&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/stat_compare_means.html&#39;&gt;stat_compare_means&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Show the plot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;exc1_plot&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Using ggplot only&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Filter by species and island&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_exc1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Chinstrap&#34;&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Dream&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Create the plot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;exc1_plot_ggplot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_exc1&lt;/span&gt;,
                           &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/stat_compare_means.html&#39;&gt;stat_compare_means&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_bw&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Show the plot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;exc1_plot_ggplot&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-15-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h3 id=&#34;multiple-group-comparison-within-a-variable&#34;&gt;Multiple group comparison within a variable&lt;/h3&gt;
&lt;p&gt;In many experiments we can have multiple groups in a single variable. For example, within a variable &lt;em&gt;nutrient concentration&lt;/em&gt; we can have multiple nutrient concentration levels such as 10%, 20%, 30% and so on.&lt;/p&gt;
&lt;p&gt;In the case of the penguins data we can find this layout if we need to compare the males bill depth between species. Only for teaching purposes, we are not going to consider any difference by island.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_male&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;male&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;penguins_male&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   sex       n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie    male     73&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap male     34&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo    male     61&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_male_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/ggboxplot.html&#39;&gt;ggboxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_male&lt;/span&gt;,
                                x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;,
                                y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt;,
                                color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_male_plot&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-17-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Like before, we can use the function &lt;code&gt;stat_compare_means&lt;/code&gt; to add a p-value for an overall comparison between groups:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_male_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/stat_compare_means.html&#39;&gt;stat_compare_means&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-18-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;However, we may also be interested in getting a p-value for the different pairwise comparisons between groups. For instance, does the bill depth of Chinstrap penguins differ significantly from that in Gentoo penguins?&lt;/p&gt;
&lt;p&gt;To do this, we can pass a &lt;em&gt;list&lt;/em&gt; to that the &lt;code&gt;stat_compare_means&lt;/code&gt; function. A list is a flexible, hierarchical R data structure. Here, we will use a list to store multiple vectors, each of which contains a pairwise comparison of interest:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;comparison_list&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Chinstrap&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                        &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Chinstrap&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Gentoo&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                        &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Gentoo&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;penguins_male_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/stat_compare_means.html&#39;&gt;stat_compare_means&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;comparisons &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;comparison_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/stat_compare_means.html&#39;&gt;stat_compare_means&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;label.y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;25&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-19-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h3 id=&#34;breakout-rooms-ii-10-min&#34;&gt;Breakout Rooms II (10 min)&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Filter the penguins data in order to have only the observations (rows) from female penguins.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a boxplot using the &lt;em&gt;ggpubr&lt;/em&gt; package.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add the multiple group comparison&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add pairwise comparisons between all groups combinations&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use the &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; function to select desired rows&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Filter by &lt;code&gt;sex == &amp;quot;female&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use &lt;a href=&#34;https://rpkgs.datanovia.com/ggpubr/reference/ggboxplot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggboxplot()&lt;/code&gt;&lt;/a&gt; function for the base plot&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use the &lt;a href=&#34;https://rpkgs.datanovia.com/ggpubr/reference/stat_compare_means.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;stat_compare_means()&lt;/code&gt;&lt;/a&gt; function for multiple group comparison&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use the &lt;code&gt;comparison&lt;/code&gt; argument to add pairwise comparison&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Filtering by sex&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_exc2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;c&#39;&gt;# Filter by species and island&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;female&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Creating the base plot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;exc2_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/ggboxplot.html&#39;&gt;ggboxplot&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_exc2&lt;/span&gt;,
                       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;,
                       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;bill_depth_mm&#34;&lt;/span&gt;,
                       fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Adding the multiple group comparison&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;exc2_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;exc2_plot&lt;/span&gt; 

&lt;span class=&#39;c&#39;&gt;# Creating the pairwise comparison&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;exc2_comparison&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt;  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Chinstrap&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                         &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Chinstrap&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Gentoo&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                         &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Gentoo&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;exc2_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;exc2_plot&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/stat_compare_means.html&#39;&gt;stat_compare_means&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;comparisons &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;comparison_list&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rpkgs.datanovia.com/ggpubr/reference/stat_compare_means.html&#39;&gt;stat_compare_means&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;label.y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;25&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;exc2_plot&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-20-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
</description>
    </item>
    
    <item>
      <title>Code Club S02E09: Combining Plots - Part 2</title>
      <link>https://biodash.github.io/codeclub/s02e09_multiple_plots_part2/</link>
      <pubDate>Tue, 26 Oct 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s02e09_multiple_plots_part2/</guid>
      <description>&lt;br&gt;
&lt;h2 id=&#34;learning-objectives&#34;&gt;Learning objectives&lt;/h2&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Continue to practice creating plots with ggplot&lt;/li&gt;
&lt;li&gt;Compare the ggplot functions &lt;code&gt;facet_grid()&lt;/code&gt; and &lt;code&gt;facet_wrap()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Arrange multiple plots of different types on a single figure&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1----intro&#34;&gt;1 &amp;ndash; Intro&lt;/h2&gt;
&lt;p&gt;In the previous session we worked with the &lt;code&gt;facet_wrap()&lt;/code&gt; function from ggplot, which allowed us to use some variable (column) in the dataset to partition data into multiple panels of a single plot. In this session, we&amp;rsquo;ll see how the &lt;code&gt;facet_wrap()&lt;/code&gt; approach compares to a similar function, &lt;code&gt;facet_grid()&lt;/code&gt;, and also explore the &lt;em&gt;patchwork&lt;/em&gt; package, which offers more control and flexibility in arranging multiple plots in a single figure.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll continue to use &lt;em&gt;tidyverse&lt;/em&gt; functions and data from &lt;em&gt;palmerpenguins&lt;/em&gt;, so install those if you need to. If you already have them installed, just load them into your current R session with the &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; functions below&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And now let&amp;rsquo;s preview/explore the penguins dataset just to remind ourselves of what&amp;rsquo;s in there&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g sex  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;           &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.1          18.7              181        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;750 male &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.5          17.4              186        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;800 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Adelie  Torge…           40.3          18                195        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;250 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Adelie  Torge…           &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Adelie  Torge…           36.7          19.3              193        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;450 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.3          20.6              190        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;650 male &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1 more variable: year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/summary.html&#39;&gt;summary&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;       species          island    bill_length_mm  bill_depth_mm  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Adelie   :152   Biscoe   :168   Min.   :32.10   Min.   :13.10  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Chinstrap: 68   Dream    :124   1st Qu.:39.23   1st Qu.:15.60  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Gentoo   :124   Torgersen: 52   Median :44.45   Median :17.30  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                                  Mean   :43.92   Mean   :17.15  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                                  3rd Qu.:48.50   3rd Qu.:18.70  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                                  Max.   :59.60   Max.   :21.50  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                                  NA&#39;s   :2       NA&#39;s   :2      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  flipper_length_mm  body_mass_g       sex           year     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Min.   :172.0     Min.   :2700   female:165   Min.   :2007  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  1st Qu.:190.0     1st Qu.:3550   male  :168   1st Qu.:2007  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Median :197.0     Median :4050   NA&#39;s  : 11   Median :2008  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Mean   :200.9     Mean   :4202                Mean   :2008  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  3rd Qu.:213.0     3rd Qu.:4750                3rd Qu.:2009  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Max.   :231.0     Max.   :6300                Max.   :2009  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  NA&#39;s   :2         NA&#39;s   :2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;2----review-of-facet_wrap&#34;&gt;2 &amp;ndash; Review Of &lt;code&gt;facet_wrap()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Last week we started with a plot Michael Broe had previously constructed&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-4-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;We then used &lt;code&gt;facet_wrap()&lt;/code&gt; to present the data for the three species in separate panels, in place of using color&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-5-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Then as part of the breakout rooms, we tried faceting on more than one variable - we subsetted the dataset for only Adelie penguins, then plotted the relationship between bill length and bill depth faceted across both &lt;em&gt;island&lt;/em&gt; and &lt;em&gt;sex&lt;/em&gt;&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-6-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&#34;3----facet_grid&#34;&gt;3 &amp;ndash; &lt;code&gt;facet_grid()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;While you can use &lt;code&gt;facet_wrap()&lt;/code&gt; as above, &lt;code&gt;facet_grid()&lt;/code&gt; is often a better option when faceting on two variables. Here&amp;rsquo;s what the example above looks like with &lt;code&gt;facet_grid()&lt;/code&gt;&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_grid&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;rows &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-7-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Notice that with &lt;code&gt;facet_grid()&lt;/code&gt; we specify which variable defines the rows and which variable defines the columns.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;breakout-rooms-i-facet-grids&#34;&gt;Breakout Rooms I: Facet Grids&lt;/h3&gt;
&lt;h4 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Try analyzing the relationship between Adelie penguin bill length and bill depth separately for each combination of &lt;em&gt;year&lt;/em&gt; and &lt;em&gt;sex&lt;/em&gt;. Make the columns represent male/female, and the rows represent the different years (in this case, 2007-2009).&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; to select out Adelie penguins, then create a scatter plot similar to the one in the &lt;code&gt;facet_grid()&lt;/code&gt; example. Assign the rows as &lt;em&gt;year&lt;/em&gt; and the columns as &lt;em&gt;sex&lt;/em&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_grid&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;rows &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-8-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now let&amp;rsquo;s modify the plot you just created a bit. Add the title &amp;ldquo;Bill Dimensions Of Adelie Penguins&amp;rdquo;, and move the year labels from the right side to the left side of the plot.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Check out the &lt;em&gt;switch&lt;/em&gt; option in the &lt;code&gt;facet_grid()&lt;/code&gt; documentation for moving the year labels. For the title, consider &lt;code&gt;labs()&lt;/code&gt; or &lt;code&gt;ggtitle()&lt;/code&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_grid&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;rows &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, switch &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;y&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggtitle&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Bill Dimensions Of Adelie Penguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-9-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4----multi-panel-plots-patchwork&#34;&gt;4 &amp;ndash; Multi-Panel Plots: Patchwork&lt;/h2&gt;
&lt;p&gt;Faceting with &lt;code&gt;facet_wrap()&lt;/code&gt; or &lt;code&gt;facet_grid()&lt;/code&gt; works when you want to partition the plots based on one or more variables in the dataset. But if you want to arrange multiple plots into one figure, possibly even different types of plots, one good option is the &lt;em&gt;patchwork&lt;/em&gt; package. Let&amp;rsquo;s install and load it&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;patchwork&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://patchwork.data-imaginist.com&#39;&gt;patchwork&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;With &lt;em&gt;patchwork&lt;/em&gt;, you create and save each plot as a separate object. Then, once you&amp;rsquo;ve made the plots, you just tell patchwork how to arrange them. The syntax to define the layout is based on common mathematical operators.&lt;/p&gt;
&lt;p&gt;Some examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;plot1 + plot2&lt;/code&gt; puts two plots side-by-side&lt;/li&gt;
&lt;li&gt;&lt;code&gt;plot1 / plot2&lt;/code&gt; stacks two plots vertically&lt;/li&gt;
&lt;li&gt;&lt;code&gt;plot1 / (plot2 + plot3)&lt;/code&gt; gives plot1 on a top row, and plots 2 and 3 on a bottom row&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;In the examples above, &lt;em&gt;plot1&lt;/em&gt;, &lt;em&gt;plot2&lt;/em&gt;, and &lt;em&gt;plot3&lt;/em&gt; represent plots that have been saved as objects with those names.&lt;/p&gt;
&lt;p&gt;Below is an example from &lt;em&gt;palmerpenguins&lt;/em&gt;. First we create the plots, saving each as a new object&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;avg_island_lgth&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;mean_bill_length&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mean_bill_length&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_col&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggtitle&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Average Penguin Bill Length&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;mass_by_sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggtitle&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Effect of Sex on Penguin Size&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;lgth_by_depth&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggtitle&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Relationship Between Bill Length and Bill Depth&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then we simply use the patchwork syntax to define how these 3 plots will be arranged. In this case, the first (faceted) plot on top, with the other two side-by-side below it&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;lgth_by_depth&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;avg_island_lgth&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mass_by_sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;breakout-rooms-ii-combining-plots&#34;&gt;Breakout Rooms II: Combining Plots&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Use the palmerpenguin data to try to create the plot below&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint 1 (Boxplot)&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; For the boxplot, use &lt;code&gt;geom_boxplot()&lt;/code&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint 2 (Boxplot)&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Notice that R initially interprets the &lt;em&gt;year&lt;/em&gt; variable as a continuous variable, but boxplots need a discrete x axis. Convert that variable to character or factor. You can use &lt;code&gt;mutate&lt;/code&gt; along with &lt;code&gt;as.character&lt;/code&gt; or &lt;code&gt;as.factor&lt;/code&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint 3 (Plot Formatting)&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; For the formatting, try &lt;code&gt;theme_classic()&lt;/code&gt; &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint 4 (Labels 1)&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; The title and axis labels can be specified with &lt;code&gt;labs()&lt;/code&gt;, among other options. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint 5 (Labels 2)&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; To get the &amp;lsquo;A&amp;rsquo; and &amp;lsquo;B&amp;rsquo; plot annotations, check out the help page for the &lt;a href=&#34;https://patchwork.data-imaginist.com/reference/plot_annotation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;plot_annotation()&lt;/code&gt;&lt;/a&gt; function within &lt;em&gt;patchwork&lt;/em&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_flipper&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Relationship Between Bill Length and Flipper Length&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill Length (mm)&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Flipper Length (mm)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
&lt;span class=&#39;nv&#39;&gt;mass_yr&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;year&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/character.html&#39;&gt;as.character&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Size Over Time&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Body Mass (g)&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Year&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_flipper&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mass_yr&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://patchwork.data-imaginist.com/reference/plot_annotation.html&#39;&gt;plot_annotation&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;tag_levels &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;A&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Code Club S02E08: Combining Plots</title>
      <link>https://biodash.github.io/codeclub/s02e08_multiple_plots/</link>
      <pubDate>Tue, 19 Oct 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s02e08_multiple_plots/</guid>
      <description>&lt;br&gt;
&lt;h2 id=&#34;learning-objectives&#34;&gt;Learning objectives&lt;/h2&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Continue to practice creating plots with ggplot&lt;/li&gt;
&lt;li&gt;Use faceting to divide a plot into multiple panels according to some variable.&lt;/li&gt;
&lt;li&gt;Arrange multiple plots of different types on a single figure.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1----intro&#34;&gt;1 &amp;ndash; Intro&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;ll continue with our theme on plotting by exploring some options for arranging multiple plots on a single figure. A couple scenarios where you might want to do this&amp;hellip;&lt;/p&gt;
&lt;p&gt;1.) You create a plot that needs to be subdivided according to some variable, possibly because accounting for that variable is important for the interpretation, or maybe there&amp;rsquo;s just too much on one plot and it helps to split the data up according to some factor.&lt;/p&gt;
&lt;p&gt;2.) You have a series of different plots that all address some related question, maybe each in a slightly different way, and you want to present them all in one figure.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll take a couple approaches during this and next week&amp;rsquo;s sessions to deal with these two scenarios. Today we&amp;rsquo;ll look at some &lt;em&gt;ggplot&lt;/em&gt; functions like &lt;code&gt;facet_wrap()&lt;/code&gt; and &lt;code&gt;facet_grid()&lt;/code&gt; that allow us to easily deal with scenario 1. Then in the next session we&amp;rsquo;ll try a separate package, &lt;em&gt;patchwork&lt;/em&gt;, that offers one good option for scenario 2.&lt;/p&gt;
&lt;p&gt;Like in previous sessions, we&amp;rsquo;ll use some packages from the &lt;em&gt;tidyverse&lt;/em&gt; and also the &lt;em&gt;palmerpenguins&lt;/em&gt; dataset. If you haven&amp;rsquo;t installed either of those yet, you can do so with the following commands. If you installed them previously, you can just run the latter of the commands (&lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt;) to load them for the current session.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And now let&amp;rsquo;s preview/explore the penguins dataset just to remind ourselves of what&amp;rsquo;s in there&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g sex  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;           &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.1          18.7              181        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;750 male &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.5          17.4              186        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;800 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Adelie  Torge…           40.3          18                195        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;250 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Adelie  Torge…           &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Adelie  Torge…           36.7          19.3              193        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;450 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.3          20.6              190        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;650 male &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1 more variable: year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/summary.html&#39;&gt;summary&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;       species          island    bill_length_mm  bill_depth_mm  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Adelie   :152   Biscoe   :168   Min.   :32.10   Min.   :13.10  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Chinstrap: 68   Dream    :124   1st Qu.:39.23   1st Qu.:15.60  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Gentoo   :124   Torgersen: 52   Median :44.45   Median :17.30  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                                  Mean   :43.92   Mean   :17.15  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                                  3rd Qu.:48.50   3rd Qu.:18.70  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                                  Max.   :59.60   Max.   :21.50  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                                  NA&#39;s   :2       NA&#39;s   :2      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  flipper_length_mm  body_mass_g       sex           year     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Min.   :172.0     Min.   :2700   female:165   Min.   :2007  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  1st Qu.:190.0     1st Qu.:3550   male  :168   1st Qu.:2007  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Median :197.0     Median :4050   NA&#39;s  : 11   Median :2008  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Mean   :200.9     Mean   :4202                Mean   :2008  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  3rd Qu.:213.0     3rd Qu.:4750                3rd Qu.:2009  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Max.   :231.0     Max.   :6300                Max.   :2009  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  NA&#39;s   :2         NA&#39;s   :2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;2----faceting&#34;&gt;2 &amp;ndash; Faceting&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s start by revisiting some plots Michael Broe created in his intro to ggplot a couple sessions ago. He was using the plots to investigate whether a relationship exists between the variables &lt;em&gt;bill length&lt;/em&gt; and &lt;em&gt;bill depth&lt;/em&gt; in these penguins. A scatterplot with a line of best fit from &lt;em&gt;ggplot&lt;/em&gt;&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_smooth).&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-4-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;As Michael pointed out previously, mapping an additional aesthetic (color) to the variable &lt;em&gt;species&lt;/em&gt; helps us see a relationship a little more clearly&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_smooth).&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-5-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The color aesthetic partitions the data according to some variable (in this case, species), and here helps add important information to the visualization. An alternative might be to plot the data in separate panels, with each corresponding to a different species. We can do that with either of two functions from ggplot, &lt;code&gt;facet_wrap()&lt;/code&gt; or &lt;code&gt;facet_grid()&lt;/code&gt;. Let&amp;rsquo;s start with &lt;code&gt;facet_wrap()&lt;/code&gt;. This is added as an additional layer to the plot, and indicates one or more variables that will be used to split the data into separate panels. I&amp;rsquo;ll facet here by species.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_smooth).&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-6-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The effect here is similar to what we did with adding a color aesthetic to the &lt;em&gt;species&lt;/em&gt; variable earlier - it allows us to evaluate the relationship between bill length and bill depth for each species separately.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;breakout-rooms-faceting&#34;&gt;Breakout Rooms: Faceting&lt;/h3&gt;
&lt;h4 id=&#34;exercise-1-analyze-adelie-penguins-by-island&#34;&gt;Exercise 1: Analyze Adelie Penguins By Island&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Try analyzing the relationship between bill length and bill depth for just the Adelie penguins (the only species with observations from each of the three islands). For this species, try faceting by island. Does the relationship seem to be consistent across all islands?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; to select out Adelie penguins, then create a plot similar to the one in the example, but facet on &lt;em&gt;island&lt;/em&gt; instead of &lt;em&gt;species&lt;/em&gt; &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;island&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 1 rows containing non-finite values (stat_smooth).&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 1 rows containing missing values (geom_point).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-7-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;exercise-2a-multiple-facets&#34;&gt;Exercise 2a: Multiple Facets&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now building on the plot you just created for Adelie Penguins, what if you wanted to facet on not just &lt;em&gt;island&lt;/em&gt;, but a combination of &lt;em&gt;island&lt;/em&gt; and &lt;em&gt;sex&lt;/em&gt;? Give it a try.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; &lt;code&gt;facet_wrap()&lt;/code&gt; accepts a character vector of column names. Use the c() function to provide a vector with two column names. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;island&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;sex&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 1 rows containing non-finite values (stat_smooth).&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 1 rows containing missing values (geom_point).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-8-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;exercise-2b-multiple-facets&#34;&gt;Exercise 2b: Multiple Facets&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;There are some facets coming through in that last plot that are based on NA&amp;rsquo;s. Try getting rid of all observations that include missing data before creating the plot.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use the &lt;code&gt;drop_na()&lt;/code&gt; function to remove observations with NA before calling ggplot. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;island&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;sex&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-9-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;exercise-3-axis-scales&#34;&gt;Exercise 3: Axis Scales&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now let&amp;rsquo;s go back to the full dataset where we faceted by species. The code we used (with the &lt;code&gt;drop_na&lt;/code&gt; function added), along with its associated plot, are below&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-10-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Use the help page for &lt;code&gt;facet_wrap&lt;/code&gt; to look in to the &lt;em&gt;scales&lt;/em&gt; option. Try changing the value of this option to see what effect it has on the plot.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint 1&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;code&gt;?facet_wrap&lt;/code&gt; to get the help page for the function, and find information about the &lt;em&gt;scales&lt;/em&gt; option. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint 2&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Within the &lt;code&gt;facet_wrap()&lt;/code&gt; function, set scales = &amp;ldquo;free_y&amp;rdquo;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;method &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;lm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;, scales &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;free&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_smooth).&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-11-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;p&gt;In next week&amp;rsquo;s session, we&amp;rsquo;ll use &lt;code&gt;facet_grid()&lt;/code&gt;, which has some similarities to &lt;code&gt;facet_wrap()&lt;/code&gt;, and then check out the &lt;em&gt;patchwork&lt;/em&gt; package, which gives you more control over how multiple plots are combined in a single figure.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>S02E07: Intro to ggplot2 (part 2)</title>
      <link>https://biodash.github.io/codeclub/s02e07_ggplot2_part2/</link>
      <pubDate>Tue, 05 Oct 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s02e07_ggplot2_part2/</guid>
      <description>&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New to Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Please open RStudio before Code Club starts to test things out &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;new-to-ggplot2&#34;&gt;New to &lt;em&gt;ggplot2&lt;/em&gt;?&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Check out the &lt;a href=&#34;https://biodash.github.io/codeclub/S02E06_ggplot2/&#34;&gt;last Code Club Session&lt;/a&gt;, which was the first of this two-part introduction to &lt;em&gt;ggplot2&lt;/em&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You may find &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this &lt;em&gt;ggplot2&lt;/em&gt; cheat sheet&lt;/a&gt; useful!&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;h4 id=&#34;session-goals&#34;&gt;Session goals&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Get more familiar with building and layering plots using geoms, using a new geom, &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_boxplot()&lt;/code&gt;&lt;/a&gt;, as our starting point.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Learn to format plots using &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/theme.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;theme()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/labs.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;labs()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;h4 id=&#34;getting-set-up&#34;&gt;Getting set up&lt;/h4&gt;
&lt;p&gt;We will continue to work with the data contained in the Palmer Penguins package. You only have to install it if you didn&amp;rsquo;t do so in a previous session:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If the package has been installed, you do need to always load it with the &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; function &amp;ndash; and we&amp;rsquo;ll also load the &lt;em&gt;tidyverse&lt;/em&gt;, which includes the &lt;em&gt;ggplot2&lt;/em&gt; package.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h4 id=&#34;penguin-bill-length&#34;&gt;Penguin bill length&lt;/h4&gt;
&lt;p&gt;We are going to mostly be plotting &lt;code&gt;bill_length_mm&lt;/code&gt;, which is the &amp;ldquo;horizontal&amp;rdquo; length of the bill: see the image below.&lt;/p&gt;
&lt;figure&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=figs/culmen_depth.png width=&#34;75%&#34; alt=&#34;depiction of bill length protruding from the penguins face, and bill depth, the height of the bill&#34;&gt;
&lt;figcaption&gt;
Artwork by Allison Horst
&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---a-geom-for-boxplots&#34;&gt;1 - A geom for boxplots&lt;/h2&gt;
&lt;h4 id=&#34;geom-recap&#34;&gt;Geom recap&lt;/h4&gt;
&lt;p&gt;&lt;em&gt;ggplot2&lt;/em&gt;&amp;rsquo;s &amp;ldquo;geoms&amp;rdquo; are basically plot types of which there are quite a few available (see the &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;cheatsheet&lt;/a&gt;). Last week, we saw two geoms: &lt;code&gt;geom_point()&lt;/code&gt; to plot individual data points, and &lt;code&gt;geom_smooth()&lt;/code&gt; to fit a line to data points.&lt;/p&gt;
&lt;p&gt;While doing so, we also saw two other properties of &lt;em&gt;ggplot2&lt;/em&gt; and its geoms:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Geoms can be layered on top of each other.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Geoms can simply plot the data &amp;ldquo;as is&amp;rdquo; (&lt;code&gt;geom_point()&lt;/code&gt;) or can perform computations under the hood, and show the results of those computations (&lt;code&gt;geom_smooth()&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let&amp;rsquo;s use a new geom to get a little more fluent with &lt;em&gt;ggplot2&lt;/em&gt; basics.&lt;/p&gt;
&lt;h4 id=&#34;boxplots&#34;&gt;Boxplots&lt;/h4&gt;
&lt;p&gt;A boxplot is a very useful type of plot that shows you the median as well as the variation of a distribution. &lt;em&gt;ggplot2&lt;/em&gt; has the geom &lt;code&gt;geom_boxplot()&lt;/code&gt; to create boxplots &amp;ndash; another example of a geom that does calculations for us prior to plotting.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s make a boxplot that shows the distribution of penguin bill length (column &lt;code&gt;bill_length_mm&lt;/code&gt; in our &lt;code&gt;penguins&lt;/code&gt; dataframe) along the y-axis &amp;ndash; recall that we use &lt;code&gt;aes()&lt;/code&gt; to refer to a column in the data frame from which the data should be taken:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-3-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Why do we get the warning shown above?&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;We got the following warning:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;We get this warning because 2 rows contain &lt;code&gt;NA&lt;/code&gt;s for the variable we are plotting, &lt;code&gt;bill_length_mm&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;We could take a look at those rows as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 2 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g sex  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie  Torge…             &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;               &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Gentoo  Biscoe             &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;               &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1 more variable: year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And we could &lt;em&gt;remove&lt;/em&gt; those rows as follows, saving the results in a new dataframe:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## By negating the `is.na` condition:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Or using the specialized `drop_na` function:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
The nitty-gritty of boxplots: what is shown exactly? (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Lower whisker = smallest observation greater than or equal to lower hinge - 1.5 * IQR&lt;/li&gt;
&lt;li&gt;Lower hinge/bottom line of box part of boxplot = 25% quantile&lt;/li&gt;
&lt;li&gt;Middle line = median = 50% quantile&lt;/li&gt;
&lt;li&gt;Upper hinge/top line of box part of boxplot = 75% quantile&lt;/li&gt;
&lt;li&gt;Upper whisker = largest observation less than or equal to upper hinge + 1.5 * IQR&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;p&gt;That worked, but the plot shows the distribution of bill lengths across all 3 species together, which is not that informative. To separate species along the x-axis, we can map the &lt;code&gt;species&lt;/code&gt; column to x:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-6-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Great! We can see, at a glance, that Adelie Penguins tend to have considerably shorter bills than the other two species. Chinstrap&amp;rsquo;s bills are just a bit longer than those of Gentoos, but the longest-billed bird is a Gentoo.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2---adding-a-plot-layer&#34;&gt;2 - Adding a plot layer&lt;/h2&gt;
&lt;p&gt;To get an even better sense of the distribution of bill lengths, and also of our sample sizes, we may want to add the raw data points to our boxplot using &lt;code&gt;geom_point()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;(You may have noticed that in the previous plot, a Gentoo Penguin outlier was shown as a point. To prevent plotting that point twice, we will add &lt;code&gt;outlier.shape = NA&lt;/code&gt; to the boxplot call, a somewhat roundabout way of saying that we don&amp;rsquo;t want to plot outliers.)&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
               outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error: geom_point requires the following missing aesthetics: x and y&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Why did this not work?&lt;/p&gt;
&lt;p&gt;We had previously species the aesthetics mapping inside the &lt;code&gt;geom_boxplot()&lt;/code&gt; call &amp;ndash; that is, we set it for that geom only (&amp;ldquo;local aesthetics&amp;rdquo;) and not for the entire plot (&amp;ldquo;global aesthetics&amp;rdquo;). To add a &lt;code&gt;geom_point()&lt;/code&gt; layer with the same aesthetics, we can do one of two things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Set the aesthetic mapping globally, i.e. inside the &lt;code&gt;ggplot()&lt;/code&gt; call, or&lt;/li&gt;
&lt;li&gt;Set a local aesthetic mapping &lt;em&gt;also&lt;/em&gt; inside &lt;code&gt;geom_point()&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Let&amp;rsquo;s do the former, so we are not repeating ourselves:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-8-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This doesn&amp;rsquo;t look too good because many of the points are plotted on top of each other. We can use a few arguments to &lt;code&gt;geom_point()&lt;/code&gt; to make some changes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Add &lt;code&gt;position = &amp;quot;jitter&amp;quot;&lt;/code&gt; to the &lt;code&gt;geom_point()&lt;/code&gt; call to introduce a small amount of randomness to our points to make us able to see them better.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Add &lt;code&gt;size = 1&lt;/code&gt; to make the point size a little smaller (1.5 is the default).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;jitter&#34;&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-9-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Note that &lt;code&gt;position = &amp;quot;jitter&amp;quot;&lt;/code&gt; and &lt;code&gt;size = 1&lt;/code&gt; are &lt;em&gt;not&lt;/em&gt; specified as mappings (i.e., not inside &lt;code&gt;mapping = aes()&lt;/code&gt;): here, we are not mapping data to the plot, but are just changing some &amp;ldquo;settings&amp;rdquo;.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;Because jittering is so common, there is also a specialized jittering geom available: &lt;code&gt;geom_jitter()&lt;/code&gt; is shorthand for &lt;code&gt;geom_point(position = &amp;quot;jitter&amp;quot;)&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;So, we could have also used the following code to create the same plot:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-i&#34;&gt;Breakout Rooms I&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Run the code below and figure out what the problem is.&lt;br&gt;
(And why do you think &lt;em&gt;ggplot2&lt;/em&gt; creates a legend with the item &amp;ldquo;blue&amp;rdquo;, instead of throwing an error?)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Modify the code to get the originally intended effect: blue points.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;blue&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;jitter&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Here is the botched plot:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;blue&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;jitter&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Should &lt;code&gt;color = &amp;quot;blue&amp;quot;&lt;/code&gt; be a mapping, that is, should it be part of the &lt;code&gt;mapping = aes()&lt;/code&gt; argument?&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The problem with the original code&lt;/strong&gt; is that &lt;code&gt;color = &amp;quot;blue&amp;quot;&lt;/code&gt; should &lt;em&gt;not&lt;/em&gt; be a mapping.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Why &lt;em&gt;ggplot2&lt;/em&gt; does not throw an error:&lt;/strong&gt; the &lt;code&gt;mapping&lt;/code&gt; argument is used to map data to an aesthetic like point color. Normally, that data is a column in the dataframe, but because the code quotes &amp;ldquo;blue&amp;rdquo; (&lt;code&gt;color = &amp;quot;blue&amp;quot;&lt;/code&gt; instead of &lt;code&gt;color = blue&lt;/code&gt;), &lt;em&gt;ggplot2&lt;/em&gt; does not assume it is a column and instead creates a variable on the fly that just contains the value &amp;ldquo;blue&amp;rdquo;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The correct code to color points blue&lt;/strong&gt;:&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;blue&#34;&lt;/span&gt;,
             position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;jitter&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;p&gt;Violin plots are somewhat similar to boxplots, but show a density distribution. Using Google, find out which &lt;em&gt;ggplot2&lt;/em&gt; geom creates a violin plot, and then make one plotting bill length by species like we have done for boxplots.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;geom_violin()&lt;/code&gt; is the geom that creates violin plots.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Other than the geom function, you can leave the code the same as in the previous examples.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_violin&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_ydensity).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3---intro-to-formatting-plots&#34;&gt;3 - Intro to formatting plots&lt;/h2&gt;
&lt;p&gt;So far, we have mostly been concerned with &lt;em&gt;what&lt;/em&gt; we are plotting, and haven&amp;rsquo;t paid much attention to how our plot looks. But I, for one, dislike that gray background to the plot, and perhaps the axis labels are a little small?&lt;/p&gt;
&lt;p&gt;&lt;em&gt;ggplot2&lt;/em&gt; offers &lt;em&gt;many&lt;/em&gt; options to modify the look of our plot. There are so many that it isn&amp;rsquo;t really possible to remember even the majority of them. Therefore, even for daily users of &lt;em&gt;ggplot2&lt;/em&gt;, creating a publication-ready figure will usually involve some Googling or checking the &lt;a href=&#34;https://ggplot2.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ggplot2 documentation&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s have a look at some of the most commonly used options to change the look of &lt;em&gt;ggplot2&lt;/em&gt; plots.&lt;/p&gt;
&lt;h4 id=&#34;a-starting-plot&#34;&gt;A starting plot&lt;/h4&gt;
&lt;p&gt;We&amp;rsquo;ll start with the following plot, similar to one we have created before:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;jitter&#34;&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;grey70&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-15-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;(Note the addition of &lt;code&gt;color = &amp;quot;grey70&amp;quot;&lt;/code&gt; to make the points less dominant in the plot.&lt;br&gt;
See &lt;a href=&#34;http://www.stat.columbia.edu/~tzheng/files/Rcolor.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this PDF for an overview of named colors in R&lt;/a&gt;.)&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4---formatting-with-theme-and-more&#34;&gt;4 - Formatting with &lt;code&gt;theme()&lt;/code&gt; and more&lt;/h2&gt;
&lt;p&gt;The quickest way to modify the overall look and feel of our plot is by using a different &amp;ldquo;complete theme&amp;rdquo;. The default theme is &lt;code&gt;theme_gray()&lt;/code&gt;, which comes with that gray background and many other settings that control what the plot looks like.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;ggplot2&lt;/em&gt; documentation has &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/ggtheme.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;a list of complete themes&lt;/a&gt; that shows you what they look like.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s switch to a different theme, &lt;code&gt;theme_classic()&lt;/code&gt;, for our penguin boxplot:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;jitter&#34;&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;grey70&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-16-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;These complete theme functions (&lt;code&gt;theme_&amp;lt;theme-name&amp;gt;&lt;/code&gt;) also take a few arguments &amp;ndash;&lt;br&gt;
&lt;code&gt;base_size&lt;/code&gt; is very useful if we want to simultaneously change the size of all text labels:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;jitter&#34;&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;grey70&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;base_size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-17-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This retains the relative sizes of different labels. For instance, note that in both plots, the &amp;ldquo;axis titles&amp;rdquo; (&lt;code&gt;species&lt;/code&gt; on x, &lt;code&gt;bill_lenth_mm&lt;/code&gt; on y) are larger than the &amp;ldquo;axis text&amp;rdquo; (the labels at the tick marks).&lt;/p&gt;
&lt;p&gt;If we wanted to change individual theme components like those, we would need to use the &lt;code&gt;theme()&lt;/code&gt; function (check &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/theme.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;its documentation page&lt;/a&gt; to see the many possible arguments).&lt;/p&gt;
&lt;p&gt;For example, to make axis titles and axis text/labels the same size:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;jitter&#34;&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;grey70&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;base_size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;axis.text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
        axis.title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-18-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;5---adding-labels-to-our-plot&#34;&gt;5 - Adding labels to our plot&lt;/h2&gt;
&lt;p&gt;Right now, the axis titles are simply the names of the columns that we used in the mapping. The y-axis title in particular (&lt;code&gt;bill_length_mm&lt;/code&gt;) could be improved. We might also want to add a title and even a subtitle to our plot.&lt;/p&gt;
&lt;p&gt;We can do all of this with the &lt;code&gt;labs()&lt;/code&gt; function as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;jitter&#34;&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;grey70&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;base_size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Bill Length by Species&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Collected at Palmer Station, Antarctica&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin species&#34;&lt;/span&gt;,     &lt;span class=&#39;c&#39;&gt;# x-axis label&lt;/span&gt;
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill length (mm)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;    &lt;span class=&#39;c&#39;&gt;# y-axis label&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-19-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-ii&#34;&gt;Breakout Rooms II&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Modify the code used to produce the last plot (just above this exercise) to try several of the themes from the &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/ggtheme.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;list of complete themes&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Do you have a preference?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/ggtheme.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;list of complete themes&lt;/a&gt; also shows that these functions have a few more arguments than the &lt;code&gt;base_size&lt;/code&gt; one we explored.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Bonus: Change the &lt;code&gt;base_line_size&lt;/code&gt;. What does it do?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Bonus (&lt;strong&gt;may not work out of the box on Windows&lt;/strong&gt;): Using a different font family can nicely shake things up &amp;ndash; this is the &lt;code&gt;base_family&lt;/code&gt; argument. Most standard font family names (e.g. see &lt;a href=&#34;https://www.w3.org/Style/Examples/007/fonts.en.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this list&lt;/a&gt;) should work. For instance, you can try &lt;code&gt;Optima&lt;/code&gt;, &lt;code&gt;Verdana&lt;/code&gt;, &lt;code&gt;Times New Roman&lt;/code&gt;, &lt;code&gt;Courier&lt;/code&gt;, or &lt;code&gt;cursive&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Example solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;With &lt;code&gt;theme_bw()&lt;/code&gt; and:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;base_line_size = 1&lt;/code&gt; (thicker axis lines)&lt;/li&gt;
&lt;li&gt;the &lt;code&gt;cursive&lt;/code&gt; font family using &lt;code&gt;base_family = cursive&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;jitter&#34;&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;grey70&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_bw&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;base_size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;,
                base_line_size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,
                base_family &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;cursive&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Bill Length by Species and Sex&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Collected at Palmer Station, Antarctica&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Species&#34;&lt;/span&gt;, 
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill length (mm)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-20-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Modify your code from Exercise 3 to color the jittered points, but not the boxplots, according to sex.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As we also saw last week, a legend should have automatically appeared when mapping color to a variable. But what if we wanted to move the legend from the right to the top of the plot?&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Scroll through the &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/theme.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;theme()&lt;/code&gt; documentation&lt;/a&gt; and try and find the argument that controls the position of the legend. Then, use this argument to move the legend to the top.&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To color points by sex without modifying the boxplots, add the mapping locally for &lt;code&gt;geom_point()&lt;/code&gt; only.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To move the legend, use the &lt;code&gt;legend.position&lt;/code&gt; argument of &lt;code&gt;theme()&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Color points by sex:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;jitter&#34;&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,
             mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;base_size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Bill Length by Species and Sex&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Collected at Palmer Station, Antarctica&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Species&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill length (mm)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-21-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Move the legend to the top:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;jitter&#34;&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,
             mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;base_size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;top&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Bill Length by Species and Sex&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Collected at Palmer Station, Antarctica&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Species&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill length (mm)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing non-finite values (stat_boxplot).&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-22-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-5-bonus&#34;&gt;Exercise 5 (bonus)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Try to modify one of the previous plots to get separate boxes for each combination of species and sex, and no jittered points (don&amp;rsquo;t hesitate to look at the hints!).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Did you see the &lt;code&gt;NA&lt;/code&gt; sex (i.e., missing data)? Recreate the plot without the missing data.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Map &lt;code&gt;sex&lt;/code&gt; to &lt;code&gt;color&lt;/code&gt; or &lt;code&gt;fill&lt;/code&gt; (and continue to map &lt;code&gt;species&lt;/code&gt; to &lt;code&gt;x&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use &lt;code&gt;drop_na(sex)&lt;/code&gt; to remove rows with an &lt;code&gt;NA&lt;/code&gt; in the &lt;code&gt;sex&lt;/code&gt; column. You can save the result in a new dataframe and then plot that dataframe, or you can pipe (&lt;code&gt;%&amp;gt;%&lt;/code&gt;) the result straight into the &lt;code&gt;ggplot()&lt;/code&gt; function.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;This example maps &lt;code&gt;sex&lt;/code&gt; to &lt;code&gt;fill&lt;/code&gt;, which will &amp;ldquo;fill&amp;rdquo; the box with colors (as we saw before, mapping to &lt;code&gt;color&lt;/code&gt; colors the lines instead):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
                       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;,
                       fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Now mapping sex to &#34;fill&#34;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;    &lt;span class=&#39;c&#39;&gt;# We now do want to see the outliers!&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;base_size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Bill Length by Species and Sex&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Collected at Palmer Station, Antarctica&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Species&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill length (mm)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-23-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;going-further&#34;&gt;Going further&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;One basic aspect of &lt;em&gt;ggplot2&lt;/em&gt; that we have not touched upon in this or the previous session are &amp;ldquo;&lt;em&gt;scales&lt;/em&gt;&amp;rdquo;. For instance, to change the colors used in mappings (like our boxplot color), we would need to use scales. For an introduction, see the &lt;a href=&#34;https://r4ds.had.co.nz/graphics-for-communication.html#scales&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;section on scales from the R for Data Science book&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We also didn&amp;rsquo;t talk about saving plots, which can be done with the &lt;code&gt;ggsave()&lt;/code&gt; function (&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/ggsave.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;documentation page&lt;/a&gt;). Just be aware that if you don&amp;rsquo;t specify dimensions with the &lt;code&gt;width&lt;/code&gt; and &lt;code&gt;height&lt;/code&gt; arguments, they will be taken from the current size of the RStudio plotting window, which is not necessarily what you want.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>Code Club S02E06: Visualizing Data</title>
      <link>https://biodash.github.io/codeclub/s02e06_ggplot2/</link>
      <pubDate>Tue, 28 Sep 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s02e06_ggplot2/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New To Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has some pointers that might be helpful if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Please open RStudio before Code Club to test things out &amp;ndash; if you run into issues, join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Learn the philosophy of &lt;strong&gt;coding&lt;/strong&gt; a graphic.&lt;/li&gt;
&lt;li&gt;Learn the basic &lt;strong&gt;template&lt;/strong&gt; of a &lt;strong&gt;ggplot&lt;/strong&gt; graphic, so you can reuse it for multiple chart types.&lt;/li&gt;
&lt;li&gt;Learn how you can quickly add visual information to a graphic using &lt;strong&gt;aesthetics&lt;/strong&gt; and &lt;strong&gt;layers&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;intro-the-ggplot-philosophy&#34;&gt;Intro: The ggplot philosophy&lt;/h2&gt;
&lt;p&gt;We have seen that in R, instead of manually manipulating data frames with a mouse as you do when editing Excel spreadsheets, we &lt;strong&gt;code&lt;/strong&gt; the operations we want to perform using &lt;code&gt;dplyr&lt;/code&gt; verbs like &lt;code&gt;select()&lt;/code&gt;, &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt;, &lt;code&gt;arrange()&lt;/code&gt;, and so on.&lt;/p&gt;
&lt;p&gt;In a similar way when performing visualization, instead of clicking on a chart type in Excel and selecting options, we &lt;strong&gt;code the chart&lt;/strong&gt; in R.&lt;/p&gt;
&lt;p&gt;And just as &lt;code&gt;dplyr&lt;/code&gt; gives us efficient ways to manipulate data frames, &lt;code&gt;ggplot2&lt;/code&gt; (which is also part of the tidyverse) gives us efficient ways to manipulate charts/plots/graphics (we use these terms interchangeably).&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;gg&lt;/strong&gt; in &lt;strong&gt;gg&lt;/strong&gt;plot2 stands for &lt;em&gt;grammar of graphics&lt;/em&gt;, a systematic approach for designing statistical plots developed by Leland Wilkinson. The idea behind this is to think about &amp;lsquo;pulling apart&amp;rsquo; various plots into their component pieces, then provide code that could put those pieces together again in different ways to make new plots.&lt;/p&gt;
&lt;p&gt;This notion of pulling apart a graphic leads to the idea of &lt;em&gt;layers&lt;/em&gt;. You can build up a plot of any complexity by &lt;em&gt;overlaying&lt;/em&gt; different views of the same data.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s a learning curve here for sure, but there are many advantages.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First, &lt;em&gt;every&lt;/em&gt; graphic shares a &lt;strong&gt;common template&lt;/strong&gt;. Once you understand this structure you can &amp;ldquo;say&amp;rdquo; a lot of different things.&lt;br&gt;
(And I mean a &lt;em&gt;lot&lt;/em&gt;. The &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ggplot cheat sheet&lt;/a&gt; lists over 40 plot-types, but because this is a language in its own right, users can create their own &lt;a href=&#34;https://exts.ggplot2.tidyverse.org/gallery/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;extensions&lt;/a&gt; that you can also utilize, adding over 80 more.)&lt;/li&gt;
&lt;li&gt;Second, because the graphic is now a piece of code, it is &lt;em&gt;reusable&lt;/em&gt;. Once you have a little library of graphs you&amp;rsquo;ve made, you can tweak them in various ways to make more. You can also share your code with others, so they can apply the same approach to their data.&lt;/li&gt;
&lt;li&gt;Third, the way we put layers together is identical to the way we use pipes. You can read &lt;code&gt;%&amp;gt;%&lt;/code&gt; as &lt;em&gt;and then&lt;/em&gt;: &amp;ldquo;&lt;code&gt;select()&lt;/code&gt; &lt;em&gt;and then&lt;/em&gt; &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; &lt;em&gt;and then&lt;/em&gt; &lt;code&gt;mutate()&lt;/code&gt;&amp;rdquo;. In graphics, the &amp;ldquo;and then&amp;rdquo; symbol is &lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;+&lt;/code&gt;&lt;/a&gt;: &amp;ldquo;show this layer, &lt;em&gt;and then&lt;/em&gt; add this layer, &lt;em&gt;and then&lt;/em&gt; add this layer&amp;rdquo;. In this way you can gradually build up a graphic of increasing complexity; or on the other hand take someone else&amp;rsquo;s code and simplify it by deleting layers.&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;a-first-example&#34;&gt;A First Example&lt;/h2&gt;
&lt;p&gt;So how does this work in practice? We&amp;rsquo;ll work through visualizing aspects of the &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;palmerpenguins&lt;/a&gt; package which was introduced in &lt;a href=&#34;https://biodash.github.io/codeclub/s02e04_tidyverse-intro-part1/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;S02E04 Intro to the Tidyverse&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In addition, &lt;strong&gt;ggplot2&lt;/strong&gt; is part of the tidyverse package so we need to load that as well:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# this assumes you&#39;ve already installed tidyverse and palmerpenguins with install.packages()&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And recall that the &lt;strong&gt;penguins&lt;/strong&gt; dataset is included in that package:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 344&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ island            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Torgersen, Torgersen, Torgersen, Torgersen, Torgerse…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_length_mm    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_depth_mm     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ flipper_length_mm &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ body_mass_g       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sex               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; male, female, female, NA, female, male, female, male…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What is the correlation between bill-length and bill-width in these species?&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;culmen_depth.png&#34; style=&#34;width:50.0%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Are longer bills also deeper? We can explore this with a &lt;strong&gt;scatterplot&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;But first let&amp;rsquo;s look at the &lt;code&gt;ggplot()&lt;/code&gt; &lt;strong&gt;template&lt;/strong&gt;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Note:&lt;/em&gt; the &lt;em&gt;package&lt;/em&gt; is &lt;strong&gt;ggplot2&lt;/strong&gt;, the &lt;em&gt;command&lt;/em&gt; is just &lt;code&gt;ggplot()&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;pre&gt;&lt;code&gt;ggplot(data = &amp;lt;DATA&amp;gt;) + 
  &amp;lt;GEOM_FUNCTION&amp;gt;(mapping = aes(&amp;lt;MAPPINGS&amp;gt;))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These are the obligatory parts of any plot: &lt;strong&gt;data&lt;/strong&gt;, &lt;strong&gt;geoms&lt;/strong&gt;, and &lt;strong&gt;mappings&lt;/strong&gt;. The first argument to &lt;code&gt;ggplot()&lt;/code&gt; is the data frame:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-3-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This is not very interesting! but it&amp;rsquo;s notable that it is &lt;em&gt;something&lt;/em&gt;. &lt;code&gt;ggplot()&lt;/code&gt; has created a base coordinate system (a base layer) that we can add visual layers to. It&amp;rsquo;s completely uninfomative because we haven&amp;rsquo;t said how we want the data (or even which data) to be mapped to graphic elements.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;add a layer&lt;/em&gt; operator is &amp;ldquo;&lt;strong&gt;+&lt;/strong&gt;&amp;rdquo;, which is the &lt;code&gt;ggplot&lt;/code&gt; equivalent of the pipe symbol, and best practice is to &lt;strong&gt;place it at the end of the line&lt;/strong&gt;, just like the pipe. This makes your layers more readable in the code (and can lead to problems if you put it some other places).&lt;/p&gt;
&lt;p&gt;The next argument specifies the kind plot we want: scatterplot, bar chart, fitted line, boxplot, violin plot, etc, etc. &lt;strong&gt;ggplot2&lt;/strong&gt; refers to these as &lt;strong&gt;geoms&lt;/strong&gt;: each different plot-type uses a different &lt;strong&gt;geom&lt;/strong&gt;etrical object to represent data.&lt;/p&gt;
&lt;p&gt;You can see an overview of many of these geoms in the &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;cheat sheet&lt;/a&gt;.The geom for a scatterplot is &lt;code&gt;geom_point()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But we also require a &lt;code&gt;mapping&lt;/code&gt; argument, which maps the &lt;em&gt;variables&lt;/em&gt; or columns in the dataset we want to focus on to their &lt;em&gt;visual representation&lt;/em&gt; in the plot.&lt;/p&gt;
&lt;p&gt;And finally we need to specify &lt;strong&gt;aesthetics&lt;/strong&gt; for the geometric objects in the plot, which will control things like shape, color, transparency, etc. Perhaps surprisingly, the &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; coordinates of the points are aesthetics, since these control, not the shape or color, but the relative &lt;strong&gt;position&lt;/strong&gt; of the points in the plot. (After all, flipping the &lt;code&gt;x&lt;/code&gt; for &lt;code&gt;y&lt;/code&gt; in some plots will flip the plot 90 degrees.)&lt;/p&gt;
&lt;p&gt;Sounds like a lot when you spell it all out, but it&amp;rsquo;s actually pretty simple in practice. Here then is our complete first plot:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-4-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Hmmm&amp;hellip; the relationship is not very clear, but I guess if you squint your eyes you can maybe see some local positive correlations? We&amp;rsquo;ll explore this relationship in more detail below using extra aesthetics.&lt;/p&gt;
&lt;p&gt;But let&amp;rsquo;s get coding!&lt;/p&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Create a scatterplot comparing body mass and flipper length. Does it look like there is any correlation?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt; Check the output of the glimpse() function to see what the precise variable names for body mass and flipper length are. It&#39;s up to you which you assign to x and y. &lt;br&gt; &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-5-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;the-power-of-aesthetics&#34;&gt;The power of aesthetics&lt;/h2&gt;
&lt;p&gt;We saw above that the relationship between bill length and bill depth is not particularly clear; but that there &lt;em&gt;might&lt;/em&gt; be some local patterns. How can we explore this? Is it possible that these clusters correspond somehow to the three different species: &lt;em&gt;Adelie&lt;/em&gt;, &lt;em&gt;Chinstrap&lt;/em&gt;, and &lt;em&gt;Gentoo&lt;/em&gt;? Part of the problem with our original plot may be that we are lumping all the data from all three species together. We can quickly explore this by adding an extra aesthetic.&lt;/p&gt;
&lt;p&gt;Our current plot uses two &lt;strong&gt;numeric&lt;/strong&gt; variables: &lt;code&gt;bill_length_mm&lt;/code&gt; and &lt;code&gt;bill_depth_mm&lt;/code&gt;. We can add a third &lt;strong&gt;categorical&lt;/strong&gt; variable, like &lt;code&gt;species&lt;/code&gt;, to a two dimensional scatterplot by mapping it to a different visual aesthetic. We&amp;rsquo;ve mapped length and depth to &lt;code&gt;x,y&lt;/code&gt; coordinates. Now we&amp;rsquo;ll simultaneously map species to &lt;code&gt;color&lt;/code&gt; by expanding our list of aesthetics.&lt;/p&gt;
&lt;p&gt;But before we do that, let&amp;rsquo;s improve our plotting commands a little.&lt;/p&gt;
&lt;p&gt;First, our template includes a general &lt;code&gt;mapping =&lt;/code&gt; directive, which in turn includes a bunch of &lt;em&gt;specific&lt;/em&gt; mappings from variables to aesthetics. While I think it&amp;rsquo;s quite useful to be explicit that this is a mapping component (which connects columns with graphical objects) it turns out we can drop the &lt;code&gt;mapping =&lt;/code&gt; syntax completely (and many people do). The very fact we have specific mappings inside &lt;code&gt;aes()&lt;/code&gt; makes the &lt;code&gt;mapping =&lt;/code&gt; redundant. (I&amp;rsquo;ve come to think of it as &amp;lsquo;syntactic sugar&amp;rsquo;).&lt;/p&gt;
&lt;p&gt;Second, we can actually pipe the dataset into the &lt;code&gt;ggplot()&lt;/code&gt; command! We then set the mappings, and then choose our geom in a new layer. This is very common. Our new syntax looks like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-6-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now let&amp;rsquo;s add an extra aesthetic for the &lt;code&gt;species&lt;/code&gt; variable. For this example we&amp;rsquo;ll use the &lt;code&gt;color&lt;/code&gt; aesthetic:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-7-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;We get a neat legend on the right hand side for free. It&amp;rsquo;s much clearer now that, within each species, there does seem to be a positive correlation between length and depth. It&amp;rsquo;s just that the absolute values for each species fall in different regions of &amp;ldquo;bill space&amp;rdquo;.&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Notice:&lt;/em&gt; We are piping &lt;em&gt;the entire raw dataset&lt;/em&gt; into the plot here, while only graphing part of it. The elegance of the pipe syntax is that we can first pass the dataset through a series of &lt;code&gt;dplyr&lt;/code&gt; operations - filtering and mutating etc. - and then pipe that modified dataset directly into our plotting commands. We&amp;rsquo;ll see more of that in coming Code Clubs (and Exercise 3)!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Go back to your body_mass/flipper data and color by species, also using our new syntax.&lt;/p&gt;
&lt;p&gt;There are various aesthetics you can use for a categorical variable (see help for geom_point). One is &lt;code&gt;shape&lt;/code&gt;. Try this instead of &lt;code&gt;color&lt;/code&gt; and see which you prefer.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-8-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-9-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;the-fitted-line-geom-geom_smooth&#34;&gt;The fitted-line geom: &lt;code&gt;geom_smooth()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;In the scatterplot for bill length vs. bill depth, there wasn&amp;rsquo;t a very clean overall positive relationship. We can make this even more apparent visually by fitting a line to the data: &lt;em&gt;overlaying&lt;/em&gt; another geom in the same plot.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using method = &#39;loess&#39; and formula &#39;y ~ x&#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-10-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;Technical note:&lt;/em&gt; by default, the &lt;code&gt;geom_smooth()&lt;/code&gt; function doesn&amp;rsquo;t use classical linear regression to fit the data. Instead it uses &lt;strong&gt;lo&lt;/strong&gt;cally &lt;strong&gt;e&lt;/strong&gt;stimated &lt;strong&gt;s&lt;/strong&gt;catterplot &lt;strong&gt;s&lt;/strong&gt;moothing: &lt;a href=&#34;https://en.m.wikipedia.org/wiki/Local_regression&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;loess&lt;/a&gt;. This snakes around and tries to find a more local best fit to the data. You can request different fit algorithms with the &lt;code&gt;method&lt;/code&gt; option. See help for &lt;code&gt;geom_smooth&lt;/code&gt; for details.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;But again, this is messy since we are trying to analyze all the data at once. What if we set the species aesthetic before we apply &lt;em&gt;any&lt;/em&gt; geom, so that the aesthetic is inherited by &lt;em&gt;both&lt;/em&gt; geoms?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using method = &#39;loess&#39; and formula &#39;y ~ x&#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-11-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Here we can see there does seem to be a strong positive correlation if we analyze the data species-by-species.&lt;/p&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Revisit your flipper/body_mass data, and fit lines to each species.&lt;/p&gt;
&lt;p&gt;There is a lot of overlap between two of the species in the scatterplot, which makes it hard to see the overall patterns for those two species. Does the fitted line overlay help make sense of this?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using method = &#39;loess&#39; and formula &#39;y ~ x&#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;Perhaps you think this plot is too noisy, with the scatterplot data messing up the basic linear relationships. Modify your plot so it just shows the linear layer without the scatterplot layer.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt; Remember you can delete layers just as easily as you can add layers. &lt;br&gt; &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using method = &#39;loess&#39; and formula &#39;y ~ x&#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;p&gt;(Bonus: if you have time&amp;hellip;)&lt;/p&gt;
&lt;p&gt;Pipe your dataset into a dplyr &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; command which pulls out just the &lt;code&gt;Gentoo&lt;/code&gt; data; then pipe that data into the &lt;code&gt;ggplot()&lt;/code&gt; command, to create a scatterplot, together with a smoothed-line overlay, for just that one species.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt; Remember two important things about the filter() function: (i) the check for equality is a double equals sign == (ii) the species name is a character string, not a number, so has to be quoted with &#34;...&#34;. &lt;br&gt; &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Gentoo&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using method = &#39;loess&#39; and formula &#39;y ~ x&#39;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Code Club S02E05: Intro to the Tidyverse (Part 2)</title>
      <link>https://biodash.github.io/codeclub/s02e05_tidyverse-intro-part2/</link>
      <pubDate>Wed, 22 Sep 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s02e05_tidyverse-intro-part2/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;prep-homework&#34;&gt;Prep homework&lt;/h2&gt;
&lt;h3 id=&#34;basic-computer-setup&#34;&gt;Basic computer setup&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;What will we go over today&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;We will continue using the &lt;em&gt;dplyr&lt;/em&gt; package, which is part of the &lt;em&gt;tidyverse&lt;/em&gt; and was introduced last week.&lt;/li&gt;
&lt;li&gt;Learn using &lt;a href=&#34;https://dplyr.tidyverse.org/reference/arrange.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;arrange()&lt;/code&gt;&lt;/a&gt; - orders the rows of a data frame by the values of selected columns.&lt;/li&gt;
&lt;li&gt;Learn using &lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; - adds new variables and preserves existing ones.&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---what-is-the-dplyr-package&#34;&gt;1 - What is the dplyr package?&lt;/h2&gt;
&lt;p&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/index.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;dplyr&lt;/em&gt;&lt;/a&gt; is one of the &lt;em&gt;tidyverse&lt;/em&gt; packages that are designed for data science. &lt;em&gt;dplyr&lt;/em&gt; provides functions for data manipulation.&lt;/p&gt;
&lt;p&gt;Functions for row-wise operations include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; - chooses rows based on column values.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/slice.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;slice()&lt;/code&gt;&lt;/a&gt; - chooses rows based on location.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/arrange.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;arrange()&lt;/code&gt;&lt;/a&gt; - orders the rows of a data frame by the values of selected columns.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Functions for column-wise operations include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; - changes whether or not a column is included.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/rename.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;rename&lt;/code&gt;()&lt;/a&gt; - changes the name of columns.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; - changes the values of columns and creates new columns&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/relocate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;relocate&lt;/code&gt;()&lt;/a&gt; - changes the order of the columns.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Functions for &lt;em&gt;groups&lt;/em&gt; of rows include:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarise()&lt;/code&gt;&lt;/a&gt; - collapses a group into a single row.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Last week, we got introduced to the &lt;em&gt;tidyverse&lt;/em&gt; and covered the &lt;code&gt;%&amp;gt;%&lt;/code&gt; pipe, &lt;code&gt;select()&lt;/code&gt;, and &lt;code&gt;filter&lt;/code&gt;. We saw that packages are basically R add-ons that contain additional functions or datasets we can use. Using the function &lt;a href=&#34;https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/install.packages&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;install.packages()&lt;/code&gt;&lt;/a&gt;, we can install packages that are available at the Comprehensive R Archive Network, or &lt;a href=&#34;https://cran.r-project.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CRAN&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For those who have not installed the &lt;em&gt;tidyverse&lt;/em&gt;, let&amp;rsquo;s install it. We only need to do this once, so if you did this last week, you don&amp;rsquo;t need to now.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To use the &lt;em&gt;dplyr&lt;/em&gt; package within the &lt;em&gt;tidyverse&lt;/em&gt;, we need to call it up using &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching packages&lt;/span&gt; ─────────────────────────────────────── tidyverse 1.3.1 ──&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2&lt;/span&gt; 3.3.5     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;purrr  &lt;/span&gt; 0.3.4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tibble &lt;/span&gt; 3.1.4     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr  &lt;/span&gt; 1.0.7&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr  &lt;/span&gt; 1.1.3     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;stringr&lt;/span&gt; 1.4.0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;readr  &lt;/span&gt; 2.0.1     &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;forcats&lt;/span&gt; 0.5.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt; masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::filter()&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt; &lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;::&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;    masks &lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;::lag()&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2---using-the-arrange-function&#34;&gt;2 - Using the &lt;code&gt;arrange()&lt;/code&gt; function&lt;/h2&gt;
&lt;p&gt;We will learn how to use the &lt;code&gt;arrange()&lt;/code&gt; function from &lt;em&gt;dplyr&lt;/em&gt; to sort a data frame in multiple ways. First, we will sort a dataframe by values of a single variable, and then we will learn how to sort a dataframe by more than one variable in the dataframe. By default, &lt;em&gt;dplyr&lt;/em&gt;&amp;rsquo;s &lt;code&gt;arrange()&lt;/code&gt; sorts in &lt;em&gt;ascending&lt;/em&gt; order (lowest values first).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Let&amp;rsquo;s get set up and grab some data so that we have some material to work with.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;We will use the same dataset &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;palmerpenguins&lt;/code&gt;&lt;/a&gt; we used last week. To get this data, we need to install the &lt;em&gt;palmerpenguins&lt;/em&gt; package (again, no need to do this if you already did so last week):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then, to use the package, we need to use the function &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; to load the package in R:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The dataframe we will use today is called &lt;code&gt;penguins&lt;/code&gt;. Let&amp;rsquo;s take a look at the structure of the data:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# look at the first 10 rows and all columns&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 10 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species island    bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Adelie  Torgersen           39.1          18.7               181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;750&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Adelie  Torgersen           39.5          17.4               186        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;800&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Adelie  Torgersen           40.3          18                 195        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;250&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Adelie  Torgersen           &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;            &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;                  &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Adelie  Torgersen           36.7          19.3               193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;450&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Adelie  Torgersen           39.3          20.6               190        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;650&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Adelie  Torgersen           38.9          17.8               181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;625&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Adelie  Torgersen           39.2          19.6               195        &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;675&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Adelie  Torgersen           34.1          18.1               193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;475&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Adelie  Torgersen           42            20.2               190        &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;250&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 2 more variables: sex &amp;lt;fct&amp;gt;, year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# check the structure of penguins_data&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# glimpse() which is a part of dplyr functions &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# similarly to str() and can be used interchangeably&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 344&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ island            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; Torgersen, Torgersen, Torgersen, Torgersen, Torgerse…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_length_mm    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_depth_mm     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ flipper_length_mm &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ body_mass_g       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sex               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt; male, female, female, NA, female, male, female, male…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Okay, now we have a sense of what the &lt;code&gt;penguins&lt;/code&gt; dataset is.&lt;/p&gt;
&lt;p&gt;Now we want to sort the &lt;code&gt;penguins&lt;/code&gt; dataframe by body mass to quickly learn about the lightest penguin and its relations to other variables. We will use the pipe operator &lt;code&gt;%&amp;gt;%&lt;/code&gt; to feed the data to the &lt;code&gt;arrange()&lt;/code&gt; function. We then specify name of the variable that we want to sort the dataframe by.&lt;/p&gt;
&lt;p&gt;In this example, we are sorting by variable &lt;code&gt;body_mass_g&lt;/code&gt;, so we will see the lightest penguins at the top of the dataframe:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;           &lt;span class=&#39;c&#39;&gt;# take the penguins_data&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# sort the dataframe in ascending order based on body mass&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 344 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species   island    bill_length_mm bill_depth_mm flipper_length_… body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Chinstrap Dream               46.9          16.6              192        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;700&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Adelie    Biscoe              36.5          16.6              181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;850&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Adelie    Biscoe              36.4          17.1              184        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;850&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Adelie    Biscoe              34.5          18.1              187        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;900&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Adelie    Dream               33.1          16.1              178        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;900&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Adelie    Torgersen           38.6          17                188        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;900&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Chinstrap Dream               43.2          16.6              187        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;900&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Adelie    Biscoe              37.9          18.6              193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;925&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Adelie    Dream               37.5          18.9              179        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;975&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Adelie    Dream               37            16.9              185        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 334 more rows, and 2 more variables: sex &amp;lt;fct&amp;gt;, year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If we wanted to sort &lt;em&gt;descendingly&lt;/em&gt;, such that the heaviest penguins are in the first rows, we can add a &lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;-&lt;/code&gt;&lt;/a&gt; in front of the variable:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;             &lt;span class=&#39;c&#39;&gt;# take the penguins_data&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;# sort the dataframe in descending order based on body mass&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 344 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Gentoo  Biscoe           49.2          15.2               221        &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;300&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Gentoo  Biscoe           59.6          17                 230        &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;050&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Gentoo  Biscoe           51.1          16.3               220        &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Gentoo  Biscoe           48.8          16.2               222        &lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Gentoo  Biscoe           45.2          16.4               223        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;950&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Gentoo  Biscoe           49.8          15.9               229        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;950&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Gentoo  Biscoe           48.4          14.6               213        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;850&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Gentoo  Biscoe           49.3          15.7               217        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;850&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Gentoo  Biscoe           55.1          16                 230        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;850&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Gentoo  Biscoe           49.5          16.2               229        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;800&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 334 more rows, and 2 more variables: sex &amp;lt;fct&amp;gt;, year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can also pipe the results into the &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; function covered last week, to select only penguins weighing more than 5000 g:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_new&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt;     &lt;span class=&#39;c&#39;&gt;# assign the results to a dataframe `penguins_new`&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;                               &lt;span class=&#39;c&#39;&gt;# take the penguins data&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# sort by bill length followed by bill depth&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;                 &lt;span class=&#39;c&#39;&gt;# select species greater with mass &amp;gt; 5000 g.&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_new&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;     &lt;span class=&#39;c&#39;&gt;# look at the top 5 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 5 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g sex  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Gentoo  Biscoe           44.4          17.3              219        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;250 male &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Gentoo  Biscoe           44.9          13.3              213        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;100 fema…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Gentoo  Biscoe           45            15.4              220        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;050 male &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Gentoo  Biscoe           45.1          14.5              207        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;050 fema…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Gentoo  Biscoe           45.2          14.8              212        &lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;200 fema…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1 more variable: year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s check the counts of different species and islands among our new dataset:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_new&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species     n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Gentoo     61&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_new&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   island     n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Biscoe    61&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can see that we have only retained Gentoo Penguins from the island of Biscoe.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-session-1---arrange&#34;&gt;Breakout session 1 - &lt;code&gt;arrange()&lt;/code&gt;&lt;/h2&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;With the &lt;code&gt;penguins&lt;/code&gt; dataset, answer the following questions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Create a new dataset called &lt;code&gt;penguins_shortflippers&lt;/code&gt; from the &lt;code&gt;penguins&lt;/code&gt; dataset with the 20 penguins with the shortest flippers.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;How many penguins of each species are found in &lt;code&gt;penguins_shortflippers&lt;/code&gt;?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Which islands do they come from?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Hints
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To create &lt;code&gt;penguins_shortflippers&lt;/code&gt;, first use &lt;code&gt;arrange()&lt;/code&gt; to sort by flipper lengths, and pipe the results into the &lt;a href=&#34;https://rdrr.io/r/utils/head.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;head()&lt;/code&gt;&lt;/a&gt; function to get the top 20.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To get the species and island composition, use the &lt;code&gt;count()&lt;/code&gt; function.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;To create a dataframe with the 20 penguins with the shortest flippers:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_shortflippers&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt;        &lt;span class=&#39;c&#39;&gt;# assign the results&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;                   &lt;span class=&#39;c&#39;&gt;# take penguins_data&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# sort the data by bill flipper length &lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;                       &lt;span class=&#39;c&#39;&gt;# take the top 20&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;To see the species composition in &lt;code&gt;penguins_shortflippers&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_shortflippers&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 2 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species       n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie       17&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Chinstrap     3&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;To see the island composition in &lt;code&gt;penguins_shortflippers&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_shortflippers&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   island        n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Biscoe        7&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Dream         9&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Torgersen     4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3---using-mutate&#34;&gt;3 - Using &lt;code&gt;mutate()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Besides selecting sets of existing columns, it&amp;rsquo;s often useful to add new columns that are derived from existing columns. The &lt;code&gt;mutate()&lt;/code&gt; function create new variables, usually by manipulating existing variables.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;mutate()&lt;/code&gt; always adds new columns at the end of the dataframe. When you use &lt;code&gt;mutate()&lt;/code&gt;, you need typically to specify 3 things:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;the name of the dataframe you want to modify&lt;/li&gt;
&lt;li&gt;the name of the new column that you&amp;rsquo;ll create&lt;/li&gt;
&lt;li&gt;the values to be inserted in the new column&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We will be working with the penguins dataset to learn the &lt;code&gt;mutate()&lt;/code&gt; function. We will create a new dataframe called &lt;code&gt;mutate_penguins&lt;/code&gt;, with a new column called &lt;code&gt;body_mass_g_new&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The first argument (dataset to be piped) is the dataframe we&amp;rsquo;re going to modify, &lt;code&gt;penguins&lt;/code&gt;. After that, we have the name-value pair for our new variable.&lt;/p&gt;
&lt;p&gt;Here, the name of the new variable is &lt;code&gt;size&lt;/code&gt; and the values are &lt;code&gt;body_mass_g&lt;/code&gt; multiplied by &lt;code&gt;flipper_length_mm&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;mutate_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;# assign the results to a dataframe `mutate_penguins`&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;      &lt;span class=&#39;c&#39;&gt;# take the penguins_data&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# create a new column&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mutate_penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;9&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;       &lt;span class=&#39;c&#39;&gt;# show the first rows of columns 6-9&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   body_mass_g sex     year   size&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;750 male    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007 &lt;span style=&#39;text-decoration: underline;&#39;&gt;678&lt;/span&gt;750&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;800 female  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007 &lt;span style=&#39;text-decoration: underline;&#39;&gt;706&lt;/span&gt;800&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;250 female  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007 &lt;span style=&#39;text-decoration: underline;&#39;&gt;633&lt;/span&gt;750&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;          &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;      &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007     &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;450 female  &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007 &lt;span style=&#39;text-decoration: underline;&#39;&gt;665&lt;/span&gt;850&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;650 male    &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;007 &lt;span style=&#39;text-decoration: underline;&#39;&gt;693&lt;/span&gt;500&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can see that we created data with a new column called &lt;code&gt;size&lt;/code&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-session-2---mutate&#34;&gt;Breakout session 2 - &lt;code&gt;mutate()&lt;/code&gt;&lt;/h2&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Create a new dataframe called &lt;code&gt;penguins_bills&lt;/code&gt; with a new column called &lt;code&gt;bill_shape&lt;/code&gt; by dividing bill length by bill depth.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What is the species composition of the 20 penguins with the &lt;em&gt;largest&lt;/em&gt; values for &lt;code&gt;bill_shape&lt;/code&gt;?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;To get the species composition of the top 20, first use &lt;code&gt;arrange()&lt;/code&gt; (think about the direction you need to sort in!), then &lt;a href=&#34;https://rdrr.io/r/utils/head.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;head()&lt;/code&gt;&lt;/a&gt;, and then &lt;code&gt;count()&lt;/code&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;New dataframe with a bill shape variable:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_bills&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;      &lt;span class=&#39;c&#39;&gt;# take the penguins_data&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;bill_shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# Create a new column `bill_shape`   &lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Species composition of the 20 penguins with the largest &lt;code&gt;bill_shape&lt;/code&gt; values:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_bills&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_shape&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;# sort by bill_shape in descending order&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;              &lt;span class=&#39;c&#39;&gt;# take the top 20&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;            &lt;span class=&#39;c&#39;&gt;# create a frequency table&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species     n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Gentoo     20&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;They are all Gentoo penguins!&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;p&gt;Create a new dataframe called &lt;code&gt;penguins_year&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;with only penguins sampled after 2007,&lt;/li&gt;
&lt;li&gt;with a new column called &lt;code&gt;year_nr&lt;/code&gt; which has a year number that starts counting from 2008 (i.e., 2008 = year 1, 2009 = year 2, etc.)&lt;/li&gt;
&lt;li&gt;sorted by &lt;code&gt;year_nr&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Not all values you pass to &lt;code&gt;mutate()&lt;/code&gt; need to be variables! You can subtract &lt;code&gt;year&lt;/code&gt; by a fixed number.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_year&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2007&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;year_nr &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2007&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year_nr&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;penguins_year&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 234 × 9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt; Adelie  Biscoe           39.6          17.7               186        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;500&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt; Adelie  Biscoe           40.1          18.9               188        &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;300&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt; Adelie  Biscoe           35            17.9               190        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;450&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt; Adelie  Biscoe           42            19.5               200        &lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;050&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt; Adelie  Biscoe           34.5          18.1               187        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;900&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt; Adelie  Biscoe           41.4          18.6               191        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;700&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt; Adelie  Biscoe           39            17.5               186        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;550&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt; Adelie  Biscoe           40.6          18.8               193        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;800&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt; Adelie  Biscoe           36.5          16.6               181        &lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;850&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt; Adelie  Biscoe           37.6          19.1               194        &lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;750&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 224 more rows, and 3 more variables: sex &amp;lt;fct&amp;gt;, year &amp;lt;int&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   year_nr &amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Code Club S02E04: Intro to the Tidyverse (Part 1)</title>
      <link>https://biodash.github.io/codeclub/s02e04_tidyverse-intro-part1/</link>
      <pubDate>Wed, 15 Sep 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s02e04_tidyverse-intro-part1/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;prep-homework&#34;&gt;Prep homework&lt;/h2&gt;
&lt;h3 id=&#34;basic-computer-setup&#34;&gt;Basic computer setup&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;getting-started&#34;&gt;Getting started&lt;/h2&gt;
&lt;p&gt;Now that you are familiar with the basics of RMarkdown &lt;a href=&#34;https://biodash.github.io/codeclub/07_rmarkdown&#34;&gt;season 1&lt;/a&gt; and &lt;a href=&#34;https://biodash.github.io/codeclub/s02e03_rmarkdown/&#34;&gt;season 2&lt;/a&gt;, I put together a RMarkdown file you can download which has the content for today&amp;rsquo;s Code Club.&lt;/p&gt;
&lt;h3 id=&#34;download-todays-content&#34;&gt;Download today&amp;rsquo;s content&lt;/h3&gt;
&lt;details&gt;
&lt;summary&gt;
Click here to get an Rmd (optional)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# directory for Code Club Session 2:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S02E04&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# directory for our script&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# (&#34;recursive&#34; to create two levels at once.)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S02E04/Rmds/&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# save the url location for today&#39;s script&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;todays_Rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/S02E04_tidyverse-intro-part1/intro-to-tidyverse1.Rmd&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# indicate the name of the new Rmd file&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;intro_tidyverse1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;S02E04/Rmds/intro-to-tidyverse1.Rmd&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# go get that file! &lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;todays_Rmd&lt;/span&gt;,
              destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;intro_tidyverse1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;&lt;strong&gt;What will we go over today&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;What is the tidyverse and why would I want to use it?&lt;/li&gt;
&lt;li&gt;Understanding how to use &lt;a href=&#34;https://style.tidyverse.org/pipes.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&amp;ldquo;the pipe&amp;rdquo;&lt;/a&gt; &lt;code&gt;%&amp;gt;%&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Using &lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; - picks observations (i.e., rows) based on their values&lt;/li&gt;
&lt;li&gt;Using &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; - picks variables (i.e., columns) based on their names&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---what-is-the-tidyverse-and-how-do-i-use-it&#34;&gt;1 - What is the tidyverse, and how do I use it?&lt;/h2&gt;
&lt;p&gt;The &lt;a href=&#34;https://www.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;tidyverse&lt;/a&gt; is a collection of R packages that are designed for data science. You can certainly use R without using the tidyverse, but it has many packages that I think will make your life a lot easier. The popular package &lt;a href=&#34;https://ggplot2.tidyverse.org/index.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplot2&lt;/code&gt;&lt;/a&gt; is a part of the core tidyverse, which we have talked about in previous Code Clubs (&lt;a href=&#34;https://biodash.github.io/codeclub/04_ggplot2&#34;&gt;intro&lt;/a&gt;, &lt;a href=&#34;https://biodash.github.io/codeclub/05_ggplot-round-2&#34;&gt;intro2&lt;/a&gt;, &lt;a href=&#34;https://biodash.github.io/codeclub/11_ggplot-maps&#34;&gt;maps&lt;/a&gt;, and &lt;a href=&#34;https://biodash.github.io/codeclub/15_plotly&#34;&gt;ggplotly&lt;/a&gt;), and will talk about in future sessions as well.&lt;/p&gt;
&lt;p&gt;Packages contain shareable code, documentation, tests, and data. One way to download packages is using the function &lt;a href=&#34;https://www.rdocumentation.org/packages/utils/versions/3.6.2/topics/install.packages&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;install.packages()&lt;/code&gt;&lt;/a&gt; which will allow you to download packages that exist within the Comprehensive R Archive Network, or &lt;a href=&#34;https://cran.r-project.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CRAN&lt;/a&gt;. There are packages that exist outside CRAN but that is a story for another time.&lt;/p&gt;
&lt;p&gt;Before we talk more about the tidyverse, let&amp;rsquo;s download it. We only need to do this once.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To use any of the packages within the tidyverse, we need to call them up using &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; anytime we want to use the code embedded within them.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching packages&lt;/span&gt;&lt;span&gt; ─────────────────────────────────────── tidyverse 1.3.1 ──&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2&lt;/span&gt;&lt;span&gt; 3.3.3     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;purrr  &lt;/span&gt;&lt;span&gt; 0.3.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;tibble &lt;/span&gt;&lt;span&gt; 3.1.4     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr  &lt;/span&gt;&lt;span&gt; 1.0.7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr  &lt;/span&gt;&lt;span&gt; 1.1.3     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stringr&lt;/span&gt;&lt;span&gt; 1.4.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;readr  &lt;/span&gt;&lt;span&gt; 1.4.0     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;forcats&lt;/span&gt;&lt;span&gt; 0.5.1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt;&lt;span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt;&lt;span&gt; masks &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;&lt;span&gt;::filter()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;&lt;span&gt;    masks &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;&lt;span&gt;::lag()&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s look at this message, we can see that there are eight &amp;ldquo;attaching packages&amp;rdquo; as part of the &lt;a href=&#34;https://www.tidyverse.org/packages/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&amp;ldquo;core&amp;rdquo;&lt;/a&gt; set of tidyverse.&lt;/p&gt;
&lt;p&gt;We see that there are some conflicts, for example, there is a function called &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; (which we will talk about today) that is part of &lt;code&gt;dplyr&lt;/code&gt; (a tidyverse package) that is masking another function called &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; within the &lt;code&gt;stats&lt;/code&gt; package (which loads with base R).&lt;/p&gt;
&lt;p&gt;The conflict arises from the fact that there are now two functions named &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt;. After loading the tidyverse, the default &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; will be that from &lt;code&gt;dplyr&lt;/code&gt;. If we want explcitly to use the &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; function from &lt;code&gt;stats&lt;/code&gt;, we can do that using the double colon operator &lt;a href=&#34;https://rdrr.io/r/base/ns-dblcolon.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;::&lt;/code&gt;&lt;/a&gt; like this: &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;stats::filter()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Now this is fine for us right now, so there is nothing to do, but it is a good habit to get into reading (and not ignoring) any warnings or messages that R gives you. (It is trying to help!)&lt;/p&gt;
&lt;p&gt;Remember, you can learn more about any package by accessing the help documentation. The help will pop up in the Help tab of the bottom right quadrant of RStudio when you execute the code below.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;?&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tidyverse&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=tidyverse-packages.png width=&#34;90%&#34; alt=&#34;an illustration of eight hexagons with the names of the tidyverse core packages inside, dplyr, readr, purrr, tidyverse, ggplot2, tidyr, and tibble&#34;&gt;
&lt;/p&gt;
&lt;p&gt;By &lt;a href=&#34;https://education.rstudio.com/blog/2020/07/teaching-the-tidyverse-in-2020-part-1-getting-started/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Mine Çetinkaya-Rundel&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Below is a quick description of what each package is used for.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dplyr&lt;/code&gt;&lt;/a&gt;: for data manipulation&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://ggplot2.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplot2&lt;/code&gt;&lt;/a&gt;: a &amp;ldquo;grammar of graphics&amp;rdquo; for creating beautiful plots&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://readr.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;readr&lt;/code&gt;&lt;/a&gt;: for reading in rectangular data (i.e., Excel-style formatting)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://tibble.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tibble&lt;/code&gt;&lt;/a&gt;: using tibbles as modern/better dataframes&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://stringr.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;stringr&lt;/code&gt;&lt;/a&gt;: handling strings (i.e., text or stuff in quotes)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://forcats.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;forcats&lt;/code&gt;&lt;/a&gt;: for handling categorical variables (i.e., factors) (meow!)&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://tidyr.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tidyr&lt;/code&gt;&lt;/a&gt;: to make &amp;ldquo;tidy data&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://purrr.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;purrr&lt;/code&gt;&lt;/a&gt;: for enhancing functional programming (also meow!)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If you&amp;rsquo;re not understanding what some of this means, that&amp;rsquo;s totally fine.&lt;/p&gt;
&lt;p&gt;There are more tidyverse packages outside of these core eight, and you can see what they are below.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org/reference/tidyverse_packages.html&#39;&gt;tidyverse_packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] &#34;broom&#34;         &#34;cli&#34;           &#34;crayon&#34;        &#34;dbplyr&#34;       &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [5] &#34;dplyr&#34;         &#34;dtplyr&#34;        &#34;forcats&#34;       &#34;googledrive&#34;  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [9] &#34;googlesheets4&#34; &#34;ggplot2&#34;       &#34;haven&#34;         &#34;hms&#34;          &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [13] &#34;httr&#34;          &#34;jsonlite&#34;      &#34;lubridate&#34;     &#34;magrittr&#34;     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [17] &#34;modelr&#34;        &#34;pillar&#34;        &#34;purrr&#34;         &#34;readr&#34;        &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [21] &#34;readxl&#34;        &#34;reprex&#34;        &#34;rlang&#34;         &#34;rstudioapi&#34;   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [25] &#34;rvest&#34;         &#34;stringr&#34;       &#34;tibble&#34;        &#34;tidyr&#34;        &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [29] &#34;xml2&#34;          &#34;tidyverse&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;tl;dr&lt;/strong&gt; Tidyverse has a lot of packages that make data analysis easier. None of them are &amp;lsquo;required&amp;rsquo; to do data analysis, but many tidyverse approaches you&amp;rsquo;ll find easier than using base R.&lt;/p&gt;
&lt;p&gt;You can find &lt;a href=&#34;https://tavareshugo.github.io/data_carpentry_extras/base-r_tidyverse_equivalents/base-r_tidyverse_equivalents.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt; some examples of comparing tidyverse and base R syntax.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2---using-the-pipe-&#34;&gt;2 - Using the pipe &lt;code&gt;%&amp;gt;%&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;The pipe operator &lt;code&gt;%&amp;gt;%&lt;/code&gt; is a tool that is used for expressing a series of operations. It comes from the &lt;a href=&#34;https://cran.r-project.org/web/packages/magrittr/index.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;magrittr&lt;/code&gt;&lt;/a&gt; package, and is loaded automatically when you load the tidyverse.&lt;/p&gt;
&lt;p&gt;The purpose of the pipe is to allow you to take the output of one operation and have it be the starting material of the next step. It also (hopefully) makes your code easier to read and interpret.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Let&amp;rsquo;s get set up and grab some data so that we have some material to work with.&lt;/strong&gt;&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=palmerpenguins_hex.png width=&#34;50%&#34; alt=&#34;a cute hexagon image of three penguins as a part of the palmer penguins package&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Illustration by &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/articles/art.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We are going to use a package called &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;palmerpenguins&lt;/code&gt;&lt;/a&gt; which has some fun 🐧 data for us to play with. To get this data, we need to install the &lt;code&gt;palmerpenguins&lt;/code&gt; package.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;palmerpenguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/index.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;palmerpenguins&lt;/code&gt;&lt;/a&gt; is a package developed by Allison Horst, Alison Hill and Kristen Gorman, including a dataset collected by Dr. Kristen Gorman at the Palmer Station Antarctica, as part of the Long Term Ecological Research Network. It is a nice, relatively simple dataset to practice data exploration and visualization in R. Plus the penguins are v cute.&lt;/p&gt;
&lt;p&gt;Then, to use the package, we need to use the function &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; to call the package up in R.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The data we will use today is called &lt;code&gt;penguins&lt;/code&gt;.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=culmen_depth.png width=&#34;50%&#34; alt=&#34;a cute hexagon image of three penguins as a part of the palmer penguins package&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Illustration by &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/articles/art.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# look at the first 6 rows, all columns&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g sex  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;           &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.1          18.7              181        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;750 male &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.5          17.4              186        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;800 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Adelie  Torge…           40.3          18                195        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;250 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Adelie  Torge…           &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Adelie  Torge…           36.7          19.3              193        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;450 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.3          20.6              190        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;650 male &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1 more variable: year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# check the structure of penguins_data&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# glimpse() which is a part of dplyr functions &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# similarly to str() and can be used interchangeably&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 344&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ island            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Torgersen, Torgersen, Torgersen, Torgersen, Torgerse…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_length_mm    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_depth_mm     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ flipper_length_mm &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ body_mass_g       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sex               &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; male, female, female, NA, female, male, female, male…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year              &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Okay now we have a sense of what the &lt;code&gt;penguins&lt;/code&gt; dataset is.&lt;/p&gt;
&lt;p&gt;If we want to know how many penguins there are of each &lt;code&gt;species&lt;/code&gt; we can use the function &lt;code&gt;count().&lt;/code&gt; In the &lt;code&gt;count()&lt;/code&gt; function, the first argument is the dataset, and the next argument is what you want to be counted. You can always learn more about the arguments and syntax of functions by using &lt;code&gt;?yourfunction()&lt;/code&gt; or googling for the documentation. This is the non-pipe approach.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species       n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie      152&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Chinstrap    68&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Gentoo      124&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Alternatively, we can use the pipe to send &lt;code&gt;penguins&lt;/code&gt; forward through a series of steps. For example, we can use the function &lt;code&gt;count()&lt;/code&gt; to figure out how many of each penguin &lt;code&gt;species&lt;/code&gt; there are in our dataset.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# take penguins_data&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# count how many of each species there is&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species       n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie      152&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Chinstrap    68&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Gentoo      124&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;comparing-to-base-r&#34;&gt;Comparing to base R&lt;/h3&gt;
&lt;p&gt;A main benefit of the pipe is readability, and also the ability to &amp;ldquo;pipe&amp;rdquo; many things together (which we are not doing with &lt;code&gt;count()&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;I want to stress that everything you can do with the tidyverse you can also do using base R. I tend to think the tidyverse is more intuitive than base R, which is why we have elected to teach it here first. &lt;a href=&#34;https://tavareshugo.github.io/data_carpentry_extras/base-r_tidyverse_equivalents/base-r_tidyverse_equivalents.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Here&lt;/a&gt; you can find a bunch of examples comparing tidyverse to base R equivalent syntax. &lt;a href=&#34;http://varianceexplained.org/r/teach-tidyverse/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Here&lt;/a&gt; is an interesting blogpost on the topic if this is really keeping you up at night.&lt;/p&gt;
&lt;p&gt;I am going to show you an example of a place I think the pipe really shines, don&amp;rsquo;t worry if you don&amp;rsquo;t understand all the syntax, I just want you to see how the pipe can be used.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# drop missing values listed as NA&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# group by species&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_mass &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# summarize mass into new column called &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   mean_mass&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;706.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Chinstrap     &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;733.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Gentoo        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;&lt;span&gt;092.&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We are going to continue to use the pipe &lt;code&gt;%&amp;gt;%&lt;/code&gt; as we practice with some new &lt;code&gt;dplyr&lt;/code&gt; functions. &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-session-1---install-tidyverse-use-the-pipe&#34;&gt;Breakout session 1 - install tidyverse, use the pipe&lt;/h2&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;In your breakout sessions, make sure that you each have the tidyverse installed and loaded.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;tidyverse&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;dplyr&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# this is the only one of the 8 tidyverse packages we will use today&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Occasionally we see people who are having tidyverse install issues, if this happens to you, please read the warning that R gives you, you may need to download an additional package to get it to work. If you have trouble, first try restarting your R session and see if that helps, or reach out to one of the organizers or one of your fellow codeclubbers.&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;We will practice using the pipe. In S02E02, Mike introduced you to some new functions in &lt;a href=&#34;https://biodash.github.io/codeclub/s02e02_r-intro_part2/#breakout-rooms-ii-10-min&#34;&gt;Exercise 6&lt;/a&gt;. Take the dataset &lt;code&gt;penguins&lt;/code&gt; and use the pipe to determine the dimensions of the dataframe.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;a href=&#34;https://rdrr.io/r/base/dim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dim()&lt;/code&gt;&lt;/a&gt; to determine the dimensions&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 344   8&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This means the dataframe is 344 rows and 8 columns in size.&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Take the dataset &lt;code&gt;penguins&lt;/code&gt; and use the pipe to determine the names of the columns of the dataframe.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;a href=&#34;https://rdrr.io/r/base/names.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;names()&lt;/code&gt;&lt;/a&gt; or &lt;a href=&#34;https://rdrr.io/r/base/colnames.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;colnames()&lt;/code&gt;&lt;/a&gt; to pull the column names.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/names.html&#39;&gt;names&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;species&#34;           &#34;island&#34;            &#34;bill_length_mm&#34;   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [4] &#34;bill_depth_mm&#34;     &#34;flipper_length_mm&#34; &#34;body_mass_g&#34;      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [7] &#34;sex&#34;               &#34;year&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# the same&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/colnames.html&#39;&gt;colnames&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;species&#34;           &#34;island&#34;            &#34;bill_length_mm&#34;   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [4] &#34;bill_depth_mm&#34;     &#34;flipper_length_mm&#34; &#34;body_mass_g&#34;      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [7] &#34;sex&#34;               &#34;year&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;These are the names of our 8 columns.&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3---using-select&#34;&gt;3 - Using &lt;code&gt;select()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;It has been estimated that the process of getting your data into the appropriate formats takes about 80% of the total time of analysis. I find that getting data into a format that enables analysis often trips people up more than doing the actual analysis. The tidyverse package &lt;code&gt;dplyr&lt;/code&gt; has a number of functions that help in data wrangling.&lt;/p&gt;
&lt;p&gt;The first one we will talk about is &lt;code&gt;select()&lt;/code&gt;. Tidyverse is nice in that the functions are very descriptive and intuitive as to what they do: &lt;code&gt;select()&lt;/code&gt; allows you to pick certain columns to be included in your data frame.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s try out both the &lt;code&gt;%&amp;gt;%&lt;/code&gt; and &lt;code&gt;select()&lt;/code&gt;. Let&amp;rsquo;s make a new dataframe from &lt;code&gt;penguins&lt;/code&gt; that contains only the variables &lt;code&gt;species&lt;/code&gt;, &lt;code&gt;island&lt;/code&gt; and &lt;code&gt;sex&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_only_factors&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Did it work?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_only_factors&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island    sex   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie  Torgersen male  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Adelie  Torgersen female&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Adelie  Torgersen female&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Adelie  Torgersen &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Adelie  Torgersen female&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Adelie  Torgersen male&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s check the dimensions of each dataframe to make sure we have what we would expect&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# what are the dimensions of penguins?&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 344   8&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# what are the dimensions of penguins_only_factors?&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_only_factors&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 344   3&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The output is ordered rows (first number) by columns (second number). Our output makes sense - we haven&amp;rsquo;t removed any observation (i.e., rows), we have only selected some of the columns that we want to work with.&lt;/p&gt;
&lt;p&gt;What if we want to pick just the first three columns? We can do that too.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# what are those first three columns?&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; tibble [344 × 8] (S3: tbl_df/tbl/data.frame)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ species          : Factor w/ 3 levels &#34;Adelie&#34;,&#34;Chinstrap&#34;,..: 1 1 1 1 1 1 1 1 1 1 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ island           : Factor w/ 3 levels &#34;Biscoe&#34;,&#34;Dream&#34;,..: 3 3 3 3 3 3 3 3 3 3 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ bill_length_mm   : num [1:344] 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ bill_depth_mm    : num [1:344] 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ flipper_length_mm: int [1:344] 181 186 195 NA 193 190 181 195 193 190 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ body_mass_g      : int [1:344] 3750 3800 3250 NA 3450 3650 3625 4675 3475 4250 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ sex              : Factor w/ 2 levels &#34;female&#34;,&#34;male&#34;: 2 1 1 NA 1 2 1 2 NA NA ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ year             : int [1:344] 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 ...&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# pick columns species through bill_length_mm&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# you can add head() as part of your pipe!&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island    bill_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;              &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie  Torgersen           39.1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Adelie  Torgersen           39.5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Adelie  Torgersen           40.3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Adelie  Torgersen           &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Adelie  Torgersen           36.7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Adelie  Torgersen           39.3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note, in the above chunk, this new dataframe is not being saved because we have not assigned it to anything.&lt;/p&gt;
&lt;p&gt;You could use slightly different syntax to get the same thing using an indexing approach.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# pick columns 1-3&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island    bill_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;              &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie  Torgersen           39.1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Adelie  Torgersen           39.5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Adelie  Torgersen           40.3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Adelie  Torgersen           &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Adelie  Torgersen           36.7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Adelie  Torgersen           39.3&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;There is also convenient shorthand for indicating what you &lt;em&gt;don&amp;rsquo;t&lt;/em&gt; want (instead of what you do).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# all the columns except year&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g sex  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;           &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.1          18.7              181        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;750 male &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.5          17.4              186        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;800 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Adelie  Torge…           40.3          18                195        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;250 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Adelie  Torge…           &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Adelie  Torge…           36.7          19.3              193        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;450 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.3          20.6              190        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;650 male&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Embedded within &lt;code&gt;select()&lt;/code&gt; is the column order - you can change the order by denoting the order of your columns.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   bill_length_mm island    flipper_length_mm&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;                 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt;           39.1 Torgersen               181&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt;           39.5 Torgersen               186&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt;           40.3 Torgersen               195&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt;           &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;   Torgersen                &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt;           36.7 Torgersen               193&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt;           39.3 Torgersen               190&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4---using-filter&#34;&gt;4 - Using &lt;code&gt;filter()&lt;/code&gt;&lt;/h2&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=dplyr_filter.jpeg width=&#34;95%&#34;&gt;
&lt;figcaption&gt;
Artwork by &lt;a href=&#34;https://github.com/allisonhorst/stats-illustrations&#34;&gt;Allison Horst&lt;/a&gt;.
&lt;/figcaption&gt;
&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; allows you to pick certain observations (i.e, rows) based on their values to be included in your data frame. Let&amp;rsquo;s see it in action.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=lter_penguins.png width=&#34;90%&#34; alt=&#34;an illustration of the three cutepenguins in the palmer penguins package, chinstrap, gentoo and adélie&#34;&gt;
&lt;figcaption&gt;
Artwork by &lt;a href=&#34;https://github.com/allisonhorst/stats-illustrations&#34;&gt;Allison Horst&lt;/a&gt;.
&lt;/figcaption&gt;
&lt;/p&gt;
We will select only the &#34;Chinstrap&#34; penguins.
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_chinstrap&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Chinstrap&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# note the double equals&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# let&#39;s check that it worked&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_chinstrap&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species       n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Chinstrap    68&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can also check to see if we got what we would expect by looking at the dimensions of both &lt;code&gt;penguins&lt;/code&gt; and &lt;code&gt;penguins_chinstrap&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 344   8&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_chinstrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 68  8&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Great, you can see we have kept all of the columns (denoted by the second number 8), but trimmed down the rows/observations to only the Chinstrap penguins.&lt;/p&gt;
&lt;p&gt;You can use &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; in other useful ways too. Let&amp;rsquo;s make a new dataframe that has only the penguins that are over 5000 g.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;big_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# did it work?&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;big_penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5050 6300&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# another faster non-tidyverse way to do this&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;big_penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5050 6300&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can start stacking qualifiers to get the exact penguins you want. Let&amp;rsquo;s say we are only interested in penguins that are female and on the island Dream.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;female&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Dream&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 61 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species island bill_length_mm bill_depth_mm flipper_length_mm body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;           &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;             &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Adelie  Dream            39.5          16.7               178        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;250&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Adelie  Dream            39.5          17.8               188        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;300&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Adelie  Dream            36.4          17                 195        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;325&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Adelie  Dream            42.2          18.5               180        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;550&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Adelie  Dream            37.6          19.3               181        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;300&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Adelie  Dream            36.5          18                 182        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;150&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Adelie  Dream            36            18.5               186        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;100&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Adelie  Dream            37            16.9               185        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;000&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Adelie  Dream            36            17.9               190        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;450&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Adelie  Dream            37.3          17.8               191        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;350&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 51 more rows, and 2 more variables: sex &amp;lt;fct&amp;gt;, year &amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;There are lots of useful generic R operators that you can use inside functions like &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;==&lt;/code&gt;&lt;/a&gt;: exactly equals to&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;gt;=&lt;/code&gt;&lt;/a&gt;: greater than or equals to, you can also use ≥&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;lt;=&lt;/code&gt;&lt;/a&gt;: less than or equals to, you can also use ≤&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/Logic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;amp;&lt;/code&gt;&lt;/a&gt;: and&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/Logic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;|&lt;/code&gt;&lt;/a&gt;: or&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;!=&lt;/code&gt;&lt;/a&gt;: not equal to&lt;/li&gt;
&lt;li&gt;&lt;code&gt;!x&lt;/code&gt;: not x&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/NA.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;is.na()&lt;/code&gt;&lt;/a&gt;: is NA (i.e. missing data)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;There is a longer list of helpful &lt;code&gt;select()&lt;/code&gt; features &lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;&lt;strong&gt;tl;dr, &lt;code&gt;select()&lt;/code&gt; picks columns/variables and &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; picks rows/observations.&lt;/strong&gt;&lt;/p&gt;
&lt;h2 id=&#34;breakout-session-2---pipe-filter-select&#34;&gt;Breakout session 2 - pipe, filter, select&lt;/h2&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Make a new dataframe called &lt;code&gt;penguins_new&lt;/code&gt; that includes only the columns with numeric or integer data.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; or &lt;code&gt;glimpse()&lt;/code&gt; to figure out which columns are numeric or integers. Then use &lt;code&gt;select()&lt;/code&gt; to pick only the columns you want.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 344&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Adel…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ island            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Torgersen, Torgersen, Torgersen, Torgersen, Torgerse…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_length_mm    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_depth_mm     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ flipper_length_mm &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ body_mass_g       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sex               &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; male, female, female, NA, female, male, female, male…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year              &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007…&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;penguins_new&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# check to see if it worked&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_new&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   bill_length_mm bill_depth_mm flipper_length_mm body_mass_g  year&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;             &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt;           39.1          18.7               181        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;750  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt;           39.5          17.4               186        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;800  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt;           40.3          18                 195        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;250  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt;           &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                  &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt;           36.7          19.3               193        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;450  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt;           39.3          20.6               190        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;650  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;Getting fancy with some more advanced options&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# this works too&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_new2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;ends_with&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;mm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# this works three&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_new3&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;where&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;is.numeric&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;where&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;is.integer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# are they all the same?&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/all.equal.html&#39;&gt;all.equal&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_new2&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;penguins_new3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Make a new dataframe called &lt;code&gt;penguins_adelie_female&lt;/code&gt; that includes only the female penguins that are of the &lt;code&gt;species&lt;/code&gt; Adelie.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; to set which penguins you want to keep. Use the &lt;code&gt;%&amp;gt;%&lt;/code&gt; and &lt;code&gt;count()&lt;/code&gt; to make sure what you did worked.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_adelie&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Adelie&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;female&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# check to see if it worked&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_adelie&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species sex        n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie  female    73&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Make a new dataframe called &lt;code&gt;penguins_dream_or_2007&lt;/code&gt; that includes only the penguins on the island dream, or from the year 2007. Then make sure the dataframe only contains those variables you have filtered on.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; to set which penguins you want to keep. Use the &lt;code&gt;%&amp;gt;%&lt;/code&gt; and &lt;code&gt;select()&lt;/code&gt; to construct your new dataframe.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_dream_or_2007&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Dream&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;2007&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_dream_or_2007&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   island     year&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Torgersen  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Torgersen  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Torgersen  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Torgersen  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Torgersen  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Torgersen  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# did it work?&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_dream_or_2007&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 5 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   island     year     n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Biscoe     &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007    44&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Dream      &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007    46&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Dream      &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;008    34&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Dream      &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009    44&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Torgersen  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007    20&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;further-reading&#34;&gt;Further reading&lt;/h2&gt;
&lt;p&gt;There are many good (free) references for the tidyverse, including the book &lt;a href=&#34;https://r4ds.had.co.nz/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R for Data Science&lt;/a&gt; by Hadley Wickham and Garrett Grolemund.&lt;/p&gt;
&lt;p&gt;The package &lt;a href=&#34;https://dplyr.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dplyr&lt;/code&gt;&lt;/a&gt;, as part of the &lt;a href=&#34;https://www.rdocumentation.org/packages/tidyverse/versions/1.3.0&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tidyverse&lt;/code&gt;&lt;/a&gt; has a number of very helpful functions that will help you get your data into a format suitable for your analysis.&lt;/p&gt;
&lt;p&gt;RStudio makes very useful &lt;a href=&#34;https://www.rstudio.com/resources/cheatsheets/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;cheatsheets&lt;/a&gt;, including ones on tidyverse packages like &lt;code&gt;dplyr&lt;/code&gt;, &lt;code&gt;ggplot2&lt;/code&gt;, and others.&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Code Club S02E03: R Markdown</title>
      <link>https://biodash.github.io/codeclub/s02e03_rmarkdown/</link>
      <pubDate>Thu, 02 Sep 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s02e03_rmarkdown/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;R Markdown consists of an amazing ecosystem of R packages to produce many types of technical content. Its signature capability is that is can &lt;strong&gt;print formatted text, run R code, and display the results, all inside a single document&lt;/strong&gt;. Furthermore, you can easily export this document in a large variety of formats, including HTML, PDF, Word, RTF, etc. The webpage you are looking at now was written (almost) completely in R Markdown.&lt;/p&gt;
&lt;p&gt;At the most basic level, instead of using comments interleaved with your code in an R script:&lt;br&gt;
&lt;code&gt;# This is a comment&lt;/code&gt;&lt;br&gt;
you can insert formatted text around your code in an R Markdown file. You can structure your document with headings and subheadings. You can add tables of contents. You can even generate formatted bibliographies. And the R code you insert in the document runs &lt;strong&gt;inside the document&lt;/strong&gt; and the results go to the document itself, not to the console or (in the case of plots) to the Plots pane in RStudio.&lt;/p&gt;
&lt;p&gt;This makes RMarkdown a great &lt;strong&gt;computer lab notebook&lt;/strong&gt;, since you can explain what you&amp;rsquo;re doing and why (to colleagues or your future self). It&amp;rsquo;s also an example of &lt;strong&gt;reproducible research&lt;/strong&gt; since you share not just a Word file, say, with example code, but an active document in which the code actually runs and the results are reproduced.&lt;/p&gt;
&lt;p&gt;To understand R Markdown, we need to learn about three new things:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Markdown&lt;/strong&gt;, a very lightweight text formatting language.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Code chunks&lt;/strong&gt;, which allow us to incorporate R code that can be executed and whose results we can display in text, figures, and tables.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The YAML header&lt;/strong&gt;, which encodes metadata about the output, such as the desired output format and specific formatting features.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;We&amp;rsquo;ll focus on HTML output, but will also glance at other possibilities for the output format: with R Markdown, it is possible to create not just technical reports, but also slide decks, websites, books, scientific articles, dissertations, and so on.&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;setup&#34;&gt;Setup&lt;/h4&gt;
&lt;p&gt;At the core of the R Markdown ecosystem is the &lt;em&gt;rmarkdown&lt;/em&gt; package. We need to install this but don&amp;rsquo;t need to load it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;rmarkdown&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Inside your directory for Code Club, create a folder for this week:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;S02E03&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Select this folder in the Files pane. Then make this your working directory, using &amp;ldquo;Set as Working Directory&amp;rdquo; from the More options:&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=&#34;figs/setwd.jpg&#34; width=&#34;1000px&#34;/&gt;
&lt;/p&gt;
&lt;p&gt;(You don&amp;rsquo;t need to do this now: we&amp;rsquo;ll make it part of the first Breakout Room in just a moment&amp;hellip;)&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;first-an-example&#34;&gt;First, an example&lt;/h4&gt;
&lt;p&gt;Before we go into details, let&amp;rsquo;s first see a quick demonstration of what we&amp;rsquo;re talking about. RStudio lets you create an example R Markdown document with a couple of clicks. Here are the instructions: I&amp;rsquo;ll run through them, and then we&amp;rsquo;ll open Breakout rooms so you can try it out yourself.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Go to &lt;code&gt;File&lt;/code&gt; =&amp;gt; &lt;code&gt;New File&lt;/code&gt; =&amp;gt; &lt;code&gt;R Markdown&lt;/code&gt;, change the &lt;em&gt;Title&lt;/em&gt; to &amp;ldquo;Markdown demo&amp;rdquo;, and click &lt;code&gt;OK&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Take a look at the R Markdown document, and notice that there seems to be some sort of header bounded by three dashes (=&amp;gt; &lt;em&gt;&lt;strong&gt;YAML&lt;/strong&gt;&lt;/em&gt;), followed by R code wrapped in strange constructs with backticks and curly brackets (=&amp;gt; &lt;em&gt;&lt;strong&gt;Code chunks&lt;/strong&gt;&lt;/em&gt;), and formatted written text (=&amp;gt; &lt;em&gt;&lt;strong&gt;Markdown&lt;/strong&gt;&lt;/em&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Before we can render the output, we need to save the document. Click the &lt;code&gt;Save&lt;/code&gt; button and save the files as &lt;code&gt;demo.Rmd&lt;/code&gt; inside your newly created directory.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now click the &lt;strong&gt;Knit button&lt;/strong&gt; in one of the top bars, and a document should show up in a pop-up in the Viewer pane. This is the &lt;em&gt;rendered output&lt;/em&gt; from the R Markdown document, which is translated from Markdown into HTML behind the scenes, and displayed using a built in web-browser.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Notice that the YAML header is not printed (at least not verbatim) while some of the code is printed (some is hidden), and we also see code output, including a plot!&lt;/p&gt;
&lt;p&gt;This is what the raw and rendered output look side-by-side:&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=&#34;img/rmd-demo-both.png&#34; width=&#34;1000px&#34;/&gt;
&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-room-1&#34;&gt;Breakout Room 1&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Work through the example above yourselves. Generate a sample R Markdown file, in the correct directory, look at the contents, and make sure you can render it on your system using the &amp;ldquo;Knit&amp;rdquo; to HTML button in the top command bar.&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;p&gt;We&amp;rsquo;ll now talk about Markdown, code chunks, and the YAML header in turn.&lt;/p&gt;
&lt;h2 id=&#34;i-markdown&#34;&gt;I: Markdown&lt;/h2&gt;
&lt;p&gt;To fully appreciate the magic of Markdown and where it came from, it&amp;rsquo;s useful to just briefly visit the notion of a &lt;a href=&#34;https://en.m.wikipedia.org/wiki/Markup_language&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Markup language&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The original markup was done by a subeditor using a blue pencil on a handwritten or typed manuscript. This markup included typographic instructions for printing, like making a heading larger or text boldface, etc.&lt;/p&gt;
&lt;p&gt;Computer Markup languages have the same kind of annotations, which are included in the plain text, but are visually different from the content. This marked-up text is then sent to an interpreter (e.g. a web browser, a PDF viewer, an app like Word) which renders the final document.&lt;/p&gt;
&lt;p&gt;A large number of markup languages have been developed over the years. At current count there are about 60. This is how you would markup italic text in a small selection of them:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;HTML&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;i&amp;gt;This text is italic&amp;lt;/i&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Word .docx&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;w:t&amp;gt;This is italic text.&amp;lt;/w:t&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;TeX&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;\textit{This text is italic}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ODF text document .odt&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;text:p text:style-name=&amp;quot;P1&amp;quot;&amp;gt;This text is italic.&amp;lt;/text:p&amp;gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Rich text format .rtf&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;{\rtlch\ai \ltrch\loch\i\loch This text is italic.}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Some of these are more readable than others. Some are never meant to be read by humans at all! But underneath the hood &lt;strong&gt;every format is actually Markup&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The aim of Markdown is to create &lt;em&gt;lightweight&lt;/em&gt; Markup language, which is &lt;strong&gt;easy to read and easy to write&lt;/strong&gt; in a text editor. It embodies the principle: &amp;ldquo;make common things easy, and rare things possible&amp;rdquo;. Then we let the computer do the work of translating Markdown into various markup languages and rendering them, so we don&amp;rsquo;t have to worry about the details:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Markdown&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;*This text is italic.*&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;The &amp;ldquo;Swiss Army Knife&amp;rdquo; for letting the computer convert between Markup languages is &lt;a href=&#34;https://pandoc.org&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Pandoc&lt;/a&gt;. The Pandoc site contains a graphic which shows what can be translated to what (included here just to give you a sense of the extent of this Markup world):&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Click here to see the Pandoc figure
&lt;/summary&gt;
&lt;p&gt;&lt;img src=&#34;figs/pandoc.jpg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;p&gt;R Markdown uses Pandoc as its engine for translating Markdown to various Markup languages.&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;an-overview-of-commonly-used-markdown-syntax&#34;&gt;An overview of commonly used Markdown syntax&lt;/h4&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Syntax&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;# My Title&lt;/td&gt;
&lt;td&gt;Header level 1 (largest)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;## My Section&lt;/td&gt;
&lt;td&gt;Header level 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;### My Subsection&lt;/td&gt;
&lt;td&gt;Header level 3 &amp;ndash; and so forth&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;*italic* or _italic_&lt;/td&gt;
&lt;td&gt;&lt;em&gt;italic&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;**bold** or __bold__&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;bold&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;[Markdown Guide](markdownguide.org)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://markdownguide.org&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Markdown Guide&lt;/a&gt; (Link with custom text)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;![](path/to/figure.png)&lt;/td&gt;
&lt;td&gt;Figure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;- List item&lt;/td&gt;
&lt;td&gt;Unordered (bulleted) list&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1. List item&lt;/td&gt;
&lt;td&gt;Ordered (numbered) list&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;`inline code`&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;inline code&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;```&lt;/code&gt; &lt;br&gt; &amp;hellip;code&amp;hellip; &lt;br&gt; &lt;code&gt;```&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Generic code block (for formatting only) &lt;br&gt; (&lt;em&gt;Alternative syntax: 4 leading spaces.&lt;/em&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;```r&lt;/code&gt; &lt;br&gt; &amp;hellip;code&amp;hellip; &lt;br&gt; &lt;code&gt;```&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;r&lt;/code&gt; code block (for formatting only)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;---&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Horizontal rule (line)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Below you&amp;rsquo;ll see an examples of raw Markdown on the left, and its &lt;em&gt;rendered&lt;/em&gt; (formatted) output on the right:&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/md-demo.png width=&#34;2000px&#34;&gt;
&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;&amp;ldquo;Plain&amp;rdquo; Markdown files have the extension &lt;code&gt;.md&lt;/code&gt;, whereas R Markdown&lt;/p&gt;
&lt;p&gt;files have the extension &lt;code&gt;.Rmd&lt;/code&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;ii-integrating-r-code&#34;&gt;II: Integrating R code&lt;/h2&gt;
&lt;p&gt;As we saw above, plain Markdown has syntax for code &lt;em&gt;formatting&lt;/em&gt;, but the code is not actually being executed. &lt;strong&gt;In R Markdown, however, we are able run code!&lt;/strong&gt; The syntax to do so is only slightly modified from what we saw above:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For &lt;strong&gt;inline code&lt;/strong&gt;, we add &lt;code&gt;r&lt;/code&gt; and a space before the R code that is to be executed, for example:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Raw&lt;/th&gt;
&lt;th&gt;Rendered&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;There are &lt;code&gt;`365*24`&lt;/code&gt; hours in a year&lt;/td&gt;
&lt;td&gt;There are &lt;code&gt;365*24&lt;/code&gt; hours in a year&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;There are &lt;code&gt;`r 365*24`&lt;/code&gt; hours in a year&lt;/td&gt;
&lt;td&gt;There are 8760 hours in a year&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To generate &lt;em&gt;code blocks&lt;/em&gt;, which we call &lt;strong&gt;code chunks&lt;/strong&gt; in an R Markdown context,&lt;br&gt;
we add r &lt;em&gt;inside curly braces&lt;/em&gt;: &lt;code&gt;```{r}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;We can optionally add settings that we want to apply to that chunk:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;```{r, option1=value, ...}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;These options control things like:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;do you want your code to be displayed in the document, or just the results?&lt;/li&gt;
&lt;li&gt;do you want alerts and warnings to be displayed or not?&lt;/li&gt;
&lt;li&gt;do you want to turn off results, temporarily or permanently?&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;and many others.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;RStudio keyboard shortcut to insert a code chunk: &lt;kbd&gt;Cmd/Ctrl&lt;/kbd&gt;+&lt;kbd&gt;Alt&lt;/kbd&gt;+&lt;kbd&gt;I&lt;/kbd&gt;.&lt;/p&gt;
&lt;p&gt;There is also an Insert Code Chunk Button in the top bar of RStudio.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h4 id=&#34;code-chunk-examples&#34;&gt;Code chunk examples&lt;/h4&gt;
&lt;p&gt;In these examples we&amp;rsquo;ll use the &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Palmer Penguins&lt;/a&gt; dataset. To access this dataset yourself, do:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;palmerpenguins&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;palmerpenguins&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The example code we&amp;rsquo;ll be using comes from the &lt;strong&gt;tidyverse&lt;/strong&gt; package. If you don&amp;rsquo;t have that installed yet, you need to do:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;tidyverse&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tidyverse&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;(If you&amp;rsquo;ve participated in Code Club before you probably have these packages installed).&lt;/p&gt;
&lt;p&gt;Don&amp;rsquo;t worry &lt;strong&gt;at all&lt;/strong&gt; if you don&amp;rsquo;t understand the example code. This is exactly what we&amp;rsquo;ll be moving onto in the coming weeks. The point is that the code is executed and displayed inside the document.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A code chunk with &lt;strong&gt;default options&lt;/strong&gt;&amp;hellip;&lt;/p&gt;
&lt;p align=&#34;left&#34;&gt;
&lt;img src=img/example-chunk-1.png width=&#34;100%&#34;&gt;
&lt;/p&gt;
&lt;p&gt;&amp;hellip;will be executed and shown followed by the output of the code:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 17.15117&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;As an example of using a &lt;strong&gt;code chunk option&lt;/strong&gt;, we will disable printing the code using &lt;code&gt;echo=FALSE&lt;/code&gt; (the code will still run and the output will still be shown):&lt;/p&gt;
&lt;p align=&#34;left&#34;&gt;
&lt;img src=img/example-chunk-2.png width=&#34;100%&#34;&gt;
&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 17.15117&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Figures&lt;/strong&gt; have some specific options, including &lt;strong&gt;captions&lt;/strong&gt;:&lt;/p&gt;
&lt;p align=&#34;left&#34;&gt;
&lt;img src=img/example-chunk-3.png width=&#34;100%&#34;&gt;
&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_bw&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;figure&#34; style=&#34;text-align: center&#34;&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-6-1.png&#34; alt=&#34;Fig. 1: Bill length and depth are correlated within species, &amp;lt;br&amp;gt; and differ subtly between species.&#34; width=&#34;700px&#34; /&gt;&lt;/p&gt;
&lt;p class=&#34;caption&#34;&gt;
Fig. 1: Bill length and depth are correlated within species, &lt;br&gt; and differ subtly between species.
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We added a caption for the figure using the &lt;code&gt;fig.cap&lt;/code&gt; option.&lt;/p&gt;
&lt;h4 id=&#34;code-chunk-options&#34;&gt;Code chunk options&lt;/h4&gt;
&lt;p&gt;There are huge number of options, and various options are specific to certain types of code chunks. Just learn the basic structure first, and if you ever wonder &amp;ldquo;Can I do X to modify the output?&amp;rdquo; just know that many, many people have wondered that before, and if it makes sense to do it, you can probably do it with options.&lt;/p&gt;
&lt;p&gt;Here is an overview of some the most commonly made &lt;em&gt;changes to defaults&lt;/em&gt; for code chunk options. This quickly gets confusing, but you&amp;rsquo;ll get the hang of it after experimenting a bit.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;echo=FALSE&lt;/code&gt; &amp;ndash; Don&amp;rsquo;t print the code in the output file.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;eval=FALSE&lt;/code&gt; &amp;ndash; Don&amp;rsquo;t run (&lt;strong&gt;eval&lt;/strong&gt;uate) the code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;include=FALSE&lt;/code&gt; &amp;ndash; Run but don&amp;rsquo;t print the code, nor any of its results.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;results=&amp;quot;hide&amp;quot;&lt;/code&gt; &amp;ndash; Don&amp;rsquo;t print the &lt;em&gt;text output&lt;/em&gt; of the code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fig.show=&amp;quot;hide&amp;quot;&lt;/code&gt; &amp;ndash; Don&amp;rsquo;t print &lt;em&gt;figures&lt;/em&gt; produced by the code.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Furthermore, you can use &lt;code&gt;message=FALSE&lt;/code&gt; and &lt;code&gt;warning=FALSE&lt;/code&gt; to suppress any &lt;em&gt;messages&lt;/em&gt; (like the output when loading packages) and &lt;em&gt;warnings&lt;/em&gt; (like the warning for the penguin figure above), respectively, that R might produce.&lt;/p&gt;
&lt;p&gt;For figures, the following options are especially useful:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;fig.cap=&amp;quot;My caption&amp;quot;&lt;/code&gt; &amp;ndash; Include a caption.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fig.asp=0.6&lt;/code&gt; &amp;ndash; Aspect ratio.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fig.width=6&lt;/code&gt; &amp;ndash; Width of in inches: same as sizing in regular R code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fig.height=9.6&lt;/code&gt; &amp;ndash; Height in inches: same as sizing in regular R code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;out.width=&amp;quot;70%&amp;quot;&lt;/code&gt; &amp;ndash; Figure width as &lt;em&gt;printed in the document&lt;/em&gt; (in &lt;code&gt;%&lt;/code&gt; or pixels, &lt;code&gt;px&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;out.height=&amp;quot;500px&amp;quot;&lt;/code&gt; &amp;ndash; Figure height as &lt;em&gt;printed in the document&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;iii-the-yaml-header&#34;&gt;III: The YAML header&lt;/h2&gt;
&lt;p&gt;YAML (&lt;em&gt;&amp;ldquo;YAML Ain&amp;rsquo;t Markup Language&amp;rdquo;&lt;/em&gt;) is a simple format commonly used for &lt;em&gt;configuration files&lt;/em&gt;, which allows you to provide key-value pairs such as &lt;code&gt;author: John Doe&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In R Markdown files, it is used as a &lt;strong&gt;header&lt;/strong&gt; which configures certain aspects of the output, especially the formatting. Put another way, the YAML header &lt;em&gt;contains the metadata&lt;/em&gt; for the output.&lt;/p&gt;
&lt;h4 id=&#34;a-basic-yaml-header&#34;&gt;A basic YAML header&lt;/h4&gt;
&lt;p&gt;Here is an example of a very basic YAML header:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;---
author: My name
title: The document&#39;s title
output: html_document
---
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note the lines which just contain &lt;strong&gt;three dashes&lt;/strong&gt;, which mark the beginning and the end of the YAML header.&lt;/p&gt;
&lt;h4 id=&#34;adding-extra-options&#34;&gt;Adding extra options&lt;/h4&gt;
&lt;p&gt;Often, a value (like &lt;code&gt;html_document&lt;/code&gt;) can itself be given key-value pairs to specify additional options &amp;ndash; see the example below where we include a Table of Contents (&lt;code&gt;toc&lt;/code&gt;) and also set it to &amp;ldquo;float&amp;rdquo;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;---
output:
  html_document:
    toc: true
    toc_float: true
---
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Note that indentation in YAML uses two (or four) spaces (no tabs!) per indentation level, and it is &lt;em&gt;sensitive to indentation errors&lt;/em&gt;. (Fortunately, RStudio inserts spaces for tabs by default &amp;ndash; check/set in &lt;code&gt;Tools&lt;/code&gt; =&amp;gt; &lt;code&gt;Global Options&lt;/code&gt; =&amp;gt; &lt;code&gt;Code&lt;/code&gt; =&amp;gt; &lt;code&gt;Editing&lt;/code&gt;.)&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;some-options-for-html_document-output&#34;&gt;Some options for &lt;code&gt;html_document&lt;/code&gt; output&lt;/h4&gt;
&lt;p&gt;&lt;code&gt;html_document&lt;/code&gt; is the most commonly used output format for R Markdown documents, and here are few particularly useful options to customize the output:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;code_download: true&lt;/code&gt; &amp;ndash; Include a button to download the code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;code_folding: hide&lt;/code&gt; &amp;ndash; Using &lt;code&gt;hide&lt;/code&gt; or &lt;code&gt;show&lt;/code&gt; will enable the folding of code chunks, with &lt;code&gt;hide&lt;/code&gt; hiding them by default.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toc: true&lt;/code&gt; &amp;ndash; Include a table of contents (Also: &lt;code&gt;toc_depth: 3&lt;/code&gt; sets depth to 3, &lt;code&gt;toc_float: true&lt;/code&gt; lets the TOC &amp;ldquo;float&amp;rdquo; as you scroll down the document).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;number_sections: true&lt;/code&gt; &amp;ndash; Number the section headings.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;df_print: paged&lt;/code&gt; &amp;ndash; Get nicely formatted and paged data frame printing (also try: &lt;code&gt;df_print: kable&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;theme: cerulean&lt;/code&gt; &amp;ndash; Use a pre-built theme, controlling the overall look and feel of the document. See &lt;a href=&#34;https://www.datadreaming.org/post/r-markdown-theme-gallery/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt; for a visual overview.&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/rmd-3themes.png width=&#34;100%&#34;&gt;
&lt;figcaption&gt;
Three HTML document &lt;code&gt;theme&lt;/code&gt; options: &lt;code&gt;darkly&lt;/code&gt;, &lt;code&gt;flatly&lt;/code&gt;, and &lt;code&gt;cerulean&lt;/code&gt;.
&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;iv-r-markdown-and-rstudio&#34;&gt;IV: R Markdown and RStudio&lt;/h2&gt;
&lt;p&gt;The R Markdown ecosystem of packages is being developed by RStudio, so it should come as no surprise that the RStudio IDE has some nice R Markdown functionality.&lt;/p&gt;
&lt;h4 id=&#34;knitting-and-previewing-your-document&#34;&gt;Knitting and previewing your document&lt;/h4&gt;
&lt;p&gt;The process of rendering an R Markdown file into another format, as specified by the YAML header, is called &lt;strong&gt;knitting&lt;/strong&gt;. We already saw the button to knit the current document (keyboard shortcut: &lt;kbd&gt;Cmd/Ctrl&lt;/kbd&gt;+&lt;kbd&gt;Shift&lt;/kbd&gt;+&lt;kbd&gt;K&lt;/kbd&gt;).&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;If you get preview pop-up windows in RStudio, click the cog wheel icon next to the Knit button, and then select &amp;ldquo;&lt;em&gt;Preview in Viewer Pane&lt;/em&gt;&amp;rdquo;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br&gt; Instead of knitting the entire document, you can also &lt;strong&gt;run individual code chunks&lt;/strong&gt; using the green &amp;ldquo;play button&amp;rdquo; (or &lt;kbd&gt;Cmd/Ctrl&lt;/kbd&gt;+&lt;kbd&gt;Shift&lt;/kbd&gt;+&lt;kbd&gt;Enter&lt;/kbd&gt;), or all code chunks up until the current one (button to the left of the play button).&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-room-2&#34;&gt;Breakout Room 2&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;For this exercise, you&amp;rsquo;ll convert an R Script file into an R Markdown file.&lt;/p&gt;
&lt;p&gt;First you&amp;rsquo;ll download the script file to your working directory (using the code provided below). Then open it in R Studio, copy the contents, and paste the contents into your demo.Rmd file (after the YAML header). Then work through making adjustments, and Knit at various times to check your work.&lt;/p&gt;
&lt;p&gt;There are various suggestions (in parentheses) for Markdown formatting throughout the script.&lt;/p&gt;
&lt;p&gt;And remember, you need to wrap the actual R code from the script inside R Markdown code chunks.&lt;/p&gt;
&lt;p&gt;You&amp;rsquo;ll also download an example picture. Include this picture in your demo.Rmd file using the Markdown syntax shown above. Then experiment with the various figure options to get it how you want it.&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll download the files in a similar way to last week. Execute the following code, either by copying into the console, or by creating a new script file and copying the commands into it, and executing them one by one. To keep things tidy and readable, first we create objects that hold the URLs we&amp;rsquo;re downloading from:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;script_URL&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/S02E03_rmarkdown/demo.R&amp;#34;&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;picture_URL&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/S02E03_rmarkdown/picture.jpg&amp;#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then use the &lt;a href=&#34;https://rdrr.io/r/utils/download.file.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;download.file()&lt;/code&gt;&lt;/a&gt; function with two arguments, the remote URL and the local file name (which must be in quotes):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;download.file&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;url&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;script_URL&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;destfile&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;demo.R&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;download.file&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;url&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;picture_URL&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;destfile&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;picture.jpg&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You should end up with the two local files showing up in your Files pane.&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;v-a-single-source-doc-many-output-formats&#34;&gt;V: A single source doc, many output formats!&lt;/h2&gt;
&lt;p&gt;Because of the Pandoc backend, a great feature of R Markdown is that you can output to many formats. So from one source document, or very similar variants, you can create completely different output depending on what you need.&lt;/p&gt;
&lt;h4 id=&#34;built-in-output-formats&#34;&gt;Built-in output formats&lt;/h4&gt;
&lt;p&gt;The &lt;a href=&#34;https://rmarkdown.rstudio.com/docs/reference/index.html#section-output-formats&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;built-in output formats&lt;/a&gt;, which can be used with just the &lt;em&gt;rmarkdown&lt;/em&gt; package, are listed below. These include HTML, PDF, Word, PowerPoint, and different HTML slide show formats.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/rmarkdown-output-formats.png width=&#34;80%&#34;&gt;
&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;extension-output-formats&#34;&gt;Extension output formats&lt;/h4&gt;
&lt;p&gt;It&amp;rsquo;s worth highlighting a few of the output formats that can be used with the following packages in the R Markdown ecosystem:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://rstudio.github.io/distill/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;distill&lt;/em&gt;&lt;/a&gt; &amp;ndash; An output format geared towards technical content, e.g. with extended support for equations, citations, and footnotes. Can also create websites.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/rstudio/rticles&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;rticles&lt;/em&gt;&lt;/a&gt; &amp;ndash; R Markdown templates to format output for specific scientific journals.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://rmarkdown.rstudio.com/flexdashboard/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;flexdashboard&lt;/em&gt;&lt;/a&gt; &amp;ndash; Create interactive &amp;ldquo;dashboards&amp;rdquo; to present data.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://bookdown.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;bookdown&lt;/em&gt;&lt;/a&gt; &amp;ndash; A book format, the &lt;a href=&#34;https://bookdown.org/yihui/rmarkdown/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R Markdown book&lt;/a&gt; is an example.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://bookdown.org/yihui/rmarkdown/xaringan.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;xaringan&lt;/em&gt;&lt;/a&gt; &amp;ndash; Create fancier presentation slides thanks to a JavaScript library.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Starting to use these and other output formats is often as simple as changing the YAML header:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span class=&#34;nn&#34;&gt;---&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;output&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;l&#34;&gt;distill::distill_article&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;nn&#34;&gt;---&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;
&lt;hr&gt;
&lt;h4 id=&#34;further-resources&#34;&gt;Further resources&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Free online books by the primary creator of R Markdown and other authors:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://bookdown.org/yihui/rmarkdown/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R Markdown &amp;ndash; The Definitive Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://bookdown.org/yihui/rmarkdown-cookbook/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R Markdown Cookbook&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;RStudio&amp;rsquo;s 5-page R Markdown Reference PDF&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/rstudio/cheatsheets/raw/master/rmarkdown-2.0.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;RStudio&amp;rsquo;s R Markdown Cheatsheet&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://rmarkdown.rstudio.com/lesson-1.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;RStudio R Markdown lessons&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://commonmark.org/help/tutorial/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Markdown tutorial&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>Code Club S02E02: An introduction to R (Part 2)</title>
      <link>https://biodash.github.io/codeclub/s02e02_r-intro_part2/</link>
      <pubDate>Mon, 30 Aug 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s02e02_r-intro_part2/</guid>
      <description>&lt;br&gt;
&lt;h2 id=&#34;learning-objectives&#34;&gt;Learning objectives&lt;/h2&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Create objects in R&lt;/li&gt;
&lt;li&gt;Recognize and use R functions&lt;/li&gt;
&lt;li&gt;Differentiate between some common object classes and data structures in R&lt;/li&gt;
&lt;li&gt;Read in data from a file&lt;/li&gt;
&lt;li&gt;Install and load R packages&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1----intro&#34;&gt;1 &amp;ndash; Intro&lt;/h2&gt;
&lt;p&gt;Nearly everything you do in R will involve &lt;strong&gt;objects&lt;/strong&gt;, &lt;strong&gt;functions&lt;/strong&gt;, or (often) both. In this session, we&amp;rsquo;ll take a quick look at each of these fundamental components for working in R. In addition, we&amp;rsquo;ll get introduced to R packages (since they&amp;rsquo;ll provide many of the functions you&amp;rsquo;ll use), and also practice reading some data in to R.&lt;/p&gt;
&lt;h2 id=&#34;2----objects&#34;&gt;2 &amp;ndash; Objects&lt;/h2&gt;
&lt;p&gt;Objects are things in R to which a name can be assigned. They&amp;rsquo;re created using the assignment operator &amp;ldquo;&amp;lt;-&amp;rdquo;, which can be thought of as an arrow (it&amp;rsquo;s actually two separate characters - the less than symbol and dash) that points whatever is on the right side to a name provided on the left side. For example, running the following three lines of code creates objects named &amp;ldquo;x&amp;rdquo;, &amp;ldquo;y&amp;rdquo;, and &amp;ldquo;z&amp;rdquo;, respectively&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;z&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;cat&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If you run these lines in RStudio, you&amp;rsquo;ll see the resulting objects listed in the top right panel. This is really helpful for keeping track of object names, as you&amp;rsquo;ll often create many objects during an R session. Calling the objects returns their values&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 6&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;z&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;cat&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;3----functions&#34;&gt;3 &amp;ndash; Functions&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;ll return to objects shortly, but first, let&amp;rsquo;s take a very basic look at functions, which make up a second really important part of R. You can think of objects as &lt;strong&gt;being&lt;/strong&gt; things in R, while functions &lt;strong&gt;do&lt;/strong&gt; things in R. I&amp;rsquo;ll start by writing a very simple function&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#define the function&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;cubed_plus10&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;^&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#apply the function&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;cubed_plus10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 74&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;No need to get caught up in details of writing the function right now. A couple important things to recognize at this point&amp;hellip;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;We created a function that took some input - the &amp;lsquo;4&amp;rsquo; in the example above, did something to it, and returned some output.&lt;/li&gt;
&lt;li&gt;To run the function, we used its name, followed by a set of parentheses. All R functions have that general structure. The parentheses might contain 0, 1, or more items (often referred to as &lt;strong&gt;options&lt;/strong&gt; or &lt;strong&gt;arguments&lt;/strong&gt;).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;It&amp;rsquo;s useful to be able to create your own functions. But if that sounds a little advanced to you at this point, you can still do a lot with R even without knowing how to write your own, as there are lots that have already been written for you. A number of commonly-used functions are available as soon as you start an R session - these are often referred to as &amp;ldquo;base R&amp;rdquo; functions.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#some example base R functions&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/date.html&#39;&gt;date&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Tue Aug 31 10:24:39 2021&#34;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/getwd.html&#39;&gt;getwd&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;/Users/sovic.1/Desktop/docs/Desktop_clear_4-28-21/S18_dev/biodash.github.io/content/codeclub/S02E02_r-intro_part2&#34;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/MathFun.html&#39;&gt;sqrt&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;25&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;4----object-classes-and-data-structures&#34;&gt;4 &amp;ndash; Object Classes and Data Structures&lt;/h2&gt;
&lt;p&gt;Now that we have at least a basic idea of R functions, we&amp;rsquo;ll turn attention back to objects (and use functions along the way from here on out). The objects we&amp;rsquo;ve created so far have been pretty simple. Let&amp;rsquo;s revisit the three from above&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 6&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;z&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;cat&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;There are lots of different kinds, or &lt;em&gt;classes&lt;/em&gt; of objects in R, and behind the scenes, each object that&amp;rsquo;s created is immediately assigned to a class (or possibly multiple classes). There&amp;rsquo;s no real limit to the number of classes that exist, as new ones can be created for specialized cases at any time. But there are a fairly small number of object classes you&amp;rsquo;ll encounter a lot in R, so we&amp;rsquo;ll take a look at some of those now. Let&amp;rsquo;s use the &lt;a href=&#34;https://rdrr.io/r/base/class.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;class()&lt;/code&gt;&lt;/a&gt; function to figure out what class R assigned each of our objects to&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;numeric&#34;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;logical&#34;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;z&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;character&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Some very common object classes you&amp;rsquo;ll encounter&amp;hellip;&lt;/p&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;integer&lt;/li&gt;
&lt;li&gt;double (numeric)&lt;/li&gt;
&lt;li&gt;logical&lt;/li&gt;
&lt;li&gt;character&lt;/li&gt;
&lt;li&gt;factor&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p&gt;I&amp;rsquo;m going to introduce a new term here that&amp;rsquo;s closely tied to object classes, and that&amp;rsquo;s &lt;em&gt;data structures&lt;/em&gt;. Again, there are a small number of data structures you&amp;rsquo;ll work with a lot in R. They include&amp;hellip;&lt;/p&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Vectors&lt;/li&gt;
&lt;li&gt;Matrices&lt;/li&gt;
&lt;li&gt;Data Frames&lt;/li&gt;
&lt;li&gt;Lists&lt;/li&gt;
&lt;li&gt;Arrays&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;p&gt;Today we&amp;rsquo;ll focus in on two of these - &lt;strong&gt;vectors&lt;/strong&gt; and &lt;strong&gt;data frames&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&#34;5----vectors&#34;&gt;5 &amp;ndash; Vectors&lt;/h2&gt;
&lt;p&gt;Vectors in R share a couple important characteristics&amp;hellip;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;They&amp;rsquo;re one-dimensional. In other words, they can be defined by a length property, with length zero, one, or more.&lt;/li&gt;
&lt;li&gt;All elements of a vector must be of the same type, or class.&lt;/li&gt;
&lt;li&gt;Operations can be performed on vectors - &lt;em&gt;vector recycling&lt;/em&gt; rules apply (we&amp;rsquo;ll see this in the breakout exercises next).&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The &lt;a href=&#34;https://rdrr.io/r/base/c.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;c()&lt;/code&gt;&lt;/a&gt; function is useful for creating vectors in R. It stands for &amp;ldquo;combine&amp;rdquo;, and allows you to combine multiple items into a single vector object&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;odds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;9&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;animals&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;dog&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;cat&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;cow&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#view the objects&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;odds&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 3 5 7 9&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;animals&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;dog&#34; &#34;cat&#34; &#34;cow&#34;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#check their class&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;odds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;numeric&#34;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;animals&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;character&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;breakout-rooms-i-10-min&#34;&gt;Breakout Rooms I (~10 min.)&lt;/h3&gt;
&lt;h4 id=&#34;exercise-1-create-vector-objects&#34;&gt;Exercise 1: Create Vector Objects&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Create two objects (vectors) named &lt;em&gt;short_vec&lt;/em&gt; and &lt;em&gt;long_vec&lt;/em&gt;. To &lt;em&gt;short_vec&lt;/em&gt;, assign the integers 1 through 5, and to &lt;em&gt;long_vec&lt;/em&gt;, assign the integers 1 through 10. View each of the objects and check their class.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; The colon can be used to define a sequence of integers in R, for example, 1:3 represents the vector 1,2,3. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;short_vec&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;long_vec&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;short_vec&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3 4 5&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;long_vec&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  1  2  3  4  5  6  7  8  9 10&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;short_vec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;integer&#34;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;long_vec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;integer&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h4 id=&#34;exercise-2-vector-operationsrecycling&#34;&gt;Exercise 2: Vector Operations/Recycling&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now try adding the two vectors, &lt;em&gt;short_vec&lt;/em&gt; and &lt;em&gt;long_vec&lt;/em&gt;, together. Assign the result to a new object named &lt;em&gt;vec_sum&lt;/em&gt;. Think about and talk through what you expect the result might look like before you execute the code.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Before R performs an operation on any vectors, the vectors involved must be the same length. If they aren&amp;rsquo;t, the shorter vector is &amp;ldquo;recycled&amp;rdquo; until it matches the length of longer vector. Then the operation is performed. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;
&lt;span class=&#39;nv&#39;&gt;vec_sum&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;short_vec&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long_vec&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;vec_sum&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  2  4  6  8 10  7  9 11 13 15&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h4 id=&#34;exercise-3-vector-operationsrecycling-ii&#34;&gt;Exercise 3: Vector Operations/Recycling II&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Just to drive this point on vector recycling home a little more, let&amp;rsquo;s do more operation - this time, subtract 3 (itself a vector of length 1) from &lt;em&gt;short_vec&lt;/em&gt;. Again, try to predict what will happen before you run it.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;short_vec&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -2 -1  0  1  2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;Keep in mind that all elements of a vector in R have to be of the same class. This means you typically won&amp;rsquo;t see a vector that looks like&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;mixed_vector&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;cat&#34;&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;dog&#34;&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can create such a vector, but in this case, R will view it as a character vector, meaning, for example, the 1 and 4 won&amp;rsquo;t be treated as numbers, but as characters. Such forcing of an element or object into a specific class is often referred to as &lt;strong&gt;coercion&lt;/strong&gt;. Let&amp;rsquo;s go back to our object &amp;lsquo;x&amp;rsquo;&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 6&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;numeric&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice it&amp;rsquo;s assigned as numeric. Let&amp;rsquo;s say we wanted R to see it as an integer (just slightly different in R than numeric)&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/integer.html&#39;&gt;as.integer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;integer&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We have used the &lt;a href=&#34;https://rdrr.io/r/base/integer.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;as.integer()&lt;/code&gt;&lt;/a&gt; function to coerce x into class &lt;strong&gt;integer&lt;/strong&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;6----data-frames&#34;&gt;6 &amp;ndash; Data Frames&lt;/h2&gt;
&lt;p&gt;Data frames are another data structure in R you&amp;rsquo;ll likely use a lot. Some characteristics of data frames&amp;hellip;&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;They have two dimensions (rows, columns)&lt;/li&gt;
&lt;li&gt;Each variable (column) needs to have the same number of entries.&lt;/li&gt;
&lt;li&gt;All elements of any one column have to be of the same type/class, but different columns can be of different classes.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;A good way to think about a data frame is as being analogous to an Excel spreadsheet, with the caveat that all the columns have the same number of entries, which isn&amp;rsquo;t a requirement in an Excel sheet.&lt;/p&gt;
&lt;p&gt;You can create a data frame by hand with the &lt;a href=&#34;https://rdrr.io/r/base/data.frame.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;data.frame()&lt;/code&gt;&lt;/a&gt; function, but in many cases, you&amp;rsquo;ll create a data frame in R by reading data in from a file with one of a number of functions that are available for that purpose. Let&amp;rsquo;s try it. Here&amp;rsquo;s a small example dataset I generated in Excel&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;https://github.com/biodash/biodash.github.io/raw/master/assets/data/data_frame/df_example.png&#34; alt=&#34;example data set&#34;&gt;&lt;/p&gt;
&lt;p&gt;It&amp;rsquo;s available at the following address&amp;hellip; &lt;a href=&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/data/data_frame/example_df.tsv&#34;&gt;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/data/data_frame/example_df.tsv&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;(In this case, the data set comes from online, but often it will be a file on your computer, and the path to the file works the same way as how you&amp;rsquo;ll use the web address below.)&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;breakout-rooms-ii-10-min&#34;&gt;Breakout Rooms II (~10 min.)&lt;/h3&gt;
&lt;h4 id=&#34;exercise-4-reading-in-a-data-frame&#34;&gt;Exercise 4: Reading In A Data Frame&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Create an object named &amp;ldquo;data_address&amp;rdquo; that stores the web address for the dataset.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use the assignment operator and make sure to put the address in quotes to define it as a character string. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;data_address&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/data/data_frame/example_df.tsv&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;p&gt;Now use the &lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read.table()&lt;/code&gt;&lt;/a&gt; function to read the dataset in as a data frame. Assign it as an object named &amp;lsquo;exp_data&amp;rsquo; and view it in R.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use the &lt;em&gt;data_address&lt;/em&gt; object as the first argument in the &lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read.table()&lt;/code&gt;&lt;/a&gt; function. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;exp_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/read.table.html&#39;&gt;read.table&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;data_address&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;exp_data&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;    V1        V2        V3        V4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 Age Height_cm Eye_Color Graduated&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2  22    175.26      Blue      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3  67    170.18     Green      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4  53     165.1      Blue     FALSE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5  13    134.62     Brown     FALSE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6  19    147.32     Green      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 7  27    185.42      Gray      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 8  30     190.5      Blue      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 9  11    144.78     Brown     FALSE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h4 id=&#34;exercise-5-getting-info-about-functions&#34;&gt;Exercise 5: Getting Info About Functions&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;The column names (header) were read in as the first observation, and default column names (i.e. V1, V2, etc) were added. Take a look at the help page for &lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read.table()&lt;/code&gt;&lt;/a&gt; by typing &lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;?read.table&lt;/code&gt;&lt;/a&gt; in your R console, or by searching for &amp;ldquo;read.table&amp;rdquo; in the search box in the Help tab of the lower right RStudio panel. Look through some of the options/arguments and make an adjustment to fix the column names/header, then view the data frame again.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Rerun the command, setting &amp;ldquo;header&amp;rdquo; to TRUE, instead of the default FALSE. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;exp_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/read.table.html&#39;&gt;read.table&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;data_address&lt;/span&gt;, header &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;exp_data&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Age Height_cm Eye_Color Graduated&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1  22    175.26      Blue      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2  67    170.18     Green      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3  53    165.10      Blue     FALSE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4  13    134.62     Brown     FALSE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5  19    147.32     Green      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6  27    185.42      Gray      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 7  30    190.50      Blue      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 8  11    144.78     Brown     FALSE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h4 id=&#34;exercise-6-practicing-with-some-functions&#34;&gt;Exercise 6: Practicing With Some Functions&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Spend a few minutes playing around with some of the following functions and try to figure out what they do by applying them to the exp_data object. If it&amp;rsquo;s not clear, use the help&amp;hellip;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;head()&lt;/li&gt;
&lt;li&gt;dim()&lt;/li&gt;
&lt;li&gt;nrow()&lt;/li&gt;
&lt;li&gt;ncol()&lt;/li&gt;
&lt;li&gt;names()&lt;/li&gt;
&lt;li&gt;str()&lt;/li&gt;
&lt;li&gt;summary()&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;exp_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Age Height_cm Eye_Color Graduated&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1  22    175.26      Blue      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2  67    170.18     Green      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3  53    165.10      Blue     FALSE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4  13    134.62     Brown     FALSE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5  19    147.32     Green      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6  27    185.42      Gray      TRUE&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#gives preview of object&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;exp_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 8 4&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#returns dimensions (number of row, number of columns) of the object&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;exp_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 8&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#returns number of rows in data frame&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;ncol&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;exp_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#returns number of columns in data frame&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/names.html&#39;&gt;names&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;exp_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Age&#34;       &#34;Height_cm&#34; &#34;Eye_Color&#34; &#34;Graduated&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#returns vector of column names&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;exp_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &#39;data.frame&#39;:  8 obs. of  4 variables:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ Age      : int  22 67 53 13 19 27 30 11&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ Height_cm: num  175 170 165 135 147 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ Eye_Color: Factor w/ 4 levels &#34;Blue&#34;,&#34;Brown&#34;,..: 1 4 1 2 4 3 1 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ Graduated: logi  TRUE TRUE FALSE FALSE TRUE TRUE ...&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#summarizes the structure of an object&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/summary.html&#39;&gt;summary&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;exp_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;       Age          Height_cm     Eye_Color Graduated      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Min.   :11.00   Min.   :134.6   Blue :3   Mode :logical  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  1st Qu.:17.50   1st Qu.:146.7   Brown:2   FALSE:3        &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Median :24.50   Median :167.6   Gray :1   TRUE :5        &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Mean   :30.25   Mean   :164.1   Green:2                  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  3rd Qu.:35.75   3rd Qu.:177.8                            &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Max.   :67.00   Max.   :190.5&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#provides a summary/summary statistics for individual variables/columns &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h2 id=&#34;7----r-packages&#34;&gt;7 &amp;ndash; R Packages&lt;/h2&gt;
&lt;p&gt;I mentioned above when talking about functions that many have already been written for you, and some are available as soon as you open up R - those that are considered part of &amp;ldquo;base R&amp;rdquo;. All the functions we&amp;rsquo;ve used up to this point are included in that set. But there are lots of other functions available as part of additional packages you can install and load. The two most common places to get packages are the CRAN and Bioconductor repositories - I did a couple short videos on these as part of &lt;a href=&#34;https://youtube.com/playlist?list=PLxhIMi78eQegFm3XqsylVa-Lm7nfiUshe&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this Intro To R Playlist&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;As one example, we used the function &lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read.table()&lt;/code&gt;&lt;/a&gt; above to read in the example dataset. A similar function, &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_tsv()&lt;/code&gt;&lt;/a&gt; is available as part of the &lt;em&gt;readr&lt;/em&gt; package, which is available from CRAN, and so can be installed with the &lt;a href=&#34;https://rdrr.io/r/utils/install.packages.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;install.packages()&lt;/code&gt;&lt;/a&gt; function&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;readr&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The installation should only have to be done once. Then we use the &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; function to load the library in each R session where we want to use it&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org&#39;&gt;readr&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: package &#39;readr&#39; was built under R version 3.6.2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now we should have access to the readr package and all of the functions contained in it.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;exp_data2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://readr.tidyverse.org/reference/read_delim.html&#39;&gt;read_tsv&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;data_address&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;──&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;font-weight: bold;&#39;&gt;Column specification&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #00BBBB;&#39;&gt;────────────────────────────────────────────────────────&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; cols(&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Age = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Height_cm = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Eye_Color = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Graduated = &lt;span style=&#39;color: #BBBB00;&#39;&gt;col_logical()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; )&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;exp_data2&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 8 x 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     Age Height_cm Eye_Color Graduated&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;lgl&amp;gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt;    22      175. Blue      TRUE     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt;    67      170. Green     TRUE     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt;    53      165. Blue      FALSE    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt;    13      135. Brown     FALSE    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt;    19      147. Green     TRUE     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt;    27      185. Gray      TRUE     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;7&lt;/span&gt;&lt;span&gt;    30      190. Blue      TRUE     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;8&lt;/span&gt;&lt;span&gt;    11      145. Brown     FALSE&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You might notice that &lt;em&gt;exp_data2&lt;/em&gt; is a tibble, while &lt;em&gt;exp_data&lt;/em&gt; is a data frame (try the &lt;a href=&#34;https://rdrr.io/r/base/class.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;class()&lt;/code&gt;&lt;/a&gt; function on each). This small difference in the types of objects that are returned is one of the differences in the functions &lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read.table()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_tsv()&lt;/code&gt;&lt;/a&gt;. While the class of the objects is different, the contents of the objects are the same.&lt;/p&gt;
&lt;p&gt;In addition to functions like &lt;a href=&#34;https://rdrr.io/r/utils/install.packages.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;install.packages()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; that help you manage packages in R, RStudio also provides some point-and-click ways to do these same things. Check out the &lt;em&gt;packages&lt;/em&gt; tab in the bottom-right RStudio panel.&lt;/p&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-breakout-rooms-iii-10-min&#34;&gt;Bonus: Breakout Rooms III (~10 min.)&lt;/h3&gt;
&lt;h5 id=&#34;exercise-7-reading-in-compressed-data&#34;&gt;Exercise 7: Reading In Compressed Data&lt;/h5&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Let&amp;rsquo;s look at one more example for a bit more practice with packages and reading data in to R. This time, we&amp;rsquo;ll try reading in a compressed (gzipped) version of the same example dataset. This one&amp;rsquo;s available from&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/biodash/biodash.github.io/raw/master/assets/data/data_frame/example_df.tsv.gz&#34;&gt;https://github.com/biodash/biodash.github.io/raw/master/assets/data/data_frame/example_df.tsv.gz&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s read this dataset in as an object named &lt;em&gt;zip_data&lt;/em&gt;. First try using the &lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read.table()&lt;/code&gt;&lt;/a&gt; function just like before.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;Try replacing the previous address with the updated address for the compressed file. Remember to set the header argument to TRUE.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#create an object storing the web address&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;zip_address&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://github.com/biodash/biodash.github.io/raw/master/assets/data/data_frame/example_df.tsv.gz&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;zip_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/read.table.html&#39;&gt;read.table&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;zip_address&lt;/span&gt;, header &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;p&gt;&lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read.table()&lt;/code&gt;&lt;/a&gt; isn&amp;rsquo;t able to uncompress a file directly from online, so you probably got an error message. However, it can automatically uncompress a file when reading it in locally (from your computer). So, see if you can use the &lt;a href=&#34;https://rdrr.io/r/utils/download.file.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;download.file()&lt;/code&gt;&lt;/a&gt; function to get the compressed file and then read it in in a second step.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hint&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;a href=&#34;https://rdrr.io/r/utils/download.file.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;download.file()&lt;/code&gt;&lt;/a&gt; requires that two arguments are defined: &lt;em&gt;url&lt;/em&gt; and &lt;em&gt;destfile&lt;/em&gt;. Check &lt;a href=&#34;https://rdrr.io/r/utils/download.file.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;?download.file&lt;/code&gt;&lt;/a&gt; for details.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;zip_address&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;example_zip_file.tsv.gz&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;zip_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/read.table.html&#39;&gt;read.table&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;example_zip_file.tsv.gz&#34;&lt;/span&gt;, header &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;p&gt;Alternatively, you could install the &lt;em&gt;data.table&lt;/em&gt; package and try its &lt;a href=&#34;https://Rdatatable.gitlab.io/data.table/reference/fread.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fread()&lt;/code&gt;&lt;/a&gt; function, which is able to download and automatically uncompress a file from online all in one step (though doing so requires another package, &lt;em&gt;R.utils&lt;/em&gt;, so you&amp;rsquo;ll also have to get that one first if you don&amp;rsquo;t already have it)&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;R.utils&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;data.table&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/HenrikBengtsson/R.utils&#39;&gt;R.utils&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://r-datatable.com&#39;&gt;data.table&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;data.table&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://Rdatatable.gitlab.io/data.table/reference/fread.html&#39;&gt;fread&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;zip_address&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;    Age Height_cm Eye_Color Graduated&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1:  22    175.26      Blue      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2:  67    170.18     Green      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3:  53    165.10      Blue     FALSE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4:  13    134.62     Brown     FALSE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5:  19    147.32     Green      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6:  27    185.42      Gray      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 7:  30    190.50      Blue      TRUE&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 8:  11    144.78     Brown     FALSE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Not only does this offer a little more practice with objects, functions, and reading in data, but it also provides one small example of the value in having multiple functions available that do similar things. In this specific case, when reading in data directly from online, you might find &lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read.table()&lt;/code&gt;&lt;/a&gt; to be a little easier to work with if the data are uncompressed, but &lt;a href=&#34;https://Rdatatable.gitlab.io/data.table/reference/fread.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;fread()&lt;/code&gt;&lt;/a&gt; might make things a bit easier (one less step) if the file is compressed. And we actually saw a third function, &lt;a href=&#34;https://readr.tidyverse.org/reference/read_delim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read_tsv()&lt;/code&gt;&lt;/a&gt; earlier (from the &lt;em&gt;readr&lt;/em&gt; package), which offers yet another option for reading in data-frame-like data. This kind of thing is common in R - there are typically multiple ways of doing things, and as you work in R, you&amp;rsquo;ll continue to pick up more and more efficient ways of doing what you want to do.&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Code Club S02E01:
An introduction to R (Part 1)
</title>
      <link>https://biodash.github.io/codeclub/s02e01_r-intro-part1/</link>
      <pubDate>Tue, 17 Aug 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s02e01_r-intro-part1/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;h2 id=&#34;learning-objectives&#34;&gt;Learning objectives&lt;/h2&gt;
&lt;blockquote&gt;
&lt;ul&gt;
&lt;li&gt;Learn what Code Club is all about&lt;/li&gt;
&lt;li&gt;Get some basic familiarity with R and RStudio&lt;/li&gt;
&lt;li&gt;Understand a bit about R &lt;em&gt;objects&lt;/em&gt; and how to use them&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;to-do-beforehand&#34;&gt;To do beforehand&lt;/h2&gt;
&lt;p&gt;Before the Code Club Zoom session, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions.&lt;/p&gt;
&lt;p&gt;In brief, you should have R and RStudio installed on your computer &lt;em&gt;or&lt;/em&gt; you should be set up to run RStudio Server at the Ohio Supercomputer Center (OSC). (As a bonus, you can try to install and load the &lt;em&gt;tidyverse&lt;/em&gt; package as the setup page suggests, but no sweat if you can&amp;rsquo;t get that to work yet.)&lt;/p&gt;
&lt;p&gt;In case you run into issues, contact &lt;a href=&#34;mailto:poelstra.1@osu.edu&#34;&gt;Jelmer&lt;/a&gt; or for last-minute troubleshooting, you can join the Zoom call 15-30 minutes early.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;reintroducing-code-club&#34;&gt;(Re)Introducing Code Club&lt;/h2&gt;
&lt;p&gt;OSU Code Club is a regularly occurring online gathering to improve coding skills, now in its second year.&lt;/p&gt;
&lt;p&gt;This Code Club was inspired by a paper in PLoS Computational Biology (&lt;a href=&#34;https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1008119&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&amp;ldquo;Ten simple rules to increase computational skills among biologists with Code Clubs&amp;rdquo;&lt;/a&gt;), and here are some of the underlying ideas:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Coding is best learned by doing, so Code Club is interactive and hands-on.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;Ongoing&lt;/em&gt; exposure and practice also helps when learning.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We aim to keep it informal and maybe even fun.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We have a core group of 5 organizers that do most of the presenting, but we also encourage participants to present, and will have a couple of participant-led sessions at the end of this semester (see the &lt;a href=&#34;https://biodash.github.io/codeclub-schedule/&#34;&gt;schedule&lt;/a&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;organizers&#34;&gt;Organizers&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Jelmer Poelstra (Molecular and Cellular Imaging Center (MCIC), Wooster Campus)&lt;/li&gt;
&lt;li&gt;Jessica Cooperstone (Dept. of Horticulture and Crop Science &amp;amp; Dept. of Food Science and Technology)&lt;/li&gt;
&lt;li&gt;Michael Broe (Dept. of Evolution, Ecology and Organismal Biology)&lt;/li&gt;
&lt;li&gt;Mike Sovic (Center for Applied Plant Sciences)&lt;/li&gt;
&lt;li&gt;Stephen Opiyo (MCIC, Columbus Campus)&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;session-structure&#34;&gt;Session structure&lt;/h4&gt;
&lt;p&gt;Each session consists of an instructional part where you can code along or listen, some exercises in breakout rooms with 3-4 people, and exercise recaps with the entire group.&lt;/p&gt;
&lt;h4 id=&#34;zoom-guidelines&#34;&gt;Zoom guidelines&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;We very much welcome questions at any time, so please either unmute yourself and speak, or post in the chat whenever you have a question!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Having your camera on helps, &lt;em&gt;especially&lt;/em&gt; in breakout rooms. We will record the whole-group part of each session, so we understand if some of you prefer to have their cameras off during that part. (But note that we will only share the recordings with other Code Clubbers.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can use the icons under the &amp;ldquo;Participants&amp;rdquo; menu in Zoom when we ask for a &amp;ldquo;show of hands&amp;rdquo; or if you are having problems.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In breakout rooms:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Briefly introduce yourselves.&lt;/li&gt;
&lt;li&gt;Have someone share their screen, preferably one of the least experienced people.&lt;/li&gt;
&lt;li&gt;Be friendly and patient, keep everyone aboard.&lt;/li&gt;
&lt;li&gt;The Zoom &lt;code&gt;Ask for help&lt;/code&gt; button will alert us, and one of the organizers will come into the breakout room. (&lt;code&gt;Raise hand&lt;/code&gt; is not seen by us outside of the room.)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;otherwise&#34;&gt;Otherwise&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;We need your feedback! Always feel free to email one of the organizers, and for suggestions for a topic to cover in a future Code Club, you can fill out &lt;a href=&#34;https://biodash.github.io/codeclub-suggest/&#34;&gt;this form&lt;/a&gt;!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I will quickly show the Code Club menu and BioDASH website during the session.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Zoom polling question: are you working at OSC or locally?&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1----why-r&#34;&gt;1 &amp;ndash; Why R?&lt;/h2&gt;
&lt;p&gt;R is a programming language that is most well-known for being excellent for &lt;em&gt;statistical analysis&lt;/em&gt; and &lt;em&gt;data visualization&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;While the learning curve is steeper than for most programs with graphical user interfaces (GUIs), it pays off to invest in learning R:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;R gives you greater &lt;strong&gt;flexibility&lt;/strong&gt; to do anything you want.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Writing computer instructions as &lt;em&gt;code&lt;/em&gt;, like you have to do in R, is more &lt;strong&gt;reproducible&lt;/strong&gt; than clicking around in a GUI. It also makes it much &lt;em&gt;easier to redo analyses&lt;/em&gt; with slight modifications!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;R is highly &lt;strong&gt;interdisciplinary&lt;/strong&gt; and can be used with many different kinds of data. To just name two examples, R has a very strong ecosystem for bioinformatics analysis (&amp;ldquo;Bioconductor&amp;rdquo; project), and can be used to create maps and perform GIS analyses.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;R is more than a platform to perform analysis and create figures. &lt;strong&gt;R Markdown&lt;/strong&gt; combines R with a simple text markup language to produce &lt;em&gt;analysis reports&lt;/em&gt; that integrate code, results, and text, and to create &lt;em&gt;slide decks&lt;/em&gt;, &lt;em&gt;data dashboards&lt;/em&gt;, &lt;em&gt;websites&lt;/em&gt;, and even &lt;em&gt;books&lt;/em&gt;! In the third session of Code Club, Michael Broe will talk more about R Markdown.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;While not as versatile outside of data-focused topics as a language like Python, R can be used as a general programming language, for instance to &lt;strong&gt;automate tasks&lt;/strong&gt; such as large-scale file renaming.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Finally, R:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Is open-source and freely available for all platforms (Windows, Mac, Linux).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Has a large and welcoming user community.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2----exploring-rstudio&#34;&gt;2 &amp;ndash; Exploring RStudio&lt;/h2&gt;
&lt;p&gt;R simply provides a &amp;ldquo;&lt;em&gt;console&lt;/em&gt;&amp;rdquo; (command-line interface) where you can type your commands.&lt;/p&gt;
&lt;p&gt;However, because you want to save your commands in scripts and see the graphics that you produce, it is more effective to work in an environment that provides all of this side-by-side. We will use RStudio, an excellent &lt;em&gt;graphical environment&lt;/em&gt; (&amp;ldquo;Integrated Development Environment&amp;rdquo;, IDE) for R.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;I will now demonstrate how to start an RStudio Server session from the Ohio Supercomputer Center&amp;rsquo;s website following the steps from our &lt;a href=&#34;https://biodash.github.io/codeclub-setup/#osc-run-rstudio&#34;&gt;Code Club Computer Setup page&lt;/a&gt;.&lt;/em&gt; &lt;em&gt;If you have RStudio installed on your own computer, start it now, and otherwise, follow along with me to run RStudio in your browser.&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Once you have a running instance of RStudio, &lt;strong&gt;create a new R script&lt;/strong&gt; by clicking &lt;code&gt;File&lt;/code&gt; &amp;gt; &lt;code&gt;New File&lt;/code&gt; &amp;gt; &lt;code&gt;R Script&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now, you should see all 4 &amp;ldquo;panes&amp;rdquo; that the RStudio window is divided into:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;em&gt;Top-left&lt;/em&gt;: The &lt;strong&gt;Editor&lt;/strong&gt; for your scripts and other documents (&lt;em&gt;hidden when no file is open&lt;/em&gt;).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Bottom-left&lt;/em&gt;: The &lt;strong&gt;R Console&lt;/strong&gt; to interactively run your code (+ a tab with a &lt;strong&gt;Terminal&lt;/strong&gt;).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Top-right&lt;/em&gt;: Your &lt;strong&gt;Environment&lt;/strong&gt; with R objects you have created (+ several other tabs).&lt;/li&gt;
&lt;li&gt;&lt;em&gt;Bottom-left&lt;/em&gt;: Tabs for &lt;strong&gt;Files&lt;/strong&gt;, &lt;strong&gt;Plots&lt;/strong&gt;, &lt;strong&gt;Help&lt;/strong&gt;, and others.&lt;/li&gt;
&lt;/ul&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/rstudio-layout-ed.png width=&#34;95%&#34;&gt;
&lt;/p&gt;
&lt;p&gt;So, in RStudio, we have a single interface to write code in text files or directly in the console, visualize plots, navigate the files found on our computer, and inspect the data we are working with.&lt;/p&gt;
&lt;p&gt;RStudio has a lot of useful features and during the next few sessions of Code Club, we will introduce some tips and tricks for working with it.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-i-5-min&#34;&gt;Breakout rooms I (~5 min.)&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;introduce-yourselves&#34;&gt;Introduce yourselves!&lt;/h4&gt;
&lt;p&gt;We&amp;rsquo;ll return to the same breakout room configuration later in this session to do a few exercises, so please take a moment to introduce yourself to your breakout roommates. Make sure to also mention:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Your level of experience with R and other coding languages.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What you are aiming to use or are already using R for.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;h4 id=&#34;check-that-everyone-has-rstudio-working&#34;&gt;Check that everyone has RStudio working&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Take a moment to explore the RStudio interface.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you run into issues, click the &lt;code&gt;Ask for help&lt;/code&gt; button in Zoom and one of us will come by.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;br&gt;
&lt;h2 id=&#34;3----interacting-with-r&#34;&gt;3 &amp;ndash; Interacting with R&lt;/h2&gt;
&lt;h4 id=&#34;r-as-a-calculator&#34;&gt;R as a calculator&lt;/h4&gt;
&lt;p&gt;The lower-left RStudio pane, i.e. &lt;strong&gt;the R console&lt;/strong&gt;, is where you can interact with R directly.&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; sign is the R &amp;ldquo;prompt&amp;rdquo;. It indicates that R is ready for you to type something.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s start by performing a division:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;m&#39;&gt;203&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2.54&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 79.92126&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;R does the calculation and prints the result in the console as well. Afterwards, you get your &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; prompt back. (The &lt;code&gt;[1]&lt;/code&gt; may look a bit weird when there is only one output element; this is how you can keep count of output elements when there are many.)&lt;/p&gt;
&lt;p&gt;With the expected set of symbols, you can use R as a general calculator:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;m&#39;&gt;203&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2.54&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Multiplication&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 515.62&lt;/span&gt;
&lt;span class=&#39;m&#39;&gt;203&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2.54&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Addition&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 205.54&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note that pressing the &lt;em&gt;up arrow&lt;/em&gt; key will put your previous command back on the prompt, and you can press the &lt;em&gt;up arrow&lt;/em&gt; again to go further back (as well as the &lt;em&gt;down arrow&lt;/em&gt; to go in the other direction).&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;experimenting-a-bit&#34;&gt;Experimenting a bit&amp;hellip;&lt;/h4&gt;
&lt;p&gt;What if we add spaces around our values?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;         &lt;span class=&#39;m&#39;&gt;203&lt;/span&gt;                     &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2.54&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 200.46&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This works: as it turns out, R simply ignores any extra spaces.&lt;/p&gt;
&lt;p&gt;Similarly, we &lt;em&gt;could&lt;/em&gt; omit the single spaces around the mathematical operators that we used earlier (though we will keep using them for clarity):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;m&#39;&gt;203&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;/&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2.54&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 79.92126&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;How about:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;203 /&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now the &lt;em&gt;prompt&lt;/em&gt; turned into a &lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;+&lt;/code&gt;&lt;/a&gt; instead of the usual &lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;What is going on here?&lt;/b&gt; (Click for the answer)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;R is waiting for you to finish the command, since you typed an incomplete command: something has to follow the division sign &lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;/&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;While it was obvious here that our command was incomplete, you will often type incomplete commands without realizing you did so. Just remember that when you see the &lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;+&lt;/code&gt;&lt;/a&gt; prompt, &lt;em&gt;something&lt;/em&gt; has to be missing in your command: most commonly, you&amp;rsquo;ll have forgotten a closing parenthesis &lt;code&gt;)&lt;/code&gt; or you accidentally opened up an unwanted opening parenthesis &lt;code&gt;(&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you want to &lt;em&gt;abort&lt;/em&gt; completing the incomplete command, you can press &lt;kbd&gt;Esc&lt;/kbd&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;p&gt;And if we just type a number:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;m&#39;&gt;203&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 203&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;R will print the number back to us! It turns out that the default, implicit action that R will perform on anything you type is to print it back to us (under the hood, it is calling a &lt;em&gt;function&lt;/em&gt; called &lt;a href=&#34;https://rdrr.io/r/base/print.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;print()&lt;/code&gt;&lt;/a&gt;).&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;Instead of a number, what if we try to have R print some &lt;em&gt;text&lt;/em&gt; (a character string) back to us?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;Fantastic&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error in eval(expr, envir, enclos): object &#39;Fantastic&#39; not found&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;Code Club
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error: &amp;lt;text&amp;gt;:1:6: unexpected symbol&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1: Code Club&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;          ^&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;What seems to be going wrong here?&lt;/b&gt; (Click for the answer)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Whenever you type a character string, R expects to find an &lt;em&gt;object&lt;/em&gt; with that name (we will get to what exactly objects are in a little bit!). When no object exists with that name, R will throw an error. We will learn some of the basics of objects in section 5 of today&amp;rsquo;s session.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;p&gt;We &lt;em&gt;can&lt;/em&gt; get R to print character strings back to us, and work with strings in other ways, as long as we quote them:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;s&#39;&gt;&#34;Fantastic&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Fantastic&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4----working-with-a-script&#34;&gt;4 &amp;ndash; Working with a script&lt;/h2&gt;
&lt;h4 id=&#34;need-for-scripts&#34;&gt;Need for scripts&lt;/h4&gt;
&lt;p&gt;We can go along like this, typing commands directly into the R console. But to keep better track of what we&amp;rsquo;re doing, it&amp;rsquo;s a good idea to write code in plain text files, i.e. to write &amp;ldquo;&lt;strong&gt;scripts&lt;/strong&gt;&amp;rdquo;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You should have already created a script above (otherwise, click &lt;code&gt;File&lt;/code&gt; &amp;gt; &lt;code&gt;New File&lt;/code&gt; &amp;gt; &lt;code&gt;R Script&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;code&gt;File&lt;/code&gt; &amp;gt; &lt;code&gt;Save As&lt;/code&gt; to save the script; give it a descriptive name like &lt;code&gt;intro-to-R.R&lt;/code&gt;.&lt;br&gt;
(You may want to put the script in a new subfolder for this Code Club session.)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;h4 id=&#34;interacting-with-the-r-console-from-your-script&#34;&gt;Interacting with the R console from your script&lt;/h4&gt;
&lt;p&gt;We recommend that you generally &lt;em&gt;type your commands into a script&lt;/em&gt; and execute the commands from there, instead of typing directly into the console.&lt;/p&gt;
&lt;p&gt;We want to make sure to save our division command, so start by typing the following into the R script in the top-left pane:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;m&#39;&gt;203&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2.54&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;With the cursor still on this line, press &lt;kbd&gt;Ctrl&lt;/kbd&gt; + &lt;kbd&gt;Enter&lt;/kbd&gt;. The command will be copied to the R console and executed, and then the cursor will move to the next line.&lt;/p&gt;
&lt;p&gt;Note that it doesn&amp;rsquo;t matter where on the line your cursor is: &lt;kbd&gt;Ctrl&lt;/kbd&gt; + &lt;kbd&gt;Enter&lt;/kbd&gt; will execute the entire line unless you have selected only part of it.&lt;/p&gt;
&lt;p&gt;(And when you have selected multiple lines of code, &lt;kbd&gt;Ctrl&lt;/kbd&gt; + &lt;kbd&gt;Enter&lt;/kbd&gt; will execute them all.)&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;commenting&#34;&gt;Commenting&lt;/h4&gt;
&lt;p&gt;You can use &lt;code&gt;#&lt;/code&gt; signs to annotate (comment) your code. Anything to the right of a &lt;code&gt;#&lt;/code&gt; is ignored by R, meaning it won&amp;rsquo;t be executed. You can use &lt;code&gt;#&lt;/code&gt; both at the start of a line or anywhere in a line following code.&lt;/p&gt;
&lt;p&gt;Comments are a great way to describe what your code does within the code itself, so comment liberally in your R scripts! This is useful not only for others that you may share your code with, but perhaps especially for yourself when you look back at your code a day, a month, or a year later.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Divide by 2.54 to get the wingspan in inches:&lt;/span&gt;
&lt;span class=&#39;m&#39;&gt;203&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2.54&lt;/span&gt;    &lt;span class=&#39;c&#39;&gt;# Original measurement was in cm&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;5----r-objects&#34;&gt;5 &amp;ndash; R Objects&lt;/h2&gt;
&lt;h4 id=&#34;assigning-stuff-to-r-objects&#34;&gt;Assigning stuff to R objects&lt;/h4&gt;
&lt;p&gt;We can assign any value, character, or set of values or characters to an &lt;em&gt;object&lt;/em&gt; with the assignment operator, &lt;a href=&#34;https://rdrr.io/r/base/assignOps.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;lt;-&lt;/code&gt;&lt;/a&gt;. (This is a smaller-than sign &lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/a&gt; followed by a dash &lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;-&lt;/code&gt;&lt;/a&gt;.)&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;wingspan_cm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;203&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;conversion&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2.54&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Type that into your script, and use &lt;kbd&gt;Ctrl&lt;/kbd&gt; + &lt;kbd&gt;Enter&lt;/kbd&gt; to send it to the console.&lt;/p&gt;
&lt;p&gt;The objects you create get added to your &amp;ldquo;workspace&amp;rdquo; or &amp;ldquo;environment.&amp;rdquo; RStudio shows this in the &lt;strong&gt;Environment tab&lt;/strong&gt; in the topright panel &amp;ndash; check to see if &lt;code&gt;wingspan_cm&lt;/code&gt; and &lt;code&gt;conversion&lt;/code&gt; are indeed there.&lt;/p&gt;
&lt;p&gt;After you&amp;rsquo;ve assigned a number to an object, you can use it in other calculations:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;wingspan_inch&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;wingspan_cm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;conversion&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;wingspan_inch&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 79.92126&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;More generally speaking, the object name that you provide is substituted with its contents by R, so the object name is just a &lt;em&gt;reference&lt;/em&gt; to the underlying value.&lt;/p&gt;
&lt;p&gt;Our objects so far contained just a single number and we may have also called them &lt;em&gt;variables&lt;/em&gt;. Object is the more general name that encompasses R items of any size or complexity. As we see will see next week, R distinguishes between different &lt;em&gt;types&lt;/em&gt; of objects.&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;object-names&#34;&gt;Object names&lt;/h4&gt;
&lt;p&gt;Objects can be given any name such as &lt;code&gt;x&lt;/code&gt;, &lt;code&gt;current_temperature&lt;/code&gt;, or &lt;code&gt;subject_id&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Some pointers on object names:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Because R is case sensitive, &lt;code&gt;wingspan_inch&lt;/code&gt; is different from &lt;code&gt;Wingspan_inch&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;An object name cannot contain a space, so for readability, separate words using:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;_&lt;/code&gt;&lt;/strong&gt; &amp;ndash; e.g. &lt;code&gt;wingspan_inch&lt;/code&gt; (this is called &amp;ldquo;snake case&amp;rdquo;, which we will tend to use in Code Club instructional materials)&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;.&lt;/code&gt;&lt;/strong&gt; &amp;ndash; e.g. &lt;code&gt;wingspan.inch&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;em&gt;capitalization&lt;/em&gt; &amp;ndash; e.g. &lt;code&gt;wingspanInch&lt;/code&gt; or &lt;code&gt;WingspanInch&lt;/code&gt; (&amp;ldquo;camel case&amp;rdquo;)&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Object names can contain but cannot start with a number (&lt;code&gt;2x&lt;/code&gt; is not valid, but &lt;code&gt;x2&lt;/code&gt; is)&lt;sup id=&#34;fnref:2&#34;&gt;&lt;a href=&#34;#fn:2&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;2&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Make object names descriptive yet not too long.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You will make things easier for yourself by naming objects in a consistent way, for instance by always sticking to your favorite case like &amp;ldquo;snake case.&amp;quot;&lt;sup id=&#34;fnref:3&#34;&gt;&lt;a href=&#34;#fn:3&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;3&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;objects-your-workspace-and-closing-r&#34;&gt;Objects, your workspace, and closing R&lt;/h4&gt;
&lt;p&gt;When you close R, it will probably ask you whether you want to save your workspace (&lt;em&gt;&amp;ldquo;Save workspace image to ~/.RData&amp;rdquo;&lt;/em&gt;). When you do so, then the next time you start R, you can reload everything the way it was, such as your previously created objects.&lt;/p&gt;
&lt;p&gt;While this may seem convenient, we recommend that you don&amp;rsquo;t do this.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Can you think of a reason why saving and reloading your workspace may not be a good idea?&lt;/b&gt; (Click for the answer)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;The main reason why this is generally not considered good practice relates to the idea that you should be able to &lt;em&gt;reproduce your workspace (and more broadly speaking, your analysis) from the code in your script&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Remember that you can modify your workspace either by entering commands in the console directly, or by running them from a script &amp;ndash; or even from multiple different scripts. Also, in practice, you often run lines in the script out of order, or write lines in the script that you don&amp;rsquo;t execute.&lt;/p&gt;
&lt;p&gt;Therefore, if you &amp;ldquo;carry around&amp;rdquo; the same workspace across multiple different sessions, you run a greater risk of not having a reproducible set of steps in your script.&lt;/p&gt;
&lt;p&gt;To make RStudio stop asking you about saving your workspace, click &lt;code&gt;Tools&lt;/code&gt; &amp;gt; &lt;code&gt;Global Options&lt;/code&gt; &amp;gt; &lt;code&gt;General&lt;/code&gt; and set the options as follows:&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/r_environment.png width=&#34;50%&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Taking these ideas a step further, it can be a good idea to occasionally restart R so you can check whether the code in your script is correct and complete, that you are not relying on code that is not in the script, and so on. To do so, you don&amp;rsquo;t need to close and reopen RStudio itself: under &lt;code&gt;Session&lt;/code&gt; in the top menu bar, you can click &lt;code&gt;Restart R&lt;/code&gt; (and you should also see the keyboard shortcut for it in the menu bar, which is &lt;kbd&gt;Ctrl&lt;/kbd&gt; + &lt;kbd&gt;Shift&lt;/kbd&gt; + &lt;kbd&gt;F10&lt;/kbd&gt; for Windows/Linux, and &lt;kbd&gt;Cmd&lt;/kbd&gt; + &lt;kbd&gt;Shift&lt;/kbd&gt; + &lt;kbd&gt;F10&lt;/kbd&gt; for Mac).&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms-ii-5-10-min&#34;&gt;Breakout rooms II (5-10 min.)&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;Note that in both of these exercises, the answers are not contained in what we just discussed. I would like you to think about your intuition for R&amp;rsquo;s behavior, and then see if R indeed works that way or not.&lt;/em&gt;&lt;/p&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1-object-linkage&#34;&gt;Exercise 1: Object &amp;ldquo;linkage&amp;rdquo;&lt;/h3&gt;
&lt;p&gt;What do you think the value of &lt;code&gt;y&lt;/code&gt; will be after executing the following lines in R? 100 or 160, and why?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;       &lt;span class=&#39;c&#39;&gt;# x is now 50&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;    &lt;span class=&#39;c&#39;&gt;# y is now 100&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;80&lt;/span&gt;       &lt;span class=&#39;c&#39;&gt;# x is now 80, but what is y?&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Objects don&amp;rsquo;t get linked to each other, so if you change one object, it won&amp;rsquo;t affect the values of other objects that were defined earlier.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Therefore, &lt;code&gt;y&lt;/code&gt; will continue to be &lt;code&gt;100&lt;/code&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2-errors-bonus&#34;&gt;Exercise 2: Errors&amp;hellip; (Bonus)&lt;/h3&gt;
&lt;p&gt;In section 3, you might have noticed that we got a different error when typing one versus multiple unquoted words. Here are those examples again:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;Fantastic&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error in eval(expr, envir, enclos): object &#39;Fantastic&#39; not found&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;Code Club
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error: &amp;lt;text&amp;gt;:1:6: unexpected symbol&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1: Code Club&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;          ^&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Reproduce these errors for yourself: in Rstudio&amp;rsquo;s editor pane, type these or equivalent error-generating examples in a script saved with a &lt;code&gt;.R&lt;/code&gt; extension, and send them to the console.&lt;/p&gt;
&lt;p&gt;Why is the error in the second case different, and what does it mean?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Hints&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Can you see how RStudio can &amp;ldquo;notice&amp;rdquo; errors already in the editor &amp;ndash; but only for the second of these two examples? The editor checks for &lt;em&gt;syntax&lt;/em&gt; (&amp;ldquo;R grammar&amp;rdquo;) errors but not whether objects already exist.&lt;/p&gt;
&lt;figure&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/rstudio_syntax-error.png width=&#34;60%&#34;&gt;
&lt;figcaption&gt;
&lt;p&gt;If you hover over the red cross in the margin, you can see what RStudio is upset about.&lt;/p&gt;
&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What if we put a &lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;+&lt;/code&gt;&lt;/a&gt; or another operator between the two words?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;Code&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Club&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error in eval(expr, envir, enclos): object &#39;Code&#39; not found&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
&lt;b&gt;Solution&lt;/b&gt; (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;When typing a single unquoted word which is not an existing object, R will look for an object and then complain that it can&amp;rsquo;t find that object.&lt;/p&gt;
&lt;p&gt;When typing multiple unquoted words with a space between them, regardless of whether those are existing objects, R will notice a &lt;em&gt;syntax (&amp;ldquo;R grammar&amp;rdquo;) error&lt;/em&gt; before it even gets around to checking objects.&lt;/p&gt;
&lt;p&gt;The problem is that you are referring to two objects sequentially and without any mathematical operator in between them, or some other syntax to &amp;ldquo;join&amp;rdquo; them. In R, that&amp;rsquo;s not valid syntax. (You may think it would perhaps simply try to print both objects, but this is not the case.)&lt;/p&gt;
&lt;/details&gt;
&lt;p&gt;A general lesson here is that you should always pay attention to the details of the error messages that you get. While the language may seem terse and odd at first, it usually holds important clues as to what is going wrong exactly.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;in-closing&#34;&gt;In closing&lt;/h2&gt;
&lt;h4 id=&#34;where-to-go-from-here&#34;&gt;Where to go from here&lt;/h4&gt;
&lt;p&gt;For a list of recommended resources for learning R, see our &lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/&#34;&gt;R Resources and Tips page&lt;/a&gt; page.&lt;/p&gt;
&lt;h4 id=&#34;attribution&#34;&gt;Attribution&lt;/h4&gt;
&lt;p&gt;This was modified after material from &lt;a href=&#34;https://carpentries.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;The Carpentries&lt;/a&gt;, especially from &lt;a href=&#34;http://uw-madison-aci.github.io/2016-06-01-uwmadison/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this Data Carpentry workshop&lt;/a&gt; and &lt;a href=&#34;https://datacarpentry.org/R-ecology-lesson&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this &amp;ldquo;R for Ecology&amp;rdquo; workshop&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;In RStudio, typing &lt;kbd&gt;Alt&lt;/kbd&gt; + &lt;kbd&gt;-&lt;/kbd&gt; will write &lt;a href=&#34;https://rdrr.io/r/base/assignOps.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;lt;-&lt;/code&gt;&lt;/a&gt; in a single keystroke. You can also use &lt;a href=&#34;https://rdrr.io/r/base/assignOps.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;=&lt;/code&gt;&lt;/a&gt; as assignment, but that symbol can have other meanings, so we recommend sticking with the &lt;a href=&#34;https://rdrr.io/r/base/assignOps.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;lt;-&lt;/code&gt;&lt;/a&gt; combination. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:2&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;There are some names that cannot be used because they are the names of fundamental keywords in R (e.g., &lt;code&gt;if&lt;/code&gt;, &lt;code&gt;else&lt;/code&gt;, &lt;code&gt;for&lt;/code&gt;, see &lt;a href=&#34;https://stat.ethz.ch/R-manual/R-devel/library/base/html/Reserved.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt; for a complete list). In general, it&amp;rsquo;s best not to use other function names even if it&amp;rsquo;s &amp;ldquo;allowed&amp;rdquo; (e.g., &lt;code&gt;c&lt;/code&gt;, &lt;code&gt;T&lt;/code&gt;, &lt;code&gt;mean&lt;/code&gt;, &lt;code&gt;data&lt;/code&gt;, &lt;code&gt;df&lt;/code&gt;, &lt;code&gt;weights&lt;/code&gt;). If in doubt, check the Help to see if the name is already in use. &lt;a href=&#34;#fnref:2&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li id=&#34;fn:3&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;It is also recommended to use &lt;em&gt;nouns&lt;/em&gt; for variable names, and &lt;em&gt;verbs&lt;/em&gt; for function names. For more, two popular R style guides are &lt;a href=&#34;http://adv-r.had.co.nz/Style.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Hadley Wickham&amp;rsquo;s&lt;/a&gt; and &lt;a href=&#34;https://google.github.io/styleguide/Rguide.xml&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Google&amp;rsquo;s&lt;/a&gt;. &lt;a href=&#34;#fnref:3&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>R Resources and Tips</title>
      <link>https://biodash.github.io/tutorials/r-resources-tips/</link>
      <pubDate>Tue, 17 Aug 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/tutorials/r-resources-tips/</guid>
      <description>&lt;hr&gt;
&lt;br&gt;
&lt;h2 id=&#34;resources-to-get-started-with-r&#34;&gt;Resources to get started with R&lt;/h2&gt;
&lt;h3 id=&#34;the-basics&#34;&gt;The basics&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e01_r-intro-part1/&#34;&gt;Code Club S02E01: Intro to R &amp;ndash; part 1&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e02_r-intro_part2/&#34;&gt;Code Club S02E02: Intro to R &amp;ndash; part 2&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://www.youtube.com/playlist?list=PLxhIMi78eQegFm3XqsylVa-Lm7nfiUshe&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Mike Sovic&amp;rsquo;s Youtube playlist of short videos on R&lt;/a&gt;:&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
  &lt;iframe src=&#34;https://www.youtube.com/embed/ByxF3xjN2JQ&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; allowfullscreen title=&#34;YouTube Video&#34;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;br&gt;
&lt;h3 id=&#34;lengthier-material&#34;&gt;Lengthier material&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://kingaa.github.io/R_Tutorial/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;A Tutorial Introduction to R&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The Carpentries have a number of great lessons on R, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://datacarpentry.org/R-ecology-lesson&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Data Analysis and Visualization in R for Ecologists&lt;/a&gt;,
which includes data wrangling with &lt;em&gt;tidyverse&lt;/em&gt; packages and plotting with &lt;em&gt;ggplot2&lt;/em&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://swcarpentry.github.io/r-novice-gapminder/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R for Reproducible Scientific Analysis&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you prefer material structured as a course, excellent free ones include
the &lt;a href=&#34;https://www.edx.org/course/data-science-r-basics&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R Basics&lt;/a&gt;
and &lt;a href=&#34;https://www.edx.org/course/data-science-visualization&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Visualization&lt;/a&gt; courses
by Rafael Irizarry (you do have to create an EdX account for access).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you prefer a book, we would recommend Wickham &amp;amp; Grolemund&amp;rsquo;s
&amp;ldquo;R for Data Science&amp;rdquo;, which is freely available on the web in a really nice format
&lt;a href=&#34;https://r4ds.had.co.nz/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;why-r&#34;&gt;Why R?&lt;/h3&gt;
&lt;p&gt;R is a programming language that is most well-known
for being excellent for &lt;em&gt;statistical analysis&lt;/em&gt; and &lt;em&gt;data visualization&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;While the learning curve is steeper than for most programs with graphical user
interfaces (GUIs), it pays off to invest in learning R:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;R gives you greater &lt;strong&gt;flexibility&lt;/strong&gt; to do anything you want.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Writing computer instructions as &lt;em&gt;code&lt;/em&gt;, like you have to do in R,
is more &lt;strong&gt;reproducible&lt;/strong&gt; than clicking around in a GUI.
It also makes it much &lt;em&gt;easier to redo analyses&lt;/em&gt; with slight modifications!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;R is highly &lt;strong&gt;interdisciplinary&lt;/strong&gt; and can be used with many different kinds of data.
To just name two examples,
R has a very strong ecosystem for bioinformatics analysis (&amp;ldquo;Bioconductor&amp;rdquo; project),
and can be used to create maps and perform GIS analyses.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;R is more than a platform to perform analysis and create figures.
&lt;strong&gt;R Markdown&lt;/strong&gt; combines R with a simple text markup language
to produce &lt;em&gt;analysis reports&lt;/em&gt; that integrate code, results, and text,
and to create &lt;em&gt;slide decks&lt;/em&gt;, &lt;em&gt;data dashboards&lt;/em&gt;, &lt;em&gt;websites&lt;/em&gt;, and even &lt;em&gt;books&lt;/em&gt;!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;While not as versatile outside of data-focused topics as a language like Python,
R can be used as a general programming language,
for instance to &lt;strong&gt;automate tasks&lt;/strong&gt; such as large-scale file renaming.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Finally, R:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Is open-source and freely available for all platforms (Windows, Mac, Linux).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Has a large and welcoming user community.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;miscellaneous-r-tips&#34;&gt;Miscellaneous R tips&lt;/h2&gt;
&lt;h3 id=&#34;installing-r-packages&#34;&gt;Installing R packages&lt;/h3&gt;
&lt;h4 id=&#34;cran-packages&#34;&gt;CRAN packages&lt;/h4&gt;
&lt;p&gt;To install an R package that is available at &lt;a href=&#34;https://cran.r-project.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CRAN&lt;/a&gt;,
the default R package repository,
from within R (e.g. in the R console in RStudio), use the &lt;code&gt;install.packages()&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;install.packages()&lt;/code&gt; function will handle dependencies within R &amp;ndash; i.e., it will install other R packages
that your package depends on. Occasionally, when the install function needs to compile
a package from source, errors arise that relate to missing system dependencies (i.e. software outside of R).&lt;/p&gt;
&lt;p&gt;On &lt;strong&gt;Mac&lt;/strong&gt; and &lt;strong&gt;Linux&lt;/strong&gt;, these system dependencies are best installed outside of R,
such as with &lt;code&gt;homebrew&lt;/code&gt; on Mac or &lt;code&gt;apt&lt;/code&gt; on Ubuntu.
The error message you got when trying to install an R package should tell you which system dependencies are needed.&lt;/p&gt;
&lt;p&gt;On Windows, you can use the &lt;code&gt;installr&lt;/code&gt; package to install such dependencies or other software from within R &amp;ndash; for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;installr&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;    &lt;span class=&#34;c1&#34;&gt;# Install the installr package first&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;installlr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;install.RStudio&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;    &lt;span class=&#34;c1&#34;&gt;# Install RStudio&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;installr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;install.python&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;      &lt;span class=&#34;c1&#34;&gt;# Install Python&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;
&lt;h4 id=&#34;system-setup-to-installing-packages-from-source&#34;&gt;System setup to installing packages &amp;ldquo;from source&amp;rdquo;&lt;/h4&gt;
&lt;p&gt;Sometimes you need to install a package from source, that is,
you need to compile the package rather than simply installing a pre-existing binary.
(On &lt;strong&gt;Linux&lt;/strong&gt;, where installing from source is often needed, this should work without additional steps.)
On &lt;strong&gt;Windows&lt;/strong&gt; and &lt;strong&gt;Mac&lt;/strong&gt;, installing from source is generally only needed when you
install a package from outside of CRAN (such as from Github, see below),
&lt;em&gt;but&lt;/em&gt; you will need to make sure you have the following non-R software:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;On &lt;strong&gt;Windows&lt;/strong&gt;, you will need &lt;em&gt;Rtools&lt;/em&gt; (&lt;a href=&#34;http://cran.r-project.org/bin/windows/Rtools/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Rtools installation instructions&lt;/a&gt;).&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;On a Mac, you will need &lt;em&gt;Xcode&lt;/em&gt; (which can be installed from the Mac App store).&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can test whether or not you are able to install packages from source using the &lt;em&gt;devtools&lt;/em&gt; package:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;devtools&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;    &lt;span class=&#34;c1&#34;&gt;# Install the devtools package&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;devtools&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;has_devel&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;           &lt;span class=&#34;c1&#34;&gt;# Check whether you can install packages from source&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For a bit more info, see &lt;a href=&#34;https://rstats.wtf/set-up-an-r-dev-environment.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this page&lt;/a&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;installing-packages-from-github&#34;&gt;Installing packages from GitHub&lt;/h4&gt;
&lt;p&gt;To install a package from GitHub, use either the &lt;em&gt;devtools&lt;/em&gt; or the &lt;em&gt;remotes&lt;/em&gt; package &amp;ndash; for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;remotes&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;                &lt;span class=&#34;c1&#34;&gt;# Install the remotes package&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;remotes&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;install_github&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;kbroman/broman&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Install from a repository using &amp;#34;&amp;lt;username&amp;gt;/&amp;lt;repo-name&amp;gt;&amp;#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will install the package &lt;em&gt;from source&lt;/em&gt;, so you will need to make sure you are able to do so
by following the instructions in the section right above this one.&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;installing-packages-from-bioconductor&#34;&gt;Installing packages from Bioconductor&lt;/h4&gt;
&lt;p&gt;If you&amp;rsquo;re doing bioinformatic analyses in R, you will probably run into packages
that are not on CRAN but on &lt;a href=&#34;https://bioconductor.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Bioconductor&lt;/a&gt;.
To install a package from Bioconductor, use the &lt;em&gt;BiocManager&lt;/em&gt; package &amp;ndash; for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;BiocManager&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Install the BiocManager package&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;BiocManager&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;install&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;edgeR&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;    &lt;span class=&#34;c1&#34;&gt;# Install the edgeR package from Bioconductor&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;updating-r&#34;&gt;Updating R&lt;/h3&gt;
&lt;p&gt;Consider updating R if you have an older version of R installed &amp;ndash;
as of June 2022, the current version is &lt;code&gt;R 4.2&lt;/code&gt; and we would certainly recommend
updating R if the version is below &lt;code&gt;R 4.0&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;You can check which version of R you have by looking at the first line of
output when running the following command inside R:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;sessionInfo&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;to-update&#34;&gt;To update:&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Windows&lt;/strong&gt;: You can update R from within R. The &lt;code&gt;updateR()&lt;/code&gt; function will also take care
of updating your packages:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;installr&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;installr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;updateR&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If this doesn&amp;rsquo;t work, &lt;a href=&#34;https://cloud.r-project.org/bin/windows/base/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;download the Windows R installer&lt;/a&gt;
as if you were installing it for the first time.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Mac&lt;/strong&gt;: &lt;a href=&#34;https://cloud.r-project.org/bin/macosx/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Download and install the latest &lt;code&gt;.pkg&lt;/code&gt; file&lt;/a&gt;
as if you were installing it for the first time.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Linux&lt;/strong&gt;: In Ubuntu, if you installed R with &lt;code&gt;apt&lt;/code&gt; or &lt;code&gt;apt-get&lt;/code&gt;,
you can use &lt;code&gt;apt-get upgrade&lt;/code&gt; in a terminal.
Otherwise, &lt;a href=&#34;https://cloud.r-project.org/bin/linux/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;download and install the latest version&lt;/a&gt;
after removing the old one.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;h4 id=&#34;re-installing-your-packages-after-updating-mac-and-linux&#34;&gt;Re-installing your packages after updating (Mac and Linux)&lt;/h4&gt;
&lt;p&gt;While the &lt;code&gt;installr::updateR()&lt;/code&gt; function for &lt;strong&gt;Windows&lt;/strong&gt; users takes care of
re-installing your packages along with updating R,
&lt;strong&gt;Mac&lt;/strong&gt; and &lt;strong&gt;Linux&lt;/strong&gt; users will have to manually re-install their packages.
Some people prefer to re-install these packages on the fly, which can end up being a way
to get rid of packages you no longer use.&lt;/p&gt;
&lt;p&gt;But if you want immediately re-install all your packages, run this before you upgrade:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;my_packages&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;installed.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;saveRDS&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;my_packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;my_packages.rds&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, after you&amp;rsquo;ve installed the latest R version:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;my_packages&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;readRDS&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;CurrentPackages.rds&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;my_packages[1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will only work for packages available on CRAN. Of course, you can check your list
for Github-only and Bioconductor packages and then install those with their respective commands
(see below). Yes, this can be a bit of a hassle!&lt;/p&gt;
&lt;p&gt;&lt;br/&gt; &lt;br/&gt; &lt;br/&gt;&lt;/p&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Session 20: Cleaning up variables names, and other wrangling</title>
      <link>https://biodash.github.io/codeclub/20_cleaning-up/</link>
      <pubDate>Fri, 30 Apr 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/20_cleaning-up/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;prep-homework&#34;&gt;Prep homework&lt;/h2&gt;
&lt;h3 id=&#34;basic-computer-setup&#34;&gt;Basic computer setup&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/04_ggplot2/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll help you troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can use R locally, or at OSC. You can find instructions if you are having trouble &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;getting-started&#34;&gt;Getting Started&lt;/h2&gt;
&lt;h3 id=&#34;rmarkdown-for-todays-session&#34;&gt;RMarkdown for today&amp;rsquo;s session&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# directory for Code Club Session 20:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S20&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# directory for our RMarkdown&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# (&#34;recursive&#34; to create two levels at once.)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S20/Rmd/&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# save the url location for today&#39;s script&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;todays_Rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/20_cleaning-up/CleaningUp.Rmd&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# indicate the name of the new script file&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;Session20_Rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;S20/Rmd/CleaningUp.Rmd&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# go get that file! &lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;todays_Rmd&lt;/span&gt;,
              destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Session20_Rmd&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---using-regexs-for-wrangling&#34;&gt;1 - Using regexs for wrangling&lt;/h2&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=bakers_5.png width=&#34;95%&#34; alt=&#34;cute little monsters making cupcakes and enjoying R&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Artwork by &lt;a href=&#34;https://github.com/allisonhorst/stats-illustrations&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Now that we have gone through a mini-series on regular expressions, with the &lt;a href=&#34;https://biodash.github.io/codeclub/17_regex/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;basics&lt;/a&gt;, some &lt;a href=&#34;https://biodash.github.io/codeclub/18_regex2/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;next level helpers&lt;/a&gt;, and &lt;a href=&#34;https://biodash.github.io/codeclub/19_wordclouds/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;using tidytext to make word clouds&lt;/a&gt;, I thought I&amp;rsquo;d talk today about some applications of this information to cleaning up your data.&lt;/p&gt;
&lt;p&gt;To do this, we are going to practice with the &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;palmerpenguins&lt;/code&gt;&lt;/a&gt; dataset, and get back to the &lt;a href=&#34;https://bakeoff.netlify.app/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;bakeoff&lt;/code&gt;&lt;/a&gt; for our practice exercises.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2---accessing-our-data&#34;&gt;2 - Accessing our data&lt;/h2&gt;
&lt;p&gt;First load your libraries. We will be using &lt;code&gt;stringr&lt;/code&gt; and &lt;code&gt;tidyr&lt;/code&gt; but those are both part of core &lt;code&gt;tidyverse&lt;/code&gt;. We are also using a new package today called &lt;code&gt;janitor&lt;/code&gt; which helps you &amp;ldquo;clean up&amp;rdquo; your data.&lt;/p&gt;
&lt;p&gt;If you don&amp;rsquo;t have the package &lt;code&gt;janitor&lt;/code&gt;, please install it.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;janitor&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/sfirke/janitor&#39;&gt;janitor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for cleaning up column names&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for penguins data&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://bakeoff.netlify.com&#39;&gt;bakeoff&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for bakeoff data&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then we will use the package &lt;code&gt;palmerpenguins&lt;/code&gt; and the dataset &lt;code&gt;penguins_raw&lt;/code&gt;, which has a bit more info than &lt;code&gt;penguins&lt;/code&gt;, which we have used previously.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=palmerpenguins.png width=&#34;50%&#34; alt=&#34;hex sticker for the palmer penguins package, including 3 really cute penguins&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Artwork by &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/articles/art.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3---variable-names&#34;&gt;3 - Variable names&lt;/h2&gt;
&lt;p&gt;There are many instances where you may have variables names and/or sample names that are messy. For example, variable names that include characters like white spaces, special characters like symbols, or begin with a number are going to give you problems with some R coding. I&amp;rsquo;ll say that you &lt;em&gt;can&lt;/em&gt; have these non-standard variable names, but occasionally they will give you a big headache and so I&amp;rsquo;d recommend to just avoid them.&lt;/p&gt;
&lt;p&gt;R variable &amp;ldquo;rules&amp;rdquo;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;can contain letters, numbers, underscores (&lt;code&gt;_&lt;/code&gt;) and periods (&lt;code&gt;.&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;cannot start with a number or underscore&lt;/li&gt;
&lt;li&gt;shouldn&amp;rsquo;t be a &amp;ldquo;reserved&amp;rdquo; word, like if, else, function, TRUE, FALSE etc. (if you want to see them all, execute &lt;a href=&#34;https://rdrr.io/r/base/Reserved.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;?reserved&lt;/code&gt;&lt;/a&gt; in your console)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can read about the &lt;a href=&#34;https://style.tidyverse.org/syntax.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;tidyverse style guide&lt;/a&gt; if you want to learn more.&lt;/p&gt;
&lt;p&gt;Lets look at the variable names in &lt;code&gt;penguins_raw&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_raw&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 344&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 17&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ studyName             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;PAL0708&#34;, &#34;PAL0708&#34;, &#34;PAL0708&#34;, &#34;PAL0708&#34;, &#34;PAL…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ `Sample Number`       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 1…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Species               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Adelie Penguin (Pygoscelis adeliae)&#34;, &#34;Adelie P…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Region                &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Anvers&#34;, &#34;Anvers&#34;, &#34;Anvers&#34;, &#34;Anvers&#34;, &#34;Anvers&#34;…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Island                &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Torgersen&#34;, &#34;Torgersen&#34;, &#34;Torgersen&#34;, &#34;Torgerse…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Stage                 &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Adult, 1 Egg Stage&#34;, &#34;Adult, 1 Egg Stage&#34;, &#34;Adu…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ `Individual ID`       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;N1A1&#34;, &#34;N1A2&#34;, &#34;N2A1&#34;, &#34;N2A2&#34;, &#34;N3A1&#34;, &#34;N3A2&#34;, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ `Clutch Completion`   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Yes&#34;, &#34;Yes&#34;, &#34;Yes&#34;, &#34;Yes&#34;, &#34;Yes&#34;, &#34;Yes&#34;, &#34;No&#34;, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ `Date Egg`            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;date&amp;gt;&lt;/span&gt; 2007-11-11, 2007-11-11, 2007-11-16, 2007-11-16,…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ `Culmen Length (mm)`  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ `Culmen Depth (mm)`   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ `Flipper Length (mm)` &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190,…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ `Body Mass (g)`       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 34…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Sex                   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;MALE&#34;, &#34;FEMALE&#34;, &#34;FEMALE&#34;, NA, &#34;FEMALE&#34;, &#34;MALE&#34;…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ `Delta 15 N (o/oo)`   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; NA, 8.94956, 8.36821, NA, 8.76651, 8.66496, 9.18…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ `Delta 13 C (o/oo)`   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; NA, -24.69454, -25.33302, NA, -25.32426, -25.298…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Comments              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Not enough blood for isotopes.&#34;, NA, NA, &#34;Adult…&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What you can see is that there are variable names here that don&amp;rsquo;t comply with the &amp;ldquo;rules&amp;rdquo; I just indicated. How can that be?! You can see for the variable &lt;code&gt;Sample Number&lt;/code&gt; that it is surrounded by backticks. This is how R know that this is a variable name.&lt;/p&gt;
&lt;p&gt;Okay, so who cares? If you want to call that particular variable, you will have to put it in backticks. For example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;# this doesn&#39;t work
penguins_raw %&gt;%
  select(Sample Number)&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# this works but is clunky&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_raw&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;`Sample Number`&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 344 × 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    `Sample Number`&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;               1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;               2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;               3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;               4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;               5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;               6&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;               7&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;               8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;               9&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;              10&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 334 more rows&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And, this is using &lt;code&gt;tidyverse&lt;/code&gt; functions - there will be other situations where you will get non-solvable errors because of your variable names.&lt;/p&gt;
&lt;br&gt;
&lt;p&gt;&lt;strong&gt;tl;dr just make your variable names R compliant, there are lots of other harder things you&amp;rsquo;re going to be doing with coding, so just make this easier for yourself.&lt;/strong&gt;&lt;/p&gt;
&lt;br&gt;
&lt;h3 id=&#34;using-clean_names&#34;&gt;Using &lt;code&gt;clean_names()&lt;/code&gt;&lt;/h3&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=janitor_clean_names.png width=&#34;95%&#34; alt=&#34;cute illustration of the function clean_names, with a little beaker feeding messy data into something that looks like a planar, and better column names coming out the other side&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Artwork by &lt;a href=&#34;https://github.com/allisonhorst/stats-illustrations&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You may be thinking now, okay but what happens if someone else gives me data that has unclean variable names?&lt;/p&gt;
&lt;p&gt;Don&amp;rsquo;t worry too much, you can easily fix it. My favorite, and the simplest way to do this is using the package &lt;code&gt;janitor&lt;/code&gt;, and the function &lt;a href=&#34;https://www.rdocumentation.org/packages/janitor/versions/1.2.0/topics/clean_names&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;clean_names()&lt;/code&gt;&lt;/a&gt;. Certainly you could clean your variable names manually, but why? This is really easy.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_clean&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/janitor/man/clean_names.html&#39;&gt;clean_names&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_raw&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_clean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 344&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 17&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ study_name        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;PAL0708&#34;, &#34;PAL0708&#34;, &#34;PAL0708&#34;, &#34;PAL0708&#34;, &#34;PAL0708…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sample_number     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 1…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Adelie Penguin (Pygoscelis adeliae)&#34;, &#34;Adelie Pengu…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ region            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Anvers&#34;, &#34;Anvers&#34;, &#34;Anvers&#34;, &#34;Anvers&#34;, &#34;Anvers&#34;, &#34;A…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ island            &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Torgersen&#34;, &#34;Torgersen&#34;, &#34;Torgersen&#34;, &#34;Torgersen&#34;, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ stage             &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Adult, 1 Egg Stage&#34;, &#34;Adult, 1 Egg Stage&#34;, &#34;Adult, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ individual_id     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;N1A1&#34;, &#34;N1A2&#34;, &#34;N2A1&#34;, &#34;N2A2&#34;, &#34;N3A1&#34;, &#34;N3A2&#34;, &#34;N4A…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ clutch_completion &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Yes&#34;, &#34;Yes&#34;, &#34;Yes&#34;, &#34;Yes&#34;, &#34;Yes&#34;, &#34;Yes&#34;, &#34;No&#34;, &#34;No&#34;…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ date_egg          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;date&amp;gt;&lt;/span&gt; 2007-11-11, 2007-11-11, 2007-11-16, 2007-11-16, 200…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ culmen_length_mm  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ culmen_depth_mm   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ flipper_length_mm &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 186…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ body_mass_g       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sex               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;MALE&#34;, &#34;FEMALE&#34;, &#34;FEMALE&#34;, NA, &#34;FEMALE&#34;, &#34;MALE&#34;, &#34;F…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ delta_15_n_o_oo   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; NA, 8.94956, 8.36821, NA, 8.76651, 8.66496, 9.18718,…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ delta_13_c_o_oo   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; NA, -24.69454, -25.33302, NA, -25.32426, -25.29805, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ comments          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &#34;Not enough blood for isotopes.&#34;, NA, NA, &#34;Adult not…&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can see that &lt;code&gt;Sample Number&lt;/code&gt; became &lt;code&gt;sample_number&lt;/code&gt;, &lt;code&gt;Culmen Length (mm)&lt;/code&gt; became &lt;code&gt;culmen_length_mm&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The default is to parse with &amp;ldquo;snake&amp;rdquo; case, which would look like snake_case. You could also set the argument &lt;code&gt;case&lt;/code&gt; to:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;&amp;quot;lower_camel&amp;quot;&lt;/code&gt; or &lt;code&gt;&amp;quot;small_camel&amp;quot;&lt;/code&gt; to get lowerCamel&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;quot;upper_camel&amp;quot;&lt;/code&gt; or &lt;code&gt;&amp;quot;big_camel&amp;quot;&lt;/code&gt; to get UpperCamel&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;quot;screaming_snake&amp;quot;&lt;/code&gt; or &lt;code&gt;&amp;quot;all_caps&amp;quot;&lt;/code&gt; to get SCREAMING_SNAKE (stop yelling please)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;quot;lower_upper&amp;quot;&lt;/code&gt; to get lowerUPPER (I don&amp;rsquo;t know why you&amp;rsquo;d want this)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;&amp;quot;upper_lower&amp;quot;&lt;/code&gt; to get UPPERlower (I also don&amp;rsquo;t know why you&amp;rsquo;d want this)&lt;/li&gt;
&lt;/ul&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=coding_cases.png width=&#34;95%&#34; alt=&#34;an illustration showing a camel, and the differences between camel, kebab, snake, and other useful cases&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Artwork by &lt;a href=&#34;https://github.com/allisonhorst/stats-illustrations&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4---unite-character-columns&#34;&gt;4 - Unite character columns&lt;/h2&gt;
&lt;p&gt;There will be times when you&amp;rsquo;d like to take a variable, and combine it with another variable. For example, you might want a column called &lt;code&gt;region_island&lt;/code&gt; which contains a combination of the &lt;code&gt;region&lt;/code&gt; and &lt;code&gt;island&lt;/code&gt; that each penguin is from. We can do this with the function &lt;a href=&#34;https://tidyr.tidyverse.org/reference/unite.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;unite()&lt;/code&gt;&lt;/a&gt;. The function &lt;code&gt;unite()&lt;/code&gt; allows you to paste together multiple columns to become one column.&lt;/p&gt;
&lt;p&gt;The arguments to &lt;code&gt;unite&lt;/code&gt; work like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;unite(data, col, ..., sep = &amp;quot;_&amp;quot;, remove = TRUE, na.rm = FALSE)&lt;/code&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_clean_unite&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_clean&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;unite&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;col &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;region_island&#34;&lt;/span&gt;, 
        &lt;span class=&#39;nv&#39;&gt;region&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# indicate the columns to unite&lt;/span&gt;
        remove &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# don&#39;t remove region and island&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Did it work?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_clean_unite&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 18&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   study_name sample_number species         region_island  region island stage   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; PAL0708                1 Adelie Penguin… Anvers_Torger… Anvers Torge… Adult, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; PAL0708                2 Adelie Penguin… Anvers_Torger… Anvers Torge… Adult, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; PAL0708                3 Adelie Penguin… Anvers_Torger… Anvers Torge… Adult, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; PAL0708                4 Adelie Penguin… Anvers_Torger… Anvers Torge… Adult, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; PAL0708                5 Adelie Penguin… Anvers_Torger… Anvers Torge… Adult, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; PAL0708                6 Adelie Penguin… Anvers_Torger… Anvers Torge… Adult, …&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 11 more variables: individual_id &amp;lt;chr&amp;gt;, clutch_completion &amp;lt;chr&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   date_egg &amp;lt;date&amp;gt;, culmen_length_mm &amp;lt;dbl&amp;gt;, culmen_depth_mm &amp;lt;dbl&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   flipper_length_mm &amp;lt;dbl&amp;gt;, body_mass_g &amp;lt;dbl&amp;gt;, sex &amp;lt;chr&amp;gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   delta_15_n_o_oo &amp;lt;dbl&amp;gt;, delta_13_c_o_oo &amp;lt;dbl&amp;gt;, comments &amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This is a silly example since there is only one region, but I think you can see how this function is used.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;5---separate-character-columns&#34;&gt;5 - Separate character columns&lt;/h2&gt;
&lt;p&gt;There will be times that you have a column that has two variables embedded within it, and you will want to separate or parse the column to become two separate columns. You can do this with the function &lt;a href=&#34;https://tidyr.tidyverse.org/reference/separate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;separate()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;The arguments to separate look like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;separate(data, col, into, sep = &amp;quot;yourregex&amp;quot;, remove = TRUE, extra = &amp;quot;warn&amp;quot;, fill = &amp;quot;warn&amp;quot;)&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s look at the column &lt;code&gt;stage&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_clean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;stage&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Adult, 1 Egg Stage&#34; &#34;Adult, 1 Egg Stage&#34; &#34;Adult, 1 Egg Stage&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [4] &#34;Adult, 1 Egg Stage&#34; &#34;Adult, 1 Egg Stage&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We might want to separate the column &lt;code&gt;stage&lt;/code&gt; into &lt;code&gt;age&lt;/code&gt; and &lt;code&gt;egg_stage&lt;/code&gt;. We can do this with &lt;code&gt;separate()&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_clean_stage&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_clean&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;separate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;col &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;stage&lt;/span&gt;,
           into &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;age&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;egg_stage&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
           sep &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;,&#34;&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# the comma is the separator&lt;/span&gt;
           remove &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Did it work?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_clean_stage&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;stage&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;age&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;egg_stage&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   stage              age   egg_stage     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;              &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;         &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adult, 1 Egg Stage Adult &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt; 1 Egg Stage&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Adult, 1 Egg Stage Adult &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt; 1 Egg Stage&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Adult, 1 Egg Stage Adult &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt; 1 Egg Stage&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Adult, 1 Egg Stage Adult &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt; 1 Egg Stage&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Adult, 1 Egg Stage Adult &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt; 1 Egg Stage&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Adult, 1 Egg Stage Adult &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt; 1 Egg Stage&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;6---extract-character-columns&#34;&gt;6 - Extract character columns&lt;/h2&gt;
&lt;p&gt;We can use &lt;a href=&#34;https://tidyr.tidyverse.org/reference/extract.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;extract()&lt;/code&gt;&lt;/a&gt; to set up regular expressions to allow the separation of our variable &lt;code&gt;species&lt;/code&gt; into a column with the common name, and a column with the genus species.&lt;/p&gt;
&lt;p&gt;We will use str_view to figure out a regex that will work for us.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# indicate our string&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;string&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Adelie Penguin (Pygoscelis adeliae)&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# to get Adelie Penguin&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\w+\\s\\w+&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;adelie_penguin_1.png&#34; width=&#34;60%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;\\w&lt;/code&gt; gives you anything that&amp;rsquo;s a word character&lt;/li&gt;
&lt;li&gt;the &lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;+&lt;/code&gt;&lt;/a&gt; indicates to match alphanumeric at least 1 time&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\\s&lt;/code&gt; indicates a space&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# to get Pygoscelis adeliae&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;(?&amp;lt;=\\()\\w+\\s\\w+&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;pygoscelis_adeliae_2.png&#34; width=&#34;60%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;(?&amp;lt;=)&lt;/code&gt; is called the positive lookbehind, and has this general structure &lt;code&gt;(?&amp;lt;=B)A&lt;/code&gt; which can be read like &amp;ldquo;find exprssion A which is preceeded by expression B.&amp;rdquo; In our example, expression B is a parentheses &lt;code&gt;(&lt;/code&gt;. But there is some additional complexity here because parentheses have their own meanings in regex so you need to use the &lt;code&gt;\\&lt;/code&gt; to escape them. The whole expression for this part of our regex is &lt;code&gt;(?&amp;lt;=\\()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\\w&lt;/code&gt; gives you anything that&amp;rsquo;s a word character&lt;/li&gt;
&lt;li&gt;the &lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;+&lt;/code&gt;&lt;/a&gt; indicates to match alphanumeric at least 1 time&lt;/li&gt;
&lt;li&gt;&lt;code&gt;\\s&lt;/code&gt; indicates a space&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Ok our regexs work as desired! Now we can incorporate them into &lt;code&gt;extract()&lt;/code&gt;. Here I am using &lt;code&gt;.*?&lt;/code&gt; to match the characters between our two targeted regex which here is &lt;code&gt;(&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_clean_extract&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_clean&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;extract&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;col &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
          into &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;common_name&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;genus_species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
          regex &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;(\\w+\\s\\w+).*?((?&amp;lt;=\\()\\w+\\s\\w+)&#34;&lt;/span&gt;, 
          remove &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_clean_extract&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;common_name&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;genus_species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species                             common_name    genus_species     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                               &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;          &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;             &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; Adelie Penguin (Pygoscelis adeliae) Adelie Penguin Pygoscelis adeliae&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; Adelie Penguin (Pygoscelis adeliae) Adelie Penguin Pygoscelis adeliae&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; Adelie Penguin (Pygoscelis adeliae) Adelie Penguin Pygoscelis adeliae&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; Adelie Penguin (Pygoscelis adeliae) Adelie Penguin Pygoscelis adeliae&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; Adelie Penguin (Pygoscelis adeliae) Adelie Penguin Pygoscelis adeliae&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; Adelie Penguin (Pygoscelis adeliae) Adelie Penguin Pygoscelis adeliae&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Voila!&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;7---replacing-with-str_replace&#34;&gt;7 - Replacing with &lt;code&gt;str_replace()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;The column &lt;code&gt;individual_id&lt;/code&gt; has two parts: the letter N and then a number, and the letter A and then a number. Let&amp;rsquo;s split this column into two columns, one called &lt;code&gt;id_n&lt;/code&gt; that contains the number after the N, and a second called &lt;code&gt;id_a&lt;/code&gt; that contains the number after the A.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_clean_fixID&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_clean&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;separate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;col &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;individual_id&lt;/span&gt;,
           into &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;id_n&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;id_a&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
           sep &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;A&#34;&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# can also use regex &#34;[A]&#34;&lt;/span&gt;
           remove &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Did it work?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_clean_fixID&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;individual_id&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;id_n&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;id_a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   individual_id id_n  id_a &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; N1A1          N1    1    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; N1A2          N1    2    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; N2A1          N2    1    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; N2A2          N2    2    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; N3A1          N3    1    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; N3A2          N3    2&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This worked to separate out the A, but the N is still linked with &lt;code&gt;id_n&lt;/code&gt;. We can use a combination of &lt;code&gt;mutate()&lt;/code&gt; and &lt;code&gt;str_replace_all()&lt;/code&gt; to remove the N. You can learn more about &lt;code&gt;str_replace()&lt;/code&gt; &lt;a href=&#34;https://stringr.tidyverse.org/reference/str_replace.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_clean_fixID&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_clean_fixID&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;id_n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;str_replace_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;id_n&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;N&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_clean_fixID&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;individual_id&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;id_n&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;id_a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   individual_id id_n  id_a &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;         &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; N1A1          1     1    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; N1A2          1     2    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; N2A1          2     1    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; N2A2          2     2    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; N3A1          3     1    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; N3A2          3     2&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;exercises&#34;&gt;Exercises&lt;/h2&gt;
&lt;p&gt;We will be doing our exercises today with a couple of datasets from the &lt;code&gt;bakeoff&lt;/code&gt; package.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=mel_and_sue.gif width=&#34;95%&#34; alt=&#34;mel and sue from GBBO are super excited about jaffa cakes&#34;&gt;
&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Using the dataset &lt;code&gt;bakers&lt;/code&gt;, combine &lt;code&gt;bakers_last&lt;/code&gt; with &lt;code&gt;bakers_first&lt;/code&gt; to create a new column &lt;code&gt;bakers_last_first&lt;/code&gt; which is indicated like this: Lastname, Firstname.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
Use [`head()`](https://rdrr.io/r/utils/head.html) or `glimpse()` to see the structure of this data. Use `unite()` to combine columns. Don&#39;t forget to indicate the correct `sep` &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   series baker_full   baker    age occupation   hometown  baker_last baker_first&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Annetha Mi… Annet…    30 Midwife      Essex     Mills      Annetha    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;David Cham… David     31 Entrepreneur Milton K… Chambers   David      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Edward \&#34;E… Edd       24 Debt collec… Bradford  Kimber     Edward     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Jasminder … Jasmi…    45 Assistant C… Birmingh… Randhawa   Jasminder  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Jonathan S… Jonat…    25 Research An… St Albans Shepherd   Jonathan   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Lea Harris&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt; Lea       51 Retired      Midlothi… Harris     Lea&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bakers_2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;unite&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;col &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;bakers_last_first&#34;&lt;/span&gt;,
        &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;baker_last&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;baker_first&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
        sep &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;, &#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# did it work?&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakers_2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   series baker_full              baker       age occupation hometown bakers_last_fir…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;                   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;           &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Annetha Mills&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;         Annetha      30 Midwife    Essex    Mills, Annetha  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;David Chambers&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;        David        31 Entrepren… Milton … Chambers, David &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Edward \&#34;Edd\&#34; Kimber&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt; Edd          24 Debt coll… Bradford Kimber, Edward  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Jasminder Randhawa&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;    Jasminder    45 Assistant… Birming… Randhawa, Jasmi…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Jonathan Shepherd&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;     Jonathan     25 Research … St Alba… Shepherd, Jonat…&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Lea Harris&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;            Lea          51 Retired    Midloth… Harris, Lea&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Using the dataset &lt;code&gt;bakers&lt;/code&gt;, convert the column &lt;code&gt;hometown&lt;/code&gt; to two columns, where whatever comes before the comma is in a column called &lt;code&gt;city&lt;/code&gt; and whatever comes after is in a column called &lt;code&gt;locale&lt;/code&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
Try using `separate()`. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   series baker_full   baker    age occupation   hometown  baker_last baker_first&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;        &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Annetha Mi… Annet…    30 Midwife      Essex     Mills      Annetha    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;David Cham… David     31 Entrepreneur Milton K… Chambers   David      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Edward \&#34;E… Edd       24 Debt collec… Bradford  Kimber     Edward     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Jasminder … Jasmi…    45 Assistant C… Birmingh… Randhawa   Jasminder  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Jonathan S… Jonat…    25 Research An… St Albans Shepherd   Jonathan   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Lea Harris&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt; Lea       51 Retired      Midlothi… Harris     Lea&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bakers_hometown&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;separate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;col &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;hometown&lt;/span&gt;,
           into &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;city&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;locale&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
           sep &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;, &#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Expected 2 pieces. Additional pieces discarded in 1 rows [71].&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Expected 2 pieces. Missing pieces filled with `NA` in 65 rows [1, 2, 3, 4, 5, 7, 8, 11, 12, 15, 19, 20, 23, 25, 27, 28, 31, 34, 38, 41, ...].&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# did it work?&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakers_hometown&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   series baker_full  baker    age occupation city  locale baker_last baker_first&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;       &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Annetha M… Annet…    30 Midwife    Essex &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;     Mills      Annetha    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;David Cha… David     31 Entrepren… Milt… &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;     Chambers   David      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Edward \&#34;… Edd       24 Debt coll… Brad… &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;     Kimber     Edward     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Jasminder… Jasmi…    45 Assistant… Birm… &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;     Randhawa   Jasminder  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Jonathan … Jonat…    25 Research … St A… &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;     Shepherd   Jonathan   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; 1      &lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;Lea Harri… Lea       51 Retired    Midl… Scotl… Harris     Lea&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Using the dataset &lt;code&gt;bakers&lt;/code&gt; add a column &lt;code&gt;nickname&lt;/code&gt; which indicates the bakers nickname, if they have one.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
Think about how to make a regex that would pull out the nickname. Try using `str_view_all()` to get your regex working before you apply it to `bakers`. Try using the lookahead syntax. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;baker_full&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;baker_full&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# note I used single quotes because there were double quotes in the regex&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;baker_full&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#39;(?&amp;lt;=\\&#34;).*(?=\\&#34;)&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;nicknames_3.png&#34; width=&#34;40%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bakers_nickname&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;extract&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;col &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;baker_full&lt;/span&gt;,
          into &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;nickname&#34;&lt;/span&gt;,
          regex &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;((?&amp;lt;=\\&#34;)\\w+(?=\\&#34;))&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bakers_nickname&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;nickname&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 × 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   series nickname baker     age occupation      hometown  baker_last baker_first&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;  &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;    &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;   &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt; &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;           &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;     &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;span style=&#39;color: #555555; font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt; 1      Edd      Edd        24 Debt collector… Bradford  Kimber     Edward     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt; 2      Jo       Joanne     41 Housewife       Ongar, E… Wheatley   Joanne     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt; 7      Val      Val        66 Semi-retired, … Yeovil    Stones     Valerie    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt; 8      Yan      Yan        46 Laboratory res… North Lo… Tsou       Chuen-Yan  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt; 1      &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;       Annetha    30 Midwife         Essex     Mills      Annetha    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt; 1      &lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;       David      31 Entrepreneur    Milton K… Chambers   David&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Using the dataset &lt;code&gt;challenge_results&lt;/code&gt;, write a regex to find any &lt;code&gt;signature&lt;/code&gt; that contains chocolate. Remove all observations that contain &lt;code&gt;NA&lt;/code&gt; for the &lt;code&gt;signature&lt;/code&gt;. How many of the signature bakes contain chocolate? What percentage of the total signature bakes (for which we have bake names) does this represent?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
You can get rid of NAs with `drop_na()`. Try using `str_count()` to see how many occurances you have of chocolate in the signatures. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# select only signatures, drop NAs&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;challenge_results&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signature&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;span class=&#39;c&#39;&gt;# check dimensions &lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 703   1&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# regex for chocolate (or Chocolate, or Chocolatey)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;str_count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;[Cc]hocolat[ey]&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning in stri_count_regex(string, pattern, opts_regex = opts(pattern)): argument is not an atomic vector; coercing&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 75&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# what percent of signatures contain chocolate&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;str_count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;[Cc]hocolat[ey]&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;/&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;*&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning in stri_count_regex(string, pattern, opts_regex = opts(pattern)): argument is not an atomic vector; coercing&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;          n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 10.66856&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Session 19: Word Clouds via Tidytext</title>
      <link>https://biodash.github.io/codeclub/19_wordclouds/</link>
      <pubDate>Wed, 21 Apr 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/19_wordclouds/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New To Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has some pointers that might be helpful if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Please open RStudio before Code Club to test things out &amp;ndash; if you run into issues, join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Learn the fundamentals of &lt;strong&gt;text mining&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Learn how to do text mining in a tidyverse setting.&lt;/li&gt;
&lt;li&gt;Reuse some of our dplyr and ggplot skills on text.&lt;/li&gt;
&lt;li&gt;Learn how to very simply create word cloud visualizations.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;setup&#34;&gt;Setup&lt;/h2&gt;
&lt;p&gt;This is another in our current series on text processing. We&amp;rsquo;ll be using the following previously used packages which you should load first (install them if you haven&amp;rsquo;t already):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://bakeoff.netlify.com&#39;&gt;bakeoff&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We&amp;rsquo;ll also be using the following packages, which you should install and load:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Uncomment the following line to install:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# install.packages(c(&#34;tidytext&#34;, &#34;gutenbergr&#34;, &#34;wordcloud&#34;))&lt;/span&gt;
                 
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/juliasilge/tidytext&#39;&gt;tidytext&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/gutenbergr/&#39;&gt;gutenbergr&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://blog.fellstat.com/?cat=11&#39;&gt;wordcloud&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;In this CodeClub session we&amp;rsquo;ll see how to create word clouds (also known as tag clouds) from text, using the &lt;strong&gt;tidytext&lt;/strong&gt; and &lt;strong&gt;wordcloud&lt;/strong&gt; packages. A word cloud is a visualization of word frequencies, graphically highlighting the most common words.&lt;/p&gt;
&lt;p&gt;We need to get some text from somewhere, so first let&amp;rsquo;s do it in the simplest possible way. Here we manually enter a quote, line by line, as a vector of five character strings. This is the first stanza from Robert Lowell&amp;rsquo;s &lt;a href=&#34;https://www.poetryfoundation.org/poems/47694/skunk-hour&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Skunk Hour&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;lowell&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Nautilus Island&#39;s hermit&#34;&lt;/span&gt;,
          &lt;span class=&#39;s&#39;&gt;&#34;heiress still lives through winter in her Spartan cottage;&#34;&lt;/span&gt;,
          &lt;span class=&#39;s&#39;&gt;&#34;her sheep still graze above the sea.&#34;&lt;/span&gt;,
          &lt;span class=&#39;s&#39;&gt;&#34;Her son&#39;s a bishop. Her farmer is first selectman in our village;&#34;&lt;/span&gt;,
          &lt;span class=&#39;s&#39;&gt;&#34;she&#39;s in her dotage.&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In textual analysis we distinguish between word &lt;strong&gt;types&lt;/strong&gt;, and word &lt;strong&gt;tokens&lt;/strong&gt; (multiple instances of those words in text). For example there are two tokens of the word-type &amp;ldquo;still&amp;rdquo; in this stanza:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;heiress &lt;code&gt;still&lt;/code&gt; lives through winter&lt;br&gt;
her sheep &lt;code&gt;still&lt;/code&gt; graze above the sea&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;And slightly more abstractly there are four tokens of &amp;ldquo;her&amp;rdquo;, modulo capitalization:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;her&lt;/code&gt; Spartan cottage&lt;br&gt;
&lt;code&gt;her&lt;/code&gt; sheep still graze&lt;br&gt;
&lt;code&gt;Her&lt;/code&gt; son&amp;rsquo;s a bishop.&lt;br&gt;
&lt;code&gt;Her&lt;/code&gt; farmer&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Formally, it&amp;rsquo;s the &lt;em&gt;token frequency&lt;/em&gt; of the &lt;em&gt;word types&lt;/em&gt; we are ultimately interested in capturing. So: two tasks, extract the word tokens, and count them! Done!&lt;/p&gt;
&lt;p&gt;The reason this is tricky is that natural language text is messy: the task of extracting a clean set of tokens to count is termed &lt;strong&gt;text mining&lt;/strong&gt; or &lt;strong&gt;tokenization&lt;/strong&gt;. We would also like to get the output into a tidyverse compliant data frame, so we can use familiar &lt;strong&gt;dplyr&lt;/strong&gt; and &lt;strong&gt;ggplot&lt;/strong&gt; functions to analyze it.&lt;/p&gt;
&lt;p&gt;We could imagine attacking this using &lt;strong&gt;stingr&lt;/strong&gt; functions:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;lowell_tokens&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lowell&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;c&#39;&gt;# convert upper to lower case; returns a character vector.&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;str_to_lower&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;# remove punctuation with a character class; returns a list.&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;str_extract_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;[a-z]+&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;c&#39;&gt;# flatten that list&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unlist.html&#39;&gt;unlist&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;# stick it in a data frame&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;as_tibble&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;                      

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;lowell_tokens&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;38&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 38 x 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    value    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; nautilus &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; island   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; s        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; hermit   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; heiress  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; still    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; lives    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; through  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; winter   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; in       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;11&lt;/span&gt;&lt;span&gt; her      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;12&lt;/span&gt;&lt;span&gt; spartan  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;13&lt;/span&gt;&lt;span&gt; cottage  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;14&lt;/span&gt;&lt;span&gt; her      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;15&lt;/span&gt;&lt;span&gt; sheep    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;16&lt;/span&gt;&lt;span&gt; still    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;17&lt;/span&gt;&lt;span&gt; graze    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;18&lt;/span&gt;&lt;span&gt; above    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;19&lt;/span&gt;&lt;span&gt; the      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;20&lt;/span&gt;&lt;span&gt; sea      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;21&lt;/span&gt;&lt;span&gt; her      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;22&lt;/span&gt;&lt;span&gt; son      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;23&lt;/span&gt;&lt;span&gt; s        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;24&lt;/span&gt;&lt;span&gt; a        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;25&lt;/span&gt;&lt;span&gt; bishop   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;26&lt;/span&gt;&lt;span&gt; her      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;27&lt;/span&gt;&lt;span&gt; farmer   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;28&lt;/span&gt;&lt;span&gt; is       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;29&lt;/span&gt;&lt;span&gt; first    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;30&lt;/span&gt;&lt;span&gt; selectman&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;31&lt;/span&gt;&lt;span&gt; in       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;32&lt;/span&gt;&lt;span&gt; our      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;33&lt;/span&gt;&lt;span&gt; village  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;34&lt;/span&gt;&lt;span&gt; she      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;35&lt;/span&gt;&lt;span&gt; s        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;36&lt;/span&gt;&lt;span&gt; in       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;37&lt;/span&gt;&lt;span&gt; her      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;38&lt;/span&gt;&lt;span&gt; dotage&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This is a good start: it gets rid of the capitalization issue, and also gets rid of the punctuation. But there&amp;rsquo;s a problem. The regular expression pattern &lt;code&gt;[a-z]+&lt;/code&gt; doesn&amp;rsquo;t recognize &lt;em&gt;possessives&lt;/em&gt; or &lt;em&gt;contractions&lt;/em&gt;: it just strips anything that&amp;rsquo;s not a letter, so it messes up with &lt;code&gt;Island&#39;s&lt;/code&gt;, &lt;code&gt;son&#39;s&lt;/code&gt;, and &lt;code&gt;she&#39;s&lt;/code&gt;: welcome to the subtleties of processing natural language text algorithmically! Exceptions, exceptions!!&lt;/p&gt;
&lt;p&gt;We could fiddle about with our regex, but&amp;hellip; &lt;em&gt;there&amp;rsquo;s a package for that!&lt;/em&gt; This kind of text mining is exactly what the &lt;a href=&#34;https://www.tidytextmining.com&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;tidytext&lt;/a&gt; package was built for. It will simultaneously strip punctuation intelligently and &amp;lsquo;unnest&amp;rsquo; lines into word tokens.&lt;/p&gt;
&lt;p&gt;Tidytext functions need a dataframe to operate on. So first we need to get the poem into a data frame; here we&amp;rsquo;ll use the column name &lt;code&gt;text&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;lowell_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;tibble&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lowell&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;lowell_df&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 5 x 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   text                                                             &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                                                            &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Nautilus Island&#39;s hermit                                         &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; heiress still lives through winter in her Spartan cottage;       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; her sheep still graze above the sea.                             &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Her son&#39;s a bishop. Her farmer is first selectman in our village;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; she&#39;s in her dotage.&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Each string in the character vector becomes a single row in the data frame.&lt;/p&gt;
&lt;p&gt;Again we want one word-token per row, to &amp;lsquo;tidy&amp;rsquo; our data. This is what &lt;a href=&#34;https://rdrr.io/pkg/tidytext/man/unnest_tokens.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tidytext::unnest_tokens()&lt;/code&gt;&lt;/a&gt; does. We&amp;rsquo;re going to unnest words in this case (we can unnest other things, like characters, sentences, regexes, even tweets) and we need to specify the variable in the dataframe we are unnesting (in this case just &lt;code&gt;text&lt;/code&gt;). This will create a new word-token data frame, and we&amp;rsquo;ll name the variable in the data frame &lt;code&gt;word&lt;/code&gt;. This is important (see later on stop words).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;lowell_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lowell_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/tidytext/man/unnest_tokens.html&#39;&gt;unnest_tokens&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;lowell_tidy&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;35&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 35 x 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    word     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; nautilus &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; island&#39;s &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; hermit   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; heiress  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; still    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; lives    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; through  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; winter   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; in       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; her      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;11&lt;/span&gt;&lt;span&gt; spartan  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;12&lt;/span&gt;&lt;span&gt; cottage  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;13&lt;/span&gt;&lt;span&gt; her      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;14&lt;/span&gt;&lt;span&gt; sheep    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;15&lt;/span&gt;&lt;span&gt; still    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;16&lt;/span&gt;&lt;span&gt; graze    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;17&lt;/span&gt;&lt;span&gt; above    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;18&lt;/span&gt;&lt;span&gt; the      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;19&lt;/span&gt;&lt;span&gt; sea      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;20&lt;/span&gt;&lt;span&gt; her      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;21&lt;/span&gt;&lt;span&gt; son&#39;s    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;22&lt;/span&gt;&lt;span&gt; a        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;23&lt;/span&gt;&lt;span&gt; bishop   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;24&lt;/span&gt;&lt;span&gt; her      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;25&lt;/span&gt;&lt;span&gt; farmer   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;26&lt;/span&gt;&lt;span&gt; is       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;27&lt;/span&gt;&lt;span&gt; first    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;28&lt;/span&gt;&lt;span&gt; selectman&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;29&lt;/span&gt;&lt;span&gt; in       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;30&lt;/span&gt;&lt;span&gt; our      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;31&lt;/span&gt;&lt;span&gt; village  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;32&lt;/span&gt;&lt;span&gt; she&#39;s    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;33&lt;/span&gt;&lt;span&gt; in       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;34&lt;/span&gt;&lt;span&gt; her      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;35&lt;/span&gt;&lt;span&gt; dotage&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Punctuation has been stripped and all words are lower case, but possessives and contractions are preserved (fancy usage of &lt;code&gt;str_&lt;/code&gt; regular expression functions under the hood&amp;hellip;).&lt;/p&gt;
&lt;h2 id=&#34;bakeoff&#34;&gt;Bakeoff!&lt;/h2&gt;
&lt;p&gt;Now that we have the basic idea, let&amp;rsquo;s look at a more interesting data set, from the &lt;code&gt;bakeoff&lt;/code&gt; package.&lt;/p&gt;
&lt;p&gt;First we&amp;rsquo;ll create a data frame with just the &lt;code&gt;signature&lt;/code&gt; column from the &lt;code&gt;bakes&lt;/code&gt; data set:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;signature_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakes&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;signature&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;signature_df&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 548 x 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    signature                                                                    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                                                                        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Light Jamaican Black Cakewith Strawberries and Cream&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;                       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Chocolate Orange Cake&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;                                                      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Caramel Cinnamon and Banana Cake&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;                                           &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Fresh Mango and Passion Fruit Hummingbird Cake&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;                             &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Carrot Cake with Lime and Cream Cheese Icing&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;                               &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Cranberry and Pistachio Cakewith Orange Flower Water Icing&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;                 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Carrot and Orange Cake&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;                                                     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Sticky Marmalade Tea Loaf&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;                                                  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Triple Layered Brownie Meringue Cake\nwith Raspberry Cream&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;                 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Three Tiered Lemon Drizzle Cakewith Fresh Cream and freshly made Lemon Curd&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 538 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Next we tokenize by word on the signature column:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;signature_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;signature_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/tidytext/man/unnest_tokens.html&#39;&gt;unnest_tokens&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;signature&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;signature_tidy&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 2,762 x 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    word        &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; light       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; jamaican    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; black       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; cakewith    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; strawberries&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; and         &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; cream       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; chocolate   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; orange      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; cake        &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 2,752 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now we want to count those tokens: i.e. we want to collapse all duplicate word tokens into a single word type, with the corresponding frequency. Since we now have tidy data, dplyr to the rescue!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;dplyr &lt;code&gt;count()&lt;/code&gt; lets you quickly count the unique values of one or more variables. The option &lt;code&gt;sort&lt;/code&gt;, if TRUE, will show the largest groups at the top.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;signature_count&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;signature_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
    &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;, sort &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;signature_count&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 806 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    word          n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; and         321&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; cake         66&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; chocolate    61&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; orange       42&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; with         42&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; pie          37&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; apple        34&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; ginger       30&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; lemon        29&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; biscuits     26&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 796 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We&amp;rsquo;re way more interested in &lt;code&gt;cake&lt;/code&gt; than &lt;code&gt;and&lt;/code&gt;: this is an example of a &lt;strong&gt;stop word&lt;/strong&gt;:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In computing, stop words are words which are filtered out before or after processing of natural language data (text). &amp;ldquo;stop words&amp;rdquo; usually refers to the most common words in a language.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;blockquote&gt;
&lt;p&gt;One of our major performance (search) optimizations&amp;hellip; is removing the top 10,000 most common English dictionary words (as determined by Google search). It&amp;rsquo;s shocking how little is left of most posts once you remove the top 10k English dictionary words&amp;hellip;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;The tidytext package has a database of just over a thousand of these words, including &amp;lsquo;and&amp;rsquo;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;stop_words&lt;/span&gt;, n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;30&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1,149 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    word        lexicon&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; a           SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; a&#39;s         SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; able        SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; about       SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; above       SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; according   SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; accordingly SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; across      SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; actually    SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; after       SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;11&lt;/span&gt;&lt;span&gt; afterwards  SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;12&lt;/span&gt;&lt;span&gt; again       SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;13&lt;/span&gt;&lt;span&gt; against     SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;14&lt;/span&gt;&lt;span&gt; ain&#39;t       SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;15&lt;/span&gt;&lt;span&gt; all         SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;16&lt;/span&gt;&lt;span&gt; allow       SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;17&lt;/span&gt;&lt;span&gt; allows      SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;18&lt;/span&gt;&lt;span&gt; almost      SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;19&lt;/span&gt;&lt;span&gt; alone       SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;20&lt;/span&gt;&lt;span&gt; along       SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;21&lt;/span&gt;&lt;span&gt; already     SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;22&lt;/span&gt;&lt;span&gt; also        SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;23&lt;/span&gt;&lt;span&gt; although    SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;24&lt;/span&gt;&lt;span&gt; always      SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;25&lt;/span&gt;&lt;span&gt; am          SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;26&lt;/span&gt;&lt;span&gt; among       SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;27&lt;/span&gt;&lt;span&gt; amongst     SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;28&lt;/span&gt;&lt;span&gt; an          SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;29&lt;/span&gt;&lt;span&gt; and         SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;30&lt;/span&gt;&lt;span&gt; another     SMART  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1,119 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note that the name of the stop word column is &lt;code&gt;word&lt;/code&gt;, and the name we used in our tokenized column is &lt;code&gt;word&lt;/code&gt; (now you will see why we used that name) so we can use dplyr&amp;rsquo;s &lt;code&gt;anti_join()&lt;/code&gt; to filter the word tokens!&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;anti_join()&lt;/code&gt; returns all rows from x without a match in y (where x are the word tokens, and y are the stop words)&lt;/p&gt;
&lt;/blockquote&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;signature_count&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;signature_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
    &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;, sort &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
    &lt;span class=&#39;nf&#39;&gt;anti_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;stop_words&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Joining, by = &#34;word&#34;&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;signature_count&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 762 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    word          n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; cake         66&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; chocolate    61&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; orange       42&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; pie          37&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; apple        34&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; ginger       30&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; lemon        29&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; biscuits     26&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; loaf         22&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; walnut       22&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 752 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Since we are in the tidyverse, we can pipe our results into ggplot. First we filter on counts above a certain threshold (here 12, just for visualization purposes):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;signature_count&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;12&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;geom_col&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This is ordered alphabetically by default, bottom to top; but we can reorder by count (n) using dplyr &lt;code&gt;mutate()&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;signature_count&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;12&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;word &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/reorder.factor.html&#39;&gt;reorder&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;geom_col&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;We now have everything we need for a word cloud: word types and their token frequencies:&lt;/p&gt;
&lt;p&gt;The only &lt;strong&gt;obligatory&lt;/strong&gt; arguments to &lt;a href=&#34;https://rdrr.io/pkg/wordcloud/man/wordcloud.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;wordcloud()&lt;/code&gt;&lt;/a&gt; are the first two: the rest just let you tweak the graphic:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/wordcloud/man/wordcloud.html&#39;&gt;wordcloud&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;words &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;signature_count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;, 
          freq &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;signature_count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt;, 
          min.freq &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;12&lt;/span&gt;, 
          random.order&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;, 
          rot.per&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0.3&lt;/span&gt;, 
          colors&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;brewer.pal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Dark2&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;min.freq&lt;/code&gt; lets you filter on a frequency threshold. &lt;code&gt;random.order=FALSE&lt;/code&gt; plots words in decreasing frequency (highest most central); &lt;code&gt;rot.per&lt;/code&gt; is the proportion of words with 90 degree rotation; &lt;code&gt;colors=brewer.pal(8, &amp;quot;Dark2&amp;quot;)&lt;/code&gt; lets you choose an &lt;a href=&#34;https://www.r-graph-gallery.com/38-rcolorbrewers-palettes.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;RColorBrewer&lt;/a&gt; color palette of your choice.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
  &lt;div&gt;
    &lt;p&gt;Lemmatization&lt;/p&gt;
&lt;p&gt;If you create a count data frame of &lt;code&gt;signature_tidy&lt;/code&gt; without the &lt;code&gt;sort = TRUE&lt;/code&gt; option, the words are sorted alphabetically. And if you look through that table you will see many instances such as &lt;code&gt;apple, apples;  apricot, apricots; cake, cakes&lt;/code&gt; etc. Arguably, these are the same word type (think &amp;ldquo;dictionary word&amp;rdquo;) just grammatical variations. Properly collapsing these into a single type is called &lt;strong&gt;lemmatization&lt;/strong&gt;: a very difficult problem which would take us far afield into the &lt;strong&gt;morphology of words&lt;/strong&gt;. Again in general there are many exceptions, only partly due to English borrowing so many words from other languages: besides &lt;code&gt;apple, apples&lt;/code&gt; there is &lt;code&gt;mouse, mice; self, selves; bacillus, bacilli; basis, bases&lt;/code&gt;. etc. These are known as &lt;a href=&#34;https://www.thoughtco.com/irregular-plural-nouns-in-english-1692634&#34;&gt;irregular plurals&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Verbs are worse! Perhaps you would also consider the inflectional forms &lt;code&gt;run, runs, ran, running&lt;/code&gt; as the same type, just as a dictionary does. How do you reduce those algorithmically? And if you consider inflectional forms as the same dictionary word, how would you tackle Ancient Greek, which has &lt;strong&gt;hundreds&lt;/strong&gt; of inflected forms for the same verb? Here are just a few, there are pages and pages of them&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;greek.jpg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;Currently machine learning has been unleashed on this problem, with limited success. The traditional computational linguists&#39; algorithms are still winning&amp;hellip;&lt;/p&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;h2 id=&#34;the-gutenbergr-package&#34;&gt;The &lt;code&gt;gutenbergr&lt;/code&gt; package&lt;/h2&gt;
&lt;p&gt;Say we wanted to do a word cloud for a more substantive text like Darwin&amp;rsquo;s &lt;em&gt;Origin of Species&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://www.gutenberg.org&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Project Gutenberg&lt;/a&gt; is a volunteer effort to digitize and archive cultural works and is the oldest digital library. It has over 60,000 books in the public domain (including Darwin&amp;rsquo;s works).&lt;/p&gt;
&lt;p&gt;The &lt;a href=&#34;https://cran.r-project.org/web/packages/gutenbergr/vignettes/intro.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;gutenbergr&lt;/a&gt; package allows you to download any of these works &lt;strong&gt;directly into a data frame&lt;/strong&gt; using just the Project Gutenberg ID. This is then perfect input for tidytext. The package provides all the metadata to search for author and work IDs inside R (you can also just find the ID by searching on the Project Gutenberg website):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;darwins_works&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gutenberg_metadata&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;author&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Darwin, Charles&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;darwins_works&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 40 x 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    gutenberg_id title author gutenberg_autho… language gutenberg_books… rights&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;             &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt;          944 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;The… Darwi…              485 en       Travel/Harvard … Publi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;227 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;The… Darwi…              485 en       &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;               Publi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;228 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;On … Darwi…              485 en       Harvard Classic… Publi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;The… Darwi…              485 en       Harvard Classic… Publi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;010 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;The… Darwi…              485 en       &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;               Publi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;087 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Lif… Darwi…              485 en       &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;               Publi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;088 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Lif… Darwi…              485 en       &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;               Publi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;300 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;The… Darwi…              485 en       &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;               Publi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;355 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;The… Darwi…              485 en       &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;               Publi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;485 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;The… Darwi…              485 en       Botany           Publi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 30 more rows, and 1 more variable: has_text &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;lgl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;An inspection of the results of &lt;em&gt;Origin of Species&lt;/em&gt; on the website reveals that the latest edition is ID 2009. Let&amp;rsquo;s grab it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;OoS&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/gutenbergr/reference/gutenberg_download.html&#39;&gt;gutenberg_download&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2009&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Determining mirror for Project Gutenberg from http://www.gutenberg.org/robot/harvest&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Using mirror http://aleph.gutenberg.org&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In the breakout rooms, we&amp;rsquo;ll work through inspecting the frequencies and creating a word cloud for this text.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;gutenbergr&lt;/code&gt; package is extremely useful, but as long as you can read a document into R, you can then convert it to a data frame as we did in the very first example above, and then the tidytext pipeline will work. The &lt;a href=&#34;https://cran.r-project.org/web/packages/readtext/vignettes/readtext_vignette.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;readtext&lt;/a&gt; package can import a variety of formats, including PDFs and Microsoft Word documents.&lt;/p&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout rooms&lt;/h2&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Run the command:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;OoS&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;gutenberg_download&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;m&#34;&gt;2009&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;and inspect the data frame. Identify the name of the column you want to tokenize.&lt;/p&gt;
&lt;p&gt;Then use the &lt;a href=&#34;https://rdrr.io/pkg/tidytext/man/unnest_tokens.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;unnest_tokens()&lt;/code&gt;&lt;/a&gt; command to create a data frame of word tokens.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;It&#39;s the &lt;code&gt;text&lt;/code&gt; column you want. &lt;code&gt;gutenbergr&lt;/code&gt; includes the &lt;code&gt;gutenberg_ID&lt;/code&gt; in case you download multiple texts into the same data frame. Remember to name the column in the new data frame &lt;code&gt;word&lt;/code&gt; so we can filter any stop words later on. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;OoS&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/gutenbergr/reference/gutenberg_download.html&#39;&gt;gutenberg_download&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2009&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;OoS&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 21,556 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    gutenberg_id text                                                            &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                                                           &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;1228    1859, First Edition&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;                                   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;22764   1860, Second Edition&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;                                  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;2009    1872, Sixth Edition, considered the definitive edition…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&#34;&lt;/span&gt;&lt;span&gt;                                                              &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&#34;&lt;/span&gt;&lt;span&gt;                                                              &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&#34;&lt;/span&gt;&lt;span&gt;                                                              &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&#34;&lt;/span&gt;&lt;span&gt;                                                              &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;On the Origin of Species&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;                                      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&#34;&lt;/span&gt;&lt;span&gt;                                                              &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;BY MEANS OF NATURAL SELECTION,&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;                                &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 21,546 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;OoS_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;OoS&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/tidytext/man/unnest_tokens.html&#39;&gt;unnest_tokens&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    
&lt;span class=&#39;nv&#39;&gt;OoS_tidy&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 209,048 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    gutenberg_id word   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 1228   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 1859   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 first  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 edition&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 22764  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 1860   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 second &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 edition&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 2009   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009 1872   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 209,038 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Count and sort the tokens into a new data frame. Inspect the output. Are there any stop words?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt; Pipe the &lt;code&gt;word&lt;/code&gt; column of the data frame into the dplyr &lt;code&gt;count()&lt;/code&gt; function with the &lt;code&gt;sort = TRUE&lt;/code&gt; option. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;OoS_count&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;OoS_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
    &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;, sort &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;OoS_count&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 9,233 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    word      n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; the   &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;14&lt;/span&gt;&lt;span&gt;570&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; of    &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;&lt;span&gt;438&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; and    &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;&lt;span&gt;853&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; in     &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;5&lt;/span&gt;&lt;span&gt;414&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; to     &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;&lt;span&gt;753&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; a      &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;368&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; that   &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;749&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; as     &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;230&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; have   &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;114&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; be     &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;099&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 9,223 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Remove the stop words from the output and inspect the results.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt; Use &lt;code&gt;antijoin()&lt;/code&gt; with the tidytext &lt;code&gt;stop_words&lt;/code&gt; data frame: &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;OoS_count&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;OoS_tidy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;, sort &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
    &lt;span class=&#39;nf&#39;&gt;anti_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;stop_words&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Joining, by = &#34;word&#34;&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;OoS_count&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 8,678 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    word          n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; species    &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;921&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; forms       565&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; selection   561&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; natural     535&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; varieties   486&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; plants      471&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; animals     436&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; distinct    357&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; life        350&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; nature      325&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 8,668 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Visualize the counts using &lt;code&gt;ggplot()&lt;/code&gt;, from highest frequency to lowest, using a frequency cutoff of 200. Does any one word stand out in any way?&lt;/p&gt;
&lt;p&gt;Does the tidytext package perform lemmatization? Are there any irregular plurals in this result?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt; Use a dplyr &lt;code&gt;filter()&lt;/code&gt; command on the &lt;code&gt;n&lt;/code&gt; column, and, well just look at the examples in the presentation for the details of piping it into &lt;code&gt;ggplot()&lt;/code&gt;! &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;OoS_count&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;200&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;word &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/reorder.factor.html&#39;&gt;reorder&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;geom_col&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-21-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;tidytext does not lemmatize. There are many plurals in this list, so undoubtedly there are corresponding singulars of lower frequency. Indeed we see both &lt;code&gt;forms&lt;/code&gt; and &lt;code&gt;form&lt;/code&gt;. And of course the irregular &lt;code&gt;genera&lt;/code&gt; is the plural of &lt;code&gt;genus&lt;/code&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-5&#34;&gt;Exercise 5&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Create a word cloud of this data frame, with the same frequency cut off as the &lt;code&gt;ggplot()&lt;/code&gt; (200). Otherwise use the same settings as in the presentation. Tweak those settings, especially the frequency threshold and rotation proportion. See what happens when you set &lt;code&gt;random.order=TRUE&lt;/code&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;The option for the the frequency threshold is &lt;code&gt;min.freq = 200&lt;/code&gt;. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/wordcloud/man/wordcloud.html&#39;&gt;wordcloud&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;words &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;OoS_count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;word&lt;/span&gt;, 
          freq &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;OoS_count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt;, 
          min.freq &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;200&lt;/span&gt;, 
          random.order&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;, 
          rot.per&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0.35&lt;/span&gt;, 
          colors&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;brewer.pal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Dark2&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-22-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Session 18: Regular Expressions: Part II</title>
      <link>https://biodash.github.io/codeclub/18_regex2/</link>
      <pubDate>Mon, 12 Apr 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/18_regex2/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New to Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts. If you run into issues, please join the Zoom call early and we&amp;rsquo;ll help you troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;getting-set-up&#34;&gt;Getting Set Up&lt;/h2&gt;
&lt;p&gt;Like last week, we&amp;rsquo;re going to be working with functions from the &lt;em&gt;stringr&lt;/em&gt; package, which is one of the core &lt;em&gt;tidyverse&lt;/em&gt; packages, so let&amp;rsquo;s get that loaded first&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## If needed, install the tidyverse:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;tidyverse&#34;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Load the tidyverse -- this will include loading &#34;stringr&#34;. &lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;em&gt;stringr&lt;/em&gt; has lots of useful functions for working with strings. Our focus here is on regular expressions, though, which represent just one component of working with strings. So, we&amp;rsquo;ll limit the number of &lt;em&gt;stringr&lt;/em&gt; functions we work with to try to focus more on the regular expressions themselves. In the previous session, we worked primarily with the &lt;code&gt;str_view_all()&lt;/code&gt; function. We&amp;rsquo;ll see a lot of that one again this week, and maybe a couple more as needed. Maybe we&amp;rsquo;ll do a &lt;em&gt;stringr&lt;/em&gt;-focused session down the road to see more of what it offers, but in the meantime, you can check out the &lt;em&gt;stringr&lt;/em&gt; cheatsheet &lt;a href=&#34;https://evoldyn.gitlab.io/evomics-2018/ref-sheets/R_strings.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;, which also includes some useful info on regular expressions, if you&amp;rsquo;re interested.&lt;/p&gt;
&lt;h2 id=&#34;intro&#34;&gt;Intro&lt;/h2&gt;
&lt;p&gt;In case you missed last week, or could use a refresher, here&amp;rsquo;s a quick summary&amp;hellip;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Regular expressions allow you to match specific patterns in text. These can be simple patterns, like matching &amp;lsquo;choco&amp;rsquo; in &amp;lsquo;chocolate&amp;rsquo;, or more complicated patterns, like matching only lines that end with any three or four digits.&lt;/li&gt;
&lt;li&gt;More complicated matches are possible because there are characters, or in some cases, combinations of characters, that have special meaning. These include the metacharacters, anchors, and quantifiers we saw last week, and they help us define more complicated patterns in text.&lt;/li&gt;
&lt;li&gt;Sometimes you want to turn the &amp;ldquo;special meaning&amp;rdquo; of things like metacharacters, anchors, and quantifiers off to instead interpret the characters literally. The backslash helps us in those cases, and in R, you typically need two of them.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;p&gt;If regular expressions were new to you last week, it might have felt like a lot to digest. And this week we&amp;rsquo;re just going to add more. But don&amp;rsquo;t worry &amp;ndash; the idea really isn&amp;rsquo;t that you remember all of the special characters (metacharacters) and rules for matching patterns. Personally, I use regular expressions fairly often, and still don&amp;rsquo;t remember all of them all the time &amp;ndash; it&amp;rsquo;s easy enough to grab a cheat sheet and look up what you need to know. The more important thing for now is to just get a sense of the types of things regular expressions allow you to do. With that in mind, this week we&amp;rsquo;ll consider the following additional features/uses of regular expressions&amp;hellip;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Character classes/Bracket expressions&lt;/li&gt;
&lt;li&gt;Alternation&lt;/li&gt;
&lt;li&gt;Grouping&lt;/li&gt;
&lt;li&gt;Backreferences&lt;/li&gt;
&lt;li&gt;Greediness/Non-Greediness&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;As we go through these, we&amp;rsquo;ll use the following string that contains made-up counts of 100 peoples&#39; favorite ice cream flavor to see some examples of how they work&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Chocolate-48,Vanilla-27,Strawberry-25&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;character-classesbracket-expressions&#34;&gt;Character Classes/Bracket Expressions&lt;/h3&gt;
&lt;p&gt;Regular expressions allow you to match certain classes of characters &amp;ndash; uppercase, lowercase, digits, alphanumeric, punctuation, etc. We actually saw some examples of character classes last week &amp;ndash; we just didn&amp;rsquo;t call them that. For example, the &amp;lsquo;\d&amp;rsquo; metacharacter that matched any digit, and the &amp;lsquo;\w&amp;rsquo; that matched any word character each represented character classes. Another way of defining character classes/sets is with bracket expressions. These can work in several ways. Basically, any characters defined inside square brackets are matched. So, if you wanted to match any digit, you could use&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;[01234556789]&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/exmp1_2b.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Ranges can also be defined inside the square brackets with a dash, so this would be equivalent to the expression above&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;[0-9]&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/exmp1_2b.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;And if you want to match the dash, put it at the beginning&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;[-0-9]&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/exmp3.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Many character classes have a descriptive term that can also be used if it&amp;rsquo;s bracketed by a colon on each side inside the brackets&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;[:digit:]&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/exmp1_2.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Finally, the &amp;lsquo;^&amp;rsquo; can be used inside the brackets to negate the match. Notice the difference in how this character is interpreted here as compared to when we previously used it as an anchor (outside of the square brackets) &amp;ndash; CONTEXT MATTERS!&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;[^0-9]&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/exmp4.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h3 id=&#34;alternation&#34;&gt;Alternation&lt;/h3&gt;
&lt;p&gt;Alternation allows you to search for any of two or more patterns. This is achieved with the pipe symbol/vertical bar &lt;a href=&#34;https://rdrr.io/r/base/Logic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;|&lt;/code&gt;&lt;/a&gt;, which is usually just above the Return key. Within regular expressions, it can be read as &amp;ldquo;or&amp;rdquo;. So, the expression &amp;ldquo;Chocolate|Vanilla&amp;rdquo; finds matches to either of these flavors&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Chocolate|Vanilla&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/exmp5.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;And you can chain more than two of these together, as in &amp;ldquo;Chocolate|Vanilla|Strawberry&amp;rdquo;&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Chocolate|Vanilla|Strawberry&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/exmp6.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h3 id=&#34;grouping&#34;&gt;Grouping&lt;/h3&gt;
&lt;p&gt;Grouping serves a couple main purposes in regular expressions. We&amp;rsquo;ll consider one here, and then a second in the context of backreferences in the next section. The quantifiers Jelmer introduced last week define the number of times the preceding character must occur. But what if you want to match a set of characters a specific number of times? They can be grouped by wrapping them in parentheses, so the quantifier applies to the entire set. We&amp;rsquo;ll use a new example string for this one - one from the DNA world. Sometimes strings of DNA contain short sequences of repeats, like the &amp;lsquo;ATC&amp;rsquo; repeat in the middle of this string&amp;hellip; GTACGGG&lt;strong&gt;ATCATCATCATCATC&lt;/strong&gt;GGATCCCAGT&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dna_string&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;GTACGGGATCATCATCATCATCGGATCCCAGT&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What if we wanted to find places where &amp;ldquo;ATC&amp;rdquo; was repeated at least 3 times in sequence?&lt;/p&gt;
&lt;p&gt;This doesn&amp;rsquo;t give us what we want, since the quantifier is only being applied to the &amp;lsquo;C&amp;rsquo;&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dna_string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;ATC&amp;#123;3,&amp;#125;&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/exmp7.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Instead, we can group the &amp;lsquo;ATC&amp;rsquo; with a set of parentheses to get the result we want&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dna_string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;(ATC)&amp;#123;3,&amp;#125;&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/exmp8.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h3 id=&#34;backreferences&#34;&gt;Backreferences&lt;/h3&gt;
&lt;p&gt;Another place grouping comes in handy is with backreferences. But before we get to those, let&amp;rsquo;s get comfortable with a new function from &lt;em&gt;stringr&lt;/em&gt;. So far, we&amp;rsquo;ve focused on using regular expressions just to search for patterns. But sometimes we want to not only find a pattern, but then replace it with something else. The &lt;code&gt;str_replace()&lt;/code&gt; function can be thought of as an extension of &lt;code&gt;str_view()&lt;/code&gt; that takes a third argument - the string that will be used to replace any match identified. So, say we had a mistake in the data, and &amp;ldquo;Strawberry&amp;rdquo; was actually supposed to be &amp;ldquo;Caramel&amp;rdquo;&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Chocolate-48,Vanilla-27,Strawberry-25&#34;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;str_replace&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Strawberry&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Caramel&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Chocolate-48,Vanilla-27,Caramel-25&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Backreferences allow us to use the matches to (grouped) regex patterns as replacements. The characters matching each grouped regex pattern are temporarily assigned to variables (sequential numbers - i.e. the first matched group is assigned as 1, the second as 2, and so on), and can then be recalled with those numbers. Let&amp;rsquo;s go back to our ice cream string and use backreferences to reverse the order of the flavors in the string&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#view the current string&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Chocolate-48,Vanilla-27,Strawberry-25&#34;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;str_replace&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;, 
            &lt;span class=&#39;s&#39;&gt;&#34;(Chocolate-48),(Vanilla-27),(Strawberry-25)&#34;&lt;/span&gt;, 
            &lt;span class=&#39;s&#39;&gt;&#34;\\3,\\2,\\1&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Strawberry-25,Vanilla-27,Chocolate-48&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The first grouped match (Chocolate-48) got assigned to the variable &amp;lsquo;1&amp;rsquo;, the second (Vanilla-27) to &amp;lsquo;2&amp;rsquo;, and the third (Strawberry-25) to &amp;lsquo;3&amp;rsquo;. For the replacement, we just called these variables in reverse order. The notation to call these variables (backreferences) is often the combination of a single backslash and the number, but as Jelmer pointed out last week, in R, we need two backslashes.&lt;/p&gt;
&lt;p&gt;We could also use metacharacters to do it like this (or many other ways for that matter)&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_replace&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;(C.*),(V.*),(S.*)&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\3,\\1,\\2&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Strawberry-25,Chocolate-48,Vanilla-27&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;greediness&#34;&gt;Greediness&lt;/h3&gt;
&lt;p&gt;By default, regular expression matches will be greedy, as in this example&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;C.+\\d\\d&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/exmp9.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Notice there are three possible valid matches to the search pattern here &amp;ndash; &amp;ldquo;Chocolate-48&amp;rdquo;, &amp;ldquo;Chocolate-48,Vanilla-27&amp;rdquo;, and the full string which is actually what gets matched. This is called greedy behavior - the longest valid match will be identified by default. You can add the &amp;lsquo;?&amp;rsquo; after a quantifier to make the match non-greedy&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;our_string&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;C.+?\\d\\d&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/exmp10.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;So, in summary for today,&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Bracket expressions (square brackets) allow you to match anything inside them. Ranges can be defined with a dash. Notation is also available to define and match character classes &amp;ndash; things like digits, lowercase letters, punctuation, etc.&lt;/li&gt;
&lt;li&gt;The &lt;a href=&#34;https://rdrr.io/r/base/Logic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;|&lt;/code&gt;&lt;/a&gt; means &amp;ldquo;or&amp;rdquo; &amp;ndash; use it to match one of two or more patterns.&lt;/li&gt;
&lt;li&gt;Parentheses can be used to group a set of characters/metacharacters into a single regex pattern.&lt;/li&gt;
&lt;li&gt;When grouped patterns match, they are assigned to a temporary numeric variable that can be used to recall the match, usually to use it in a replacement.&lt;/li&gt;
&lt;li&gt;If there is more than one valid match to a regex search pattern, the longest one will be returned by default. This &amp;ldquo;greedy&amp;rdquo; behavior can be reversed by adding a &amp;lsquo;?&amp;rsquo; after the relevant quantifier.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Like last week, we&amp;rsquo;ll use data from the Great British Bakeoff to practice with some of these things. If you didn&amp;rsquo;t install that dataset last week, you can get it with the following code&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## If needed, first install the &#34;remotes&#34; package:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;remotes&#34;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;remotes&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://remotes.r-lib.org/reference/install_github.html&#39;&gt;install_github&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;apreshill/bakeoff&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then (everybody), load it&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://bakeoff.netlify.com&#39;&gt;bakeoff&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout rooms&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;For the first few exercises, we&amp;rsquo;re going to work with the signature bakes found in the &amp;ldquo;signature&amp;rdquo; column of the &amp;ldquo;bakes&amp;rdquo; data frame. Assign the data from this column to an object names &amp;ldquo;sigs&amp;rdquo;. Preview it by viewing its first 3 items and getting its length.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints
&lt;/summary&gt;
&lt;p&gt;Use the &amp;lsquo;$&amp;rsquo; notation to pull out the single column from the data frame, or alternatively a combination of &lt;em&gt;dplyr&lt;/em&gt;&amp;rsquo;s &lt;code&gt;select()&lt;/code&gt; followed by &lt;a href=&#34;https://rdrr.io/r/base/unlist.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;unlist()&lt;/code&gt;&lt;/a&gt;. Use square brackets to index the vector, and the &lt;a href=&#34;https://rdrr.io/r/base/length.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;length()&lt;/code&gt;&lt;/a&gt; function to get its length.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;sigs&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bakes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signature&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;sigs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Light Jamaican Black Cakewith Strawberries and Cream&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [2] &#34;Chocolate Orange Cake&#34;                               &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [3] &#34;Caramel Cinnamon and Banana Cake&#34;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sigs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 548&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;p&gt;Find all signature bakes that contain either raspberries or blueberries. Make sure to try to cover all the ways those ingredients might be reflected in the names.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints
&lt;/summary&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use the pipe symbol for alternation (OR)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Include possible variants such as raspberry, raspberries, Raspberry, etc.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sigs&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;[Rr]aspberr.+|[Bb]lueberr.+&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/ex2.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;p&gt;Even if you&amp;rsquo;re not a millionaire, you&amp;rsquo;d like to try to eat like one. First, find all signature bakes that have &amp;ldquo;Millionaire&amp;rdquo; in the name. Then do a second search and limit the results to just those that start with &amp;ldquo;Millionaire&amp;rdquo;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints
&lt;/summary&gt;
&lt;ul&gt;
&lt;li&gt;Use the appropriate anchor to limit results to those with &amp;ldquo;Millionaire&amp;rdquo; at the beginning of the name.&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sigs&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Millionaire&#34;&lt;/span&gt;, match&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/ex3a.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sigs&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;^Millionaire&#34;&lt;/span&gt;, match&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/ex3b.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;p&gt;You tried each of the three signature bakes that start with &amp;ldquo;Millionaire&amp;rdquo;, and weren&amp;rsquo;t that impressed. Save these three bakes&#39; names in the object &amp;lsquo;not_good&amp;rsquo; and then change the names of each of the three by replacing &amp;ldquo;Millionaire&amp;rdquo; with &amp;ldquo;Poor Man&amp;rdquo;. Assign the three new names to the object &amp;lsquo;renamed&amp;rsquo;. Note you&amp;rsquo;ll need a new &lt;em&gt;stringr&lt;/em&gt; function for this exercise.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints
&lt;/summary&gt;
&lt;p&gt;Use the &lt;code&gt;str_subset()&lt;/code&gt; function to pull out the matching strings. Then use the &lt;code&gt;str_replace()&lt;/code&gt; function we used in the examples for the replacement.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;not_good&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;str_subset&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sigs&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;^Millionaire&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;not_good&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Millionaires&#39; Shortbread&#34;   &#34;Millionaire Banoffee Bonus&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [3] &#34;Millionaire&#39;s Roulade&#34;&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;renamed&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;str_replace_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;not_good&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Millionaire&#34;&lt;/span&gt;,
                           &lt;span class=&#39;s&#39;&gt;&#34;Poor Man&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;renamed&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Poor Mans&#39; Shortbread&#34;   &#34;Poor Man Banoffee Bonus&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [3] &#34;Poor Man&#39;s Roulade&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;bonus-1&#34;&gt;Bonus 1&lt;/h3&gt;
&lt;p&gt;For the bonus, let&amp;rsquo;s work with a different part of the dataset. The &amp;lsquo;bakers&amp;rsquo; data frame includes a column named &amp;lsquo;baker_full&amp;rsquo; that has the full name of each baker. First, extract that column and save it as the object &amp;lsquo;baker_names&amp;rsquo;. Then preview the first 5 names in this vector.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints
&lt;/summary&gt;
&lt;p&gt;Use the &amp;lsquo;$&amp;rsquo; and [ ] notations.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;baker_names&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;baker_full&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;baker_names&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Annetha Mills&#34;         &#34;David Chambers&#34;        &#34;Edward \&#34;Edd\&#34; Kimber&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [4] &#34;Jasminder Randhawa&#34;    &#34;Jonathan Shepherd&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;bonus-2&#34;&gt;Bonus 2&lt;/h3&gt;
&lt;p&gt;Notice from the first 5 entries of &amp;lsquo;baker_names&amp;rsquo; that the names are ordered as first name then last name, with potentially a middle name, or nickname, in between. Try reordering the names so they read last name, comma, first (and middle, if applicable). Assign the new names to &amp;lsquo;baker_names_rev&amp;rsquo;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints
&lt;/summary&gt;
&lt;p&gt;Use grouping and backreferences.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;baker_names_rev&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;str_replace&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;baker_names&lt;/span&gt;, 
                               &lt;span class=&#39;s&#39;&gt;&#34;(.+)(\\s[:alpha:]+)&#34;&lt;/span&gt;,
                               &lt;span class=&#39;s&#39;&gt;&#34;\\2, \\1&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;baker_names_rev&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34; Mills, Annetha&#34;         &#34; Chambers, David&#34;       &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [3] &#34; Kimber, Edward \&#34;Edd\&#34;&#34; &#34; Randhawa, Jasminder&#34;   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [5] &#34; Shepherd, Jonathan&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Session 17: Introduction to regular expressions</title>
      <link>https://biodash.github.io/codeclub/17_regex/</link>
      <pubDate>Tue, 06 Apr 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/17_regex/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New to Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll help you troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1-getting-set-up&#34;&gt;1. Getting set up&lt;/h2&gt;
&lt;p&gt;While base R also has functions to work with regular expressions (such as &lt;a href=&#34;https://rdrr.io/r/base/grep.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;grep()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://rdrr.io/r/base/regex.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;regexp()&lt;/code&gt;&lt;/a&gt;), we will work with the &lt;em&gt;stringr&lt;/em&gt; package, one of the core &lt;em&gt;tidyverse&lt;/em&gt; packages.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## If needed, install the tidyverse:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;tidyverse&#34;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Load the tidyverse -- this will include loading &#34;stringr&#34;. &lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To get access to some strings that we can match with regular expressions, we will use the &lt;em&gt;bakeoff&lt;/em&gt; data package:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## If needed, first install the &#34;remotes&#34; package:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;remotes&#34;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;remotes&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://remotes.r-lib.org/reference/install_github.html&#39;&gt;install_github&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;apreshill/bakeoff&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://bakeoff.netlify.com&#39;&gt;bakeoff&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2-regular-expressions-what-and-why&#34;&gt;2. Regular expressions: what and why?&lt;/h2&gt;
&lt;p&gt;You would probably have no trouble recognizing internet and email addresses, most phone numbers, or a DNA sequence embedded in a piece of text. And you would do so even if these were presented without context, and even though you may have never seen that &lt;em&gt;specific&lt;/em&gt; email address, DNA sequence, and so on.&lt;/p&gt;
&lt;p&gt;We can recognize these things because they adhere to certain patterns: a DNA sequence, for instance, typically consists of a sequence of capital As, Cs, Gs, and Ts.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Regular expressions provide a way to describe and match text that contains specific patterns to computers&lt;/strong&gt;, with expressions that convey things like &lt;em&gt;&amp;ldquo;any digit&amp;rdquo;&lt;/em&gt; and &lt;em&gt;&amp;ldquo;one or more or the previous character or character type&amp;rdquo;&lt;/em&gt;. For example, &lt;strong&gt;&lt;code&gt;\d{5}&lt;/code&gt;&lt;/strong&gt; is a regular expression that matches at least five consecutive digits and would be a good start to finding all US ZIP codes contained in some text.&lt;/p&gt;
&lt;p&gt;Regular expressions are extremely useful for a couple of related purposes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Finding and extracting information that adheres to patterns&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Finding addresses, citations, or identifiers such as accession numbers.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Finding degenerate primers (or the DNA sequence between them) or transcription factor binding sites, in which certain positions may vary.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Finding DNA repeats: you know that something is repeated, but not what is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;While we often &lt;em&gt;generalize&lt;/em&gt; and &lt;em&gt;constrain&lt;/em&gt; matches at the same time, we could also merely constrain them:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Only find instances of &amp;ldquo;&lt;em&gt;chocolate&lt;/em&gt;&amp;rdquo; if it is the first or last word of a line/sentence/string.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Only find instances of &amp;ldquo;&lt;em&gt;chocolate&lt;/em&gt;&amp;rdquo; which are followed by &amp;ldquo;cake&amp;rdquo;, &amp;ldquo;tart&amp;rdquo;, or &amp;ldquo;croissant&amp;rdquo;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Sophisticated find-and-replace&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Replace multiple variations of the same thing at once:&lt;br&gt;
e.g. change all DNA repeats to lowercase letters or Ns.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Change a date format from &lt;code&gt;M/DD/YY&lt;/code&gt; to &lt;code&gt;YYYY-MM-DD&lt;/code&gt;, or GPS coordinates in degrees/minutes/seconds format to decimal degrees (note that this needs a bit of conversion too).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Rename files: switch sample ID and treatment ID separated by underscores,&lt;br&gt;
or pad numbers (&lt;code&gt;1&lt;/code&gt;-&lt;code&gt;100&lt;/code&gt; =&amp;gt; &lt;code&gt;001&lt;/code&gt;-&lt;code&gt;100&lt;/code&gt; for proper ordering).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Finally, regular expressions can be used to &lt;strong&gt;parse and convert file formats&lt;/strong&gt;, though you generally don&amp;rsquo;t have to do this yourself unless you are dealing with highly custom file types.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Regular expressions are used in nearly all programming languages. They are also widely used in text editors and therefore provide a first taste of programming for many people.&lt;/strong&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3-str_view-and-strings&#34;&gt;3. &lt;code&gt;str_view()&lt;/code&gt; and strings&lt;/h2&gt;
&lt;p&gt;Today, to get to know regular expressions, we will just use the &lt;code&gt;str_view()&lt;/code&gt; function from the &lt;em&gt;stringr&lt;/em&gt; package. Next week, we&amp;rsquo;ll get introduced to other &lt;em&gt;stringr&lt;/em&gt; functions to search and also to replace strings.&lt;/p&gt;
&lt;p&gt;The basic syntax is &lt;code&gt;str_view(&amp;lt;target-string(s)&amp;gt;, &amp;lt;search-pattern&amp;gt;)&lt;/code&gt;, for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;chocolate&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;cola&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/cola.png&#34; width=&#34;15%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;str_view()&lt;/code&gt; shows us which part of the target string was matched in the &lt;code&gt;Viewer&lt;/code&gt; pane of RStudio. This particular match is rather obvious because we searched for a &amp;ldquo;literal string&amp;rdquo; without any special meaning. However, the visual representation will become useful when we start using special characters in our regular expressions: then, we know what &lt;em&gt;pattern&lt;/em&gt; we should be matching, but not what &lt;em&gt;exact string&lt;/em&gt; we actually matched.&lt;/p&gt;
&lt;p&gt;If we want to see all matches, and not just the first one, we have to use &lt;code&gt;str_view_all&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;chocolate&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;o&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/one_o.png&#34; width=&#34;15%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;chocolate&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;o&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/two_o.png&#34; width=&#34;15%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;em&gt;stringr&lt;/em&gt; functions are vectorized, so we can use them not just to match a single string but also to match a vector of strings:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bakes&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;plum pudding&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;chocolate cake&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;sticky toffee pudding&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakes&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;pudding&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/vector1.png&#34; width=&#34;30%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Note that the non-matching string &amp;ldquo;&lt;em&gt;chocolate cake&lt;/em&gt;&amp;rdquo; was displayed despite the lack of a match. If we only want to see strings that matched, we can set the &lt;code&gt;match&lt;/code&gt; argument to &lt;code&gt;TRUE&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakes&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;pudding&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/vector2.png&#34; width=&#34;30%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
  &lt;div&gt;
    &lt;p&gt;&lt;strong&gt;Strings in R&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;A &amp;ldquo;string&amp;rdquo; or &amp;ldquo;character string&amp;rdquo; is a contiguous sequence of characters. To indicate that something is a string in R, we put quotes around it: &lt;code&gt;&amp;quot;Hello&amp;quot;&lt;/code&gt; and &lt;code&gt;&amp;quot;9&amp;quot;&lt;/code&gt;. If you forget the quotes, R would interpret &lt;code&gt;&amp;quot;Hello&amp;quot;&lt;/code&gt; as an &lt;em&gt;object&lt;/em&gt; (because it starts with a letter) and &lt;code&gt;&amp;quot;9&amp;quot;&lt;/code&gt; as a &lt;em&gt;number&lt;/em&gt; (because it starts with a digit).&lt;/p&gt;
&lt;p&gt;There is &lt;em&gt;no difference&lt;/em&gt; between single quotes (&lt;code&gt;&#39;Hello&#39;&lt;/code&gt;) and double quotes (&lt;code&gt;&amp;quot;Hello&amp;quot;&lt;/code&gt;), but double quotes are generally recommended.&lt;/p&gt;
&lt;p&gt;If your string is itself supposed to contain a quote symbol of some kind, it is convenient to use the &lt;em&gt;other type&lt;/em&gt; of quote to define the string:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# The string contains a single quote, so we use double quotes to define it:&lt;/span&gt;
&lt;span class=&#39;s&#39;&gt;&#34;This cake&#39;s 7th layer is particularly good.&#34;&lt;/span&gt;
&lt;p&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &amp;ldquo;This cake&amp;rsquo;s 7th layer is particularly good.&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Alternatively, a quote can be &lt;strong&gt;escaped&lt;/strong&gt; using a backslash &lt;strong&gt;&lt;code&gt;\&lt;/code&gt;&lt;/strong&gt; to indicate that it does &lt;em&gt;not end the string&lt;/em&gt; but represents a literal quote &lt;em&gt;inside the string&lt;/em&gt;, which may be necessary if a string contains both single and double quotes:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;s&#39;&gt;&#34;This cake is only 2&#39;4\&#34; tall - do better!&#34;&lt;/span&gt;
&lt;p&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &amp;ldquo;This cake is only 2&#39;4&amp;quot; tall - do better!&amp;quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/p&gt;
&lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4-special-characters&#34;&gt;4. Special characters&lt;/h2&gt;
&lt;h4 id=&#34;special-characters-and-escaping-them&#34;&gt;Special characters and escaping them&lt;/h4&gt;
&lt;p&gt;In regular expressions (regex), we need a way to succinctly convey descriptions such as &amp;ldquo;any character&amp;rdquo; or &amp;ldquo;any digit&amp;rdquo;. &lt;em&gt;However, there are no characters exclusive to regular expressions:&lt;/em&gt; &lt;em&gt;instead, we re-use normal characters.&lt;/em&gt; For instance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;ldquo;&lt;strong&gt;Any digit&lt;/strong&gt;&amp;rdquo; is represented by &lt;strong&gt;&lt;code&gt;\d&lt;/code&gt;&lt;/strong&gt;, with the &lt;strong&gt;&lt;code&gt;\&lt;/code&gt;&lt;/strong&gt; basically preventing the &lt;strong&gt;&lt;code&gt;d&lt;/code&gt;&lt;/strong&gt; from being interpreted literally.&lt;/li&gt;
&lt;li&gt;&amp;ldquo;&lt;strong&gt;Any character&lt;/strong&gt;&amp;rdquo; is represented by a period, &lt;strong&gt;&lt;code&gt;.&lt;/code&gt;&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;How, then, do we indicate a literal period &lt;strong&gt;&lt;code&gt;.&lt;/code&gt;&lt;/strong&gt; in a regular expression? The solution is to &lt;strong&gt;escape&lt;/strong&gt; it with a backslash: the regular expression &lt;strong&gt;&lt;code&gt;\.&lt;/code&gt;&lt;/strong&gt; matches a period &lt;strong&gt;&lt;code&gt;.&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
  &lt;div&gt;
    &lt;h4 id=&#34;tldr-for-the-rest-of-this-section&#34;&gt;TLDR for the rest of this section&lt;/h4&gt;
&lt;p&gt;&lt;strong&gt;When writing regular expressions as strings in R,&lt;/strong&gt; &lt;strong&gt;we always need to add an extra backslash:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;The regex &lt;strong&gt;&lt;code&gt;\d&lt;/code&gt;&lt;/strong&gt; matches a digit &amp;mdash; and we write it as &lt;strong&gt;&lt;code&gt;&amp;quot;\\d&amp;quot;&lt;/code&gt;&lt;/strong&gt; in R.&lt;/li&gt;
&lt;li&gt;The regex &lt;strong&gt;&lt;code&gt;\.&lt;/code&gt;&lt;/strong&gt; matches a period &amp;mdash; and we write it as &lt;strong&gt;&lt;code&gt;&amp;quot;\\.&amp;quot;&lt;/code&gt;&lt;/strong&gt; in R.&lt;/li&gt;
&lt;/ul&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;The &amp;ldquo;escaping&amp;rdquo; described above also applies to backslashes, such that the regex &lt;strong&gt;&lt;code&gt;\\&lt;/code&gt;&lt;/strong&gt; matches a &lt;strong&gt;&lt;code&gt;\&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;escape-sequences-in-regular-strings&#34;&gt;Escape sequences in regular strings&lt;/h4&gt;
&lt;p&gt;Outside of regular expressions, R also uses backslashes &lt;strong&gt;&lt;code&gt;\&lt;/code&gt;&lt;/strong&gt; to form so-called &amp;ldquo;escape sequences&amp;rdquo;. This works similarly to how the regular expression &lt;strong&gt;&lt;code&gt;\d&lt;/code&gt;&lt;/strong&gt; means &amp;ldquo;any digit&amp;rdquo; &amp;ndash; for example, when we use &lt;strong&gt;&lt;code&gt;\n&lt;/code&gt;&lt;/strong&gt; &lt;em&gt;in any string&lt;/em&gt;, it will be interpreted as a newline:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/cat.html&#39;&gt;cat&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;cho\nco&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; cho&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; co&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In fact, a single backslash &lt;strong&gt;&lt;code&gt;\&lt;/code&gt;&lt;/strong&gt; is &lt;strong&gt;never taken literally&lt;/strong&gt; in any regular R string:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;cat(&#34;cho\dco&#34;)

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error: &#39;\d&#39; is an unrecognized escape in character string starting &#34;&#34;cho\d&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Because this is &lt;em&gt;not&lt;/em&gt; a regular expression, and &lt;strong&gt;&lt;code&gt;\d&lt;/code&gt;&lt;/strong&gt; does not happen to be an escape sequence like &lt;strong&gt;&lt;code&gt;\n&lt;/code&gt;&lt;/strong&gt; was earlier, &lt;strong&gt;&lt;code&gt;\d&lt;/code&gt;&lt;/strong&gt; doesn&amp;rsquo;t mean anything to R. But instead of assuming that the backslash is therefore a literal backslash, R throws an error, demonstrating that a backslash is always interpreted as the first character in an escape sequence.&lt;/p&gt;
&lt;p&gt;How can we include a backslash in a string, then? Same as before: we &amp;ldquo;escape&amp;rdquo; it with another backslash:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/cat.html&#39;&gt;cat&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;bla\\dbla&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; bla\dbla&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h4 id=&#34;the-backslash-plague&#34;&gt;The backslash plague&lt;/h4&gt;
&lt;p&gt;We saw that the regular expression &lt;strong&gt;&lt;code&gt;\d&lt;/code&gt;&lt;/strong&gt; matches a digit, but also that using string &lt;strong&gt;&lt;code&gt;&amp;quot;\d&amp;quot;&lt;/code&gt;&lt;/strong&gt; will merely throw an error!&lt;/p&gt;
&lt;p&gt;Therefore, to actually define a regular expression that contains &lt;strong&gt;&lt;code&gt;\d&lt;/code&gt;&lt;/strong&gt;, we need to use the string &lt;strong&gt;&lt;code&gt;&amp;quot;\\d&amp;quot;&lt;/code&gt;&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;str_view(&#34;The cake has 8 layers&#34;, &#34;\d&#34;)

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error: &#39;\d&#39; is an unrecognized escape in character string starting &#34;&#34;\d&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;The cake has 8 layers&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\d&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/digit1.png&#34; width=&#34;30%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;So, to define any regular expression symbol that contains a backslash,&lt;/strong&gt; &lt;strong&gt;we need to always use two backslashes!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;This also applies when we want to match a literal character. For example, &lt;strong&gt;to match a literal period, we need the regex &lt;code&gt;\.&lt;/code&gt;,&lt;/strong&gt; &lt;strong&gt;which we have to write as &lt;code&gt;\\.&lt;/code&gt; in an R string:&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;The cake has 8.5 layers&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\.&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/period2.png&#34; width=&#34;30%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now to the worst case: what if we want to match a backslash? We need the regular expression &lt;strong&gt;&lt;code&gt;\\&lt;/code&gt;&lt;/strong&gt;, but to define that regex as a string, we have to escape each of the two backslashes &amp;ndash; only to end up with four backslashes!&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;C:\\Windows&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Error in stri_locate_first_regex(string, pattern, opts_regex = opts(pattern)): Unrecognized backslash escape sequence in pattern. (U_REGEX_BAD_ESCAPE_SEQUENCE, context=`\`)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;C:\\Windows&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\\\&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/windows.png&#34; width=&#34;15%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Welcome to the backslash plague! &lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;5-the-great-british-bake-off&#34;&gt;5. The Great British Bake Off&lt;/h2&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/bakeoff.jpg width=60%&gt;
&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s take a look at some of the data in the &lt;em&gt;bakeoff&lt;/em&gt; package, which is about &amp;ldquo;The Great British Bake Off&amp;rdquo; (GBBO) television show.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;bakers&lt;/code&gt; dataframe contains some information about each participant (baker) in the show, and we will be matching names from the &lt;code&gt;baker_full&lt;/code&gt; column:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   series baker_full   baker    age occupation   hometown  baker_last baker_first&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;        &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;        &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;      &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; 1      &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Annetha Mi… Annet…    30 Midwife      Essex     Mills      Annetha    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; 1      &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;David Cham… David     31 Entrepreneur Milton K… Chambers   David      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; 1      &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Edward \&#34;E… Edd       24 Debt collec… Bradford  Kimber     Edward     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; 1      &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Jasminder … Jasmi…    45 Assistant C… Birmingh… Randhawa   Jasminder  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; 1      &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Jonathan S… Jonat…    25 Research An… St Albans Shepherd   Jonathan   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; 1      &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt;Lea Harris&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;&#34;&lt;/span&gt;&lt;span&gt; Lea       51 Retired      Midlothi… Harris     Lea&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;code&gt;challenge_results&lt;/code&gt; dataframe contains &amp;ldquo;signature&amp;rdquo; and &amp;ldquo;showstopper&amp;rdquo; bakes made by each participant in each episode:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;challenge_results&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   series episode baker  result signature        technical showstopper           &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt;      1       1 Annet… IN     Light Jamaican …         2 Red, White &amp;amp; Blue Cho…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt;      1       1 David  IN     Chocolate Orang…         3 Black Forest Floor Ga…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt;      1       1 Edd    IN     Caramel Cinnamo…         1 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt;      1       1 Jasmi… IN     Fresh Mango and…        &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt;      1       1 Jonat… IN     Carrot Cake wit…         9 Three Tiered White an…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt;      1       1 Louise IN     Carrot and Oran…        &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt; Never Fail Chocolate …&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The &amp;ldquo;signature&amp;rdquo; bakes are the first bakes presented in each GBBO episode, so we&amp;rsquo;ll start trying to match these bakes with regular expressions. Let&amp;rsquo;s save them in a vector for easy access later on:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;challenge_results&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signature&lt;/span&gt;     &lt;span class=&#39;c&#39;&gt;# Assign the column to a vector&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;# Remove NAs&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;                              &lt;span class=&#39;c&#39;&gt;# Look at the first 20 items&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] &#34;Light Jamaican Black Cakewith Strawberries and Cream&#34;                       &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [2] &#34;Chocolate Orange Cake&#34;                                                      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [3] &#34;Caramel Cinnamon and Banana Cake&#34;                                           &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [4] &#34;Fresh Mango and Passion Fruit Hummingbird Cake&#34;                             &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [5] &#34;Carrot Cake with Lime and Cream Cheese Icing&#34;                               &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [6] &#34;Carrot and Orange Cake&#34;                                                     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [7] &#34;Triple Layered Brownie Meringue Cake\nwith Raspberry Cream&#34;                 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [8] &#34;Three Tiered Lemon Drizzle Cakewith Fresh Cream and freshly made Lemon Curd&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [9] &#34;Cranberry and Pistachio Cakewith Orange Flower Water Icing&#34;                 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [10] &#34;Sticky Marmalade Tea Loaf&#34;                                                  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [11] &#34;Cheddar Cheese and Fresh Rosemary Biscuits&#34;                                 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [12] &#34;Oatmeal Raisin Cookie&#34;                                                      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [13] &#34;Millionaires&#39; Shortbread&#34;                                                   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [14] &#34;Honey and Candied Ginger Cookies&#34;                                           &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [15] &#34;Fresh Vanilla Biscuits with Royal Icing&#34;                                    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [16] &#34;Peanut Shortbread withSalted Peanut Caramel&#34;                                &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [17] &#34;Rose Petal Shortbread&#34;                                                      &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [18] &#34;Stained Glass Window Shortbread&#34;                                            &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [19] &#34;Chilli Bread&#34;                                                               &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [20] &#34;Olive Bread&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;6-components-of-regular-expressions&#34;&gt;6. Components of regular expressions&lt;/h2&gt;
&lt;h3 id=&#34;literal-characters&#34;&gt;Literal characters&lt;/h3&gt;
&lt;p&gt;Literal characters can be a part of regular expressions. In fact, as we saw in the first example, our entire search pattern for &lt;code&gt;str_view()&lt;/code&gt; can perfectly well consist of &lt;em&gt;only&lt;/em&gt; literal characters.&lt;/p&gt;
&lt;p&gt;But the power of regular expressions comes with special characters, and below, we&amp;rsquo;ll go through several different categories of these.&lt;/p&gt;
&lt;h3 id=&#34;metacharacters&#34;&gt;Metacharacters&lt;/h3&gt;
&lt;p&gt;Metacharacters often represent a single instance of &lt;strong&gt;a character type&lt;/strong&gt;: above, we already learned that &lt;strong&gt;&lt;code&gt;.&lt;/code&gt;&lt;/strong&gt; matches &lt;em&gt;any single character&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Other metacharacters are actually character combinations starting with a &lt;strong&gt;&lt;code&gt;\&lt;/code&gt;&lt;/strong&gt;:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Symbol&lt;/th&gt;
&lt;th&gt;Matches&lt;/th&gt;
&lt;th&gt;Negation (&amp;ldquo;anything but&amp;rdquo;)&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;.&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Any single character.&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;\d&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Any digit.&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;\D&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;\s&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Any white space: space, tab, newline, carriage return.&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;\S&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;\w&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Any word character: alphanumeric and underscore.&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;\W&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;\n&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A newline.&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;\t&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;A tab.&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;Negated metacharacters match anything except that character type: &lt;strong&gt;&lt;code&gt;\D&lt;/code&gt;&lt;/strong&gt; matches anything except a digit.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Some examples:&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Are there any digits (&lt;strong&gt;&lt;code&gt;\d&lt;/code&gt;&lt;/strong&gt;) in the bake names?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\d&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/digit2.png&#34; width=&#34;27%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Let&amp;rsquo;s match 5-character strings that start with &amp;ldquo;&lt;em&gt;Ma&lt;/em&gt;&amp;quot;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Ma...&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/ma.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Note that the only constraint we are setting with &lt;strong&gt;&lt;code&gt;...&lt;/code&gt;&lt;/strong&gt; is that at least three characters should follow &lt;strong&gt;&lt;code&gt;Ma&lt;/code&gt;&lt;/strong&gt; &amp;ndash; we are &lt;em&gt;not&lt;/em&gt; restricting matches to five-character words.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Let&amp;rsquo;s find the bakers whose (first or last) names contain at least 11 word characters &lt;strong&gt;&lt;code&gt;\w&lt;/code&gt;&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;baker_full&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w\\w&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/11letternames.png&#34; width=&#34;25%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;It&amp;rsquo;s not very convenient to have to repeat &lt;code&gt;\\w&lt;/code&gt; so many times!&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Or let&amp;rsquo;s say we wanted to get all three-part names: names that contain three sets of one or more word characters separated by non-word characters. How could we describe such a pattern? &amp;ldquo;Quantifiers&amp;rdquo; to the rescue!&lt;/p&gt;
&lt;h3 id=&#34;quantifiers&#34;&gt;Quantifiers&lt;/h3&gt;
&lt;p&gt;Quantifiers describe how many consecutive instances of the &lt;strong&gt;preceding&lt;/strong&gt; character should be matched:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Quantifier&lt;/th&gt;
&lt;th&gt;Matches&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;*&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Preceding character &lt;em&gt;any number of times&lt;/em&gt; (0 or more).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;+&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Preceding character &lt;em&gt;at least&lt;/em&gt; once (1 or more).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/utils/Question.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;?&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Preceding character &lt;em&gt;at most&lt;/em&gt; once (0 or 1).&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;{n}&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Preceding character &lt;em&gt;exactly &lt;code&gt;n&lt;/code&gt; times&lt;/em&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;{n,}&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Preceding character &lt;em&gt;at least &lt;code&gt;n&lt;/code&gt; times&lt;/em&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;{n,m}&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Preceding character &lt;em&gt;at least &lt;code&gt;n&lt;/code&gt; and at most &lt;code&gt;m&lt;/code&gt; times&lt;/em&gt;.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;em&gt;Some examples:&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Names with at least 11 (&lt;strong&gt;&lt;code&gt;{11,}&lt;/code&gt;&lt;/strong&gt;) characters &amp;ndash; note that this matches the entire word:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;baker_full&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\w&amp;#123;11,&amp;#125;&#34;&lt;/span&gt;, match&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/11letternames2.png&#34; width=&#34;25%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Match names with 2 to 3 (&lt;strong&gt;&lt;code&gt;{2,3}&lt;/code&gt;&lt;/strong&gt;) consecutive &amp;ldquo;&lt;em&gt;e&lt;/em&gt;&amp;rdquo; characters. Note that this match encompasses the full string (name), because we flank the pattern with &lt;strong&gt;&lt;code&gt;.*&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;baker_full&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;.*e&amp;#123;2,3&amp;#125;.*&#34;&lt;/span&gt;, match&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/2or3es_fullmatch.png&#34; width=&#34;17%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Account for different spelling options with &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/utils/Question.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;?&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; &amp;ndash; match &amp;ldquo;&lt;em&gt;flavor&lt;/em&gt;&amp;rdquo; or &amp;ldquo;&lt;em&gt;flavour&lt;/em&gt;&amp;quot;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;flavou?r&#34;&lt;/span&gt;, match&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/flavor.png&#34; width=&#34;65%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Match all three-part names &amp;ndash; one or more word characters (&lt;strong&gt;&lt;code&gt;\w+&lt;/code&gt;&lt;/strong&gt;) separated by a non-word character (&lt;strong&gt;&lt;code&gt;\W&lt;/code&gt;&lt;/strong&gt;) at least two consecutive times:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;baker_full&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\w+\\W\\w+\\W\\w+&#34;&lt;/span&gt;, match&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/3partnames.png&#34; width=&#34;30%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Match all three-letter names by looking for non-word characters (&lt;strong&gt;&lt;code&gt;\W&lt;/code&gt;&lt;/strong&gt;) surrounding three word characters (&lt;strong&gt;&lt;code&gt;\w{3}&lt;/code&gt;&lt;/strong&gt;)?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;baker_full&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\W\\w&amp;#123;3&amp;#125;\\W&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/3letternames1.png&#34; width=&#34;30%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;That last attempt didn&amp;rsquo;t really work &amp;ndash; note that we only got three-letter &lt;em&gt;middle names&lt;/em&gt;, since we required our three-letter names to be flanked by non-word characters.&lt;/p&gt;
&lt;p&gt;To get &lt;em&gt;all&lt;/em&gt; three-letter names, we need to be able to &amp;ldquo;anchor&amp;rdquo; our regular expressions, e.g. demand that a pattern starts at the beginning of the string.&lt;/p&gt;
&lt;h3 id=&#34;anchors&#34;&gt;Anchors&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Anchor&lt;/th&gt;
&lt;th&gt;Matches&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;^&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Beginning of the string/line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;a href=&#34;https://rdrr.io/r/base/Extract.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;$&lt;/code&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;End of the string/line&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;\b&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;A word &lt;em&gt;boundary&lt;/em&gt; (beginning or end)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;em&gt;Some examples:&lt;/em&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Match all three-letter &lt;em&gt;first&lt;/em&gt; names, by anchoring the three word characters (&lt;strong&gt;&lt;code&gt;\w{3}&lt;/code&gt;&lt;/strong&gt;) to the beginning of the string with &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;^&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;, and including a space at the end:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;baker_full&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;^\\w&amp;#123;3&amp;#125; &#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/3letterfirstnames.png&#34; width=&#34;23%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Match all three-letter names &amp;ndash;whether first, middle, or last&amp;ndash; using three word-characters (&lt;strong&gt;&lt;code&gt;\w&lt;/code&gt;&lt;/strong&gt;) surrounded by word-boundaries (&lt;strong&gt;&lt;code&gt;\b&lt;/code&gt;&lt;/strong&gt;):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;baker_full&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\b\\w&amp;#123;3&amp;#125;\\b&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/3letternames2.png&#34; width=&#34;23%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;regex-components-for-next-week&#34;&gt;Regex components for next week&lt;/h4&gt;
&lt;p&gt;Next week, we&amp;rsquo;ll talk about:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Character classes&lt;/li&gt;
&lt;li&gt;Alternation&lt;/li&gt;
&lt;li&gt;Grouping&lt;/li&gt;
&lt;li&gt;Backreferences&lt;/li&gt;
&lt;li&gt;Making quantifiers non-greedy&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
  &lt;div&gt;
    &lt;p&gt;&lt;strong&gt;Regular expressions vs globbing&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Do not confuse regular expressions with &lt;em&gt;globbing&lt;/em&gt;!&lt;/p&gt;
&lt;p&gt;If you have worked in a terminal before, you may know that you can match file names using &lt;em&gt;shell wildcards&lt;/em&gt;, which is known as &amp;ldquo;globbing&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;There are only a few characters used in shell wildcards, but their meanings differ from regular expressions in two instances!&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Shell wildcard&lt;/th&gt;
&lt;th&gt;Equivalent regex&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/utils/Question.html&#34;&gt;&lt;code&gt;?&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;.&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Any single character&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34;&gt;&lt;code&gt;*&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;.*&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Any number of any character&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;&lt;code&gt;[]&lt;/code&gt;&lt;/strong&gt; and &lt;strong&gt;&lt;code&gt;[^]&lt;/code&gt;&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;same!&lt;/td&gt;
&lt;td&gt;Match/negate match of &lt;em&gt;character class&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;ul&gt;
&lt;li&gt;Note also that &lt;strong&gt;&lt;code&gt;.&lt;/code&gt;&lt;/strong&gt; is interpreted as a literal period in globbing.&lt;/li&gt;
&lt;li&gt;We will talk about &amp;ldquo;character classes&amp;rdquo; next week.&lt;/li&gt;
&lt;/ul&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;7-breakout-rooms&#34;&gt;7. Breakout rooms&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;Find all participant names in &lt;code&gt;bakers$baker_full&lt;/code&gt; that contain at least 4 lowercase &amp;ldquo;&lt;em&gt;e&lt;/em&gt;&amp;rdquo; characters. (That, the &amp;ldquo;&lt;em&gt;e&lt;/em&gt;&amp;ldquo;s don&amp;rsquo;t need to be consecutive, but you should not disallow consecutive &amp;ldquo;&lt;em&gt;e&lt;/em&gt;&amp;ldquo;s either.)&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints
&lt;/summary&gt;
&lt;p&gt;Use &lt;code&gt;.*&lt;/code&gt; to allow for &lt;em&gt;optional&lt;/em&gt; characters in between the &amp;ldquo;e&amp;quot;s.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bakers&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;baker_full&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;e.*e.*e.*e&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/ex1.png&#34; width=&#34;30%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;p&gt;In the &lt;code&gt;signatures&lt;/code&gt; vector, match words of exactly five characters that start with &amp;ldquo;&lt;em&gt;Ta&lt;/em&gt;&amp;rdquo;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints
&lt;/summary&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To describe the five-letter word you should include three word characters after &amp;ldquo;&lt;em&gt;Ta&lt;/em&gt;&amp;rdquo;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To exclusively match five-letter words, you should use the &amp;ldquo;word boundary&amp;rdquo; anchor before and after the part that should match the word.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\bTa\\w&amp;#123;3&amp;#125;\\b&#34;&lt;/span&gt;, match &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/ex2.png&#34; width=&#34;75%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;p&gt;Match &amp;ldquo;&lt;em&gt;Donut&lt;/em&gt;&amp;rdquo; as well as &amp;ldquo;&lt;em&gt;Doughnut&lt;/em&gt;&amp;rdquo; in the &lt;code&gt;signatures&lt;/code&gt; vector.&lt;/p&gt;
&lt;p&gt;Unfortunately, &lt;code&gt;signatures&lt;/code&gt; only contains the spelling &amp;ldquo;Doughnut&amp;rdquo;. Therefore, you should separately test whether your regex would actually match &amp;ldquo;Donut&amp;rdquo;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints
&lt;/summary&gt;
&lt;p&gt;Since &amp;ldquo;&lt;em&gt;donut&lt;/em&gt;&amp;rdquo; is contained within &amp;ldquo;&lt;em&gt;doughnut&lt;/em&gt;&amp;rdquo;, you can build a single regex and use &lt;strong&gt;&lt;a href=&#34;https://rdrr.io/r/utils/Question.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;?&lt;/code&gt;&lt;/a&gt;&lt;/strong&gt; to indicate optional characters.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Dou?g?h?nut&#34;&lt;/span&gt;, match&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/ex3_1.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;signatures&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Donut&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Dou?g?h?nut&#34;&lt;/span&gt;, match&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/ex3_2.png&#34; width=&#34;90%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;p&gt;Match both dates in the string: &amp;ldquo;&lt;em&gt;The best cakes were baked between 2016-03-10 and 2017-08-31.&lt;/em&gt;&amp;rdquo;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints
&lt;/summary&gt;
&lt;p&gt;Make sure you use &lt;code&gt;str_view_all()&lt;/code&gt; and not &lt;code&gt;str_view()&lt;/code&gt;!&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;mystring&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;The best cakes were baked between 2016-03-10 and 2017-08-31.&#34;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;str_view_all&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mystring&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;\\d&amp;#123;4&amp;#125;-\\d&amp;#123;2&amp;#125;-\\d&amp;#123;2&amp;#125;&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;p&gt;&lt;img src=&#34;img/ex4.png&#34; width=&#34;80%&#34; style=&#34;display: block; margin: auto auto auto 0;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;bonus-exercise&#34;&gt;Bonus exercise&lt;/h3&gt;
&lt;p&gt;You can use the &lt;a href=&#34;https://rdrr.io/r/base/list.files.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;list.files()&lt;/code&gt;&lt;/a&gt; function in R to list files on your computer. &lt;a href=&#34;https://rdrr.io/r/base/list.files.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;list.files()&lt;/code&gt;&lt;/a&gt; takes an argument &lt;code&gt;pattern&lt;/code&gt; to which you can specify a regular expression in order to narrow down the results.&lt;/p&gt;
&lt;p&gt;For example, the code below would find all files with &amp;ldquo;&lt;em&gt;codeclub&lt;/em&gt;&amp;rdquo; in the name, from your current working directory (the default for the &lt;code&gt;path&lt;/code&gt; argument) and downwards (due to &lt;code&gt;recursive = TRUE&lt;/code&gt;):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.files.html&#39;&gt;list.files&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;pattern &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;codeclub&#34;&lt;/span&gt;, recursive &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;You can also specify a path &amp;ndash; for instance, the code below would search your home or (on Windows) Documents directory and nothing below it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.files.html&#39;&gt;list.files&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;path &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;~&#34;&lt;/span&gt;, pattern &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;codeclub&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# &#34;~&#34; is your home dir&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.files.html&#39;&gt;list.files&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;path &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;C:/Users/myname/Documents&#34;&lt;/span&gt;, pattern &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;codeclub&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Use this function to list only R scripts, i.e. files &lt;em&gt;ending in&lt;/em&gt; &lt;code&gt;.R&lt;/code&gt;,&lt;/strong&gt; &lt;strong&gt;in a directory of your choice.&lt;/strong&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints
&lt;/summary&gt;
&lt;p&gt;Make sure to use the &amp;ldquo;end of string&amp;rdquo; anchor.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution
&lt;/summary&gt;
&lt;p&gt;Here we are searching the the home dir and everything below it &amp;ndash; could take a while, but then you know how many R scripts you actually have!&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.files.html&#39;&gt;list.files&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;path &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;~&#34;&lt;/span&gt;, pattern &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;\\.R$&#34;&lt;/span&gt;, recursive &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;8-further-resources&#34;&gt;8. Further resources&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://r4ds.had.co.nz/strings.html#strings&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;The chapter on strings&lt;/a&gt; in Hadley Wickham&amp;rsquo;s R for Data Science (freely abailable online!).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://www.rstudio.com/wp-content/uploads/2016/09/RegExCheatsheet.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;RStudio regex cheatsheet&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://www.youtube.com/watch?v=NvHjYOilOf8&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;A course video by Roger Peng introducing regular expressions&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://www.garrickadenbuie.com/project/regexplain&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;RegExplain&lt;/a&gt;, an RStudio add-in to visualize regex matches and help build regular expressions.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;Since R 4.0, which was released last year, there is also a &amp;ldquo;raw string&amp;rdquo; or &amp;ldquo;raw character constant&amp;rdquo; construct, which circumvents some of these problems &amp;ndash; see &lt;a href=&#34;https://mpopov.com/blog/2020/05/22/strings-in-r-4.x/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this blogpost&lt;/a&gt; that summarizes this new syntax. Because many are not yet using R 4.x, and most current examples, vignettes, and tutorials on the internet don&amp;rsquo;t use this, we will stick to being stuck with all the backslashes for now. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Session 16: lubridate</title>
      <link>https://biodash.github.io/codeclub/16_lubridate/</link>
      <pubDate>Wed, 31 Mar 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/16_lubridate/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New to Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/04_ggplot2/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll help you troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1-getting-set-up&#34;&gt;1. Getting set up&lt;/h2&gt;
&lt;p&gt;R has a range of functions that allow you to work with dates and times. However, today we will discuss how to work with dates and times in R using the package &amp;ldquo;&lt;em&gt;lubridate&lt;/em&gt;&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;While &lt;em&gt;lubridate&lt;/em&gt; is &lt;em&gt;tidyverse&lt;/em&gt;-style, it is not part of the core &lt;em&gt;tidyverse&lt;/em&gt;, so we need to install it.&lt;/p&gt;
&lt;p&gt;We are also going to use the bird data that was first discussed in Code Club session 1, and we will need to download that.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# If needed, install the lubridate package:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;lubridate&#34;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Load the tidyverse and lubridate:&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://lubridate.tidyverse.org&#39;&gt;lubridate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Create a dir for our bird data (&#34;recursive&#34; to create two levels at once):&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;data/birds/&#34;&lt;/span&gt;, recursive &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# The URL to our file:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_file_url&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/data/birds/backyard-birds_Ohio.tsv&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# The path to the file that we want to download the data to:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;data/birds/backyard-birds_Ohio.tsv&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Download:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file_url&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Read the data:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;file &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2-what-is-lubridate&#34;&gt;2. What is &lt;em&gt;lubridate&lt;/em&gt;?&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;lubridate&lt;/em&gt; provides tools that make it easier to parse and manipulate dates.&lt;/p&gt;
&lt;p&gt;We will discuss the common use of lubridate under the following themes:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Parsing dates&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Manipulating dates&lt;br&gt;
a) &lt;em&gt;Instants&lt;/em&gt;: Rounding dates, time zones&lt;br&gt;
b) &lt;em&gt;Time spans&lt;/em&gt;: Durations, periods, intervals&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3-parsing-dates&#34;&gt;3. Parsing dates&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;lubridate&lt;/em&gt;&amp;rsquo;s parsing functions read strings into R as &amp;ldquo;date-time&amp;rdquo; objects. Year is represented by &lt;code&gt;y&lt;/code&gt;, month by &lt;code&gt;m&lt;/code&gt;, and day by &lt;code&gt;d&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Strings can be parsed using the following functions: &lt;a href=&#34;http://lubridate.tidyverse.org/reference/ymd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dmy()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/ymd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;myd()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/ymd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ymd()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/ymd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ydm()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/ymd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dym()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/ymd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mdy()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/ymd_hms.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ymd_hms()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Let us look at some examples&lt;/em&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# parsing by year, month, day&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/ymd.html&#39;&gt;ymd&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;20170131&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2017-01-31&#34;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# parsing by month, day, year&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/ymd.html&#39;&gt;mdy&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;December 1st, 2020&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2020-12-01&#34;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# parsing by day, month, year&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/ymd.html&#39;&gt;dmy&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;01-Dec-2020&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2020-12-01&#34;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/ymd.html&#39;&gt;dmy&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;01/Dec/2020&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2020-12-01&#34;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/ymd.html&#39;&gt;dmy&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;01Dec2020&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2020-12-01&#34;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# parsing by year, month, day, hour, minutes, and seconds&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/ymd_hms.html&#39;&gt;ymd_hms&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;2020-01-31 20:11:59&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2020-01-31 20:11:59 UTC&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4-manipulating-dates-instants&#34;&gt;4. Manipulating dates: Instants&lt;/h2&gt;
&lt;p&gt;&lt;em&gt;lubridate&lt;/em&gt; distinguishes between &lt;em&gt;moments&lt;/em&gt; in time (instants) and &lt;em&gt;spans&lt;/em&gt; of time (time spans).&lt;/p&gt;
&lt;p&gt;Instants are specific moments of time. They are a combination of measurements on different units (i.e, years, months, days, etc.).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://lubridate.tidyverse.org/reference/now.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;now()&lt;/code&gt;&lt;/a&gt; returns the current system time.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;http://lubridate.tidyverse.org/reference/now.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;today()&lt;/code&gt;&lt;/a&gt; returns the current system date.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The individual values for &lt;a href=&#34;http://lubridate.tidyverse.org/reference/now.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;now()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;http://lubridate.tidyverse.org/reference/now.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;today()&lt;/code&gt;&lt;/a&gt; units can be extracted from an instant and set with the accessor functions &lt;a href=&#34;http://lubridate.tidyverse.org/reference/second.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;second()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/minute.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;minute()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/hour.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;hour()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/day.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;day()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/day.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;yday()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/day.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mday()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/day.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;wday()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/week.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;week()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/month.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;month()&lt;/code&gt;&lt;/a&gt;, and &lt;a href=&#34;http://lubridate.tidyverse.org/reference/year.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;year()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Let us look at some examples&lt;/em&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Find the current system date using function today ()&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/now.html&#39;&gt;today&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2021-07-19&#34;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Find the current system time using function now ()&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;Now&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/now.html&#39;&gt;now&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;Now&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2021-07-19 20:54:27 EDT&#34;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Extract the day of the month from an object Now using function mday ()&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/day.html&#39;&gt;mday&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Now&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 19&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Extract the day of the week from an object Now using function wday()&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/day.html&#39;&gt;wday&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Now&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Extract the week of the year from an object Now using function week ()&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/week.html&#39;&gt;week&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Now&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 29&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Extract the month from an object Now using function month ()&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/month.html&#39;&gt;month&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Now&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 7&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Extract the year from an object Now using function year ()&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/year.html&#39;&gt;year&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Now&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2021&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;rounding-instants&#34;&gt;Rounding instants&lt;/h3&gt;
&lt;p&gt;Instants can be &lt;em&gt;rounded&lt;/em&gt; to a convenient unit using the functions &lt;a href=&#34;http://lubridate.tidyverse.org/reference/round_date.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ceiling_date()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/round_date.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;floor_date()&lt;/code&gt;&lt;/a&gt;, and &lt;a href=&#34;http://lubridate.tidyverse.org/reference/round_date.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;round_date()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;http://lubridate.tidyverse.org/reference/round_date.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ceiling_date()&lt;/code&gt;&lt;/a&gt; takes a date-time object and rounds it up to the nearest boundary of the specified time unit.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;http://lubridate.tidyverse.org/reference/round_date.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;round_date()&lt;/code&gt;&lt;/a&gt; takes a date-time object and time unit, and rounds it to the nearest value of the specified time unit.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;http://lubridate.tidyverse.org/reference/round_date.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;floor_date()&lt;/code&gt;&lt;/a&gt; takes a date-time object and rounds it down to the nearest boundary of the specified time unit.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Let us look at some examples&lt;/em&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/round_date.html&#39;&gt;ceiling_date&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Now&lt;/span&gt;, unit &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;minute&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2021-07-19 20:55:00 EDT&#34;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/round_date.html&#39;&gt;round_date&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Now&lt;/span&gt;, unit &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;minute&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2021-07-19 20:54:00 EDT&#34;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/round_date.html&#39;&gt;floor_date&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Now&lt;/span&gt;, unit &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;minute&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2021-07-19 20:54:00 EDT&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;time-zones&#34;&gt;Time zones&lt;/h3&gt;
&lt;p&gt;Naming time zones is challenging because everyday names of time zones tend to be ambiguous. For example, USA has EST, or Eastern Standard Time. However, both Australia and Canada also have EST!&lt;/p&gt;
&lt;p&gt;To avoid confusion, R uses the international standard IANA time zones. These use a consistent naming scheme &amp;ldquo;/&amp;rdquo;, typically in the form &lt;code&gt;&amp;lt;continent&amp;gt;/&amp;lt;city&amp;gt;&lt;/code&gt; (there are a few exceptions because not every country lies on a continent). Examples include &lt;code&gt;America/New_York&lt;/code&gt;, &lt;code&gt;Europe/Paris&lt;/code&gt;, and &lt;code&gt;Pacific/Auckland&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Unless otherwise specified, &lt;em&gt;lubridate&lt;/em&gt; always uses UTC. UTC (Coordinated Universal Time) is the standard time zone used by the scientific community and roughly equivalent to its predecessor GMT (Greenwich Mean Time).&lt;/p&gt;
&lt;p&gt;Example: &lt;a href=&#34;http://lubridate.tidyverse.org/reference/ymd_hms.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ymd_hms(&amp;quot;2021-03-27 11:54:54 EDT&amp;quot;, tz=&amp;quot;America/New_York&amp;quot;)&lt;/code&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;To find your current time zone, use the &lt;a href=&#34;https://rdrr.io/r/base/timezones.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;Sys.timezone()&lt;/code&gt;&lt;/a&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/timezones.html&#39;&gt;Sys.timezone&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;America/New_York&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To see the complete list of all time zone names, use &lt;a href=&#34;https://rdrr.io/r/base/timezones.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;OlsonNames()&lt;/code&gt;&lt;/a&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# See the first four time zones in the list of the time zone&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/timezones.html&#39;&gt;OlsonNames&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Africa/Abidjan&#34;     &#34;Africa/Accra&#34;       &#34;Africa/Addis_Ababa&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [4] &#34;Africa/Algiers&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;em&gt;lubridate&lt;/em&gt; has two functions for working with time zones:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;http://lubridate.tidyverse.org/reference/with_tz.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;with_tz()&lt;/code&gt;&lt;/a&gt;: Changes the time zone in which an instant is displayed. The clock time displayed for the instant changes, but the moment of time described remains the same.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;http://lubridate.tidyverse.org/reference/force_tz.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;force_tz()&lt;/code&gt;&lt;/a&gt;: Changes only the time zone element of an instant. The clock time displayed remains the same, but the resulting instant describes a new moment of time.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/now.html&#39;&gt;now&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# An example using with_tz()&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x1a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/with_tz.html&#39;&gt;with_tz&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x1&lt;/span&gt;, tzone &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Australia/Lord_Howe&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;x1a&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Time difference of 0 secs&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Now use force_tz()&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x1b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/force_tz.html&#39;&gt;force_tz&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x1&lt;/span&gt;, tzone &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Australia/Lord_Howe&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;x1b&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Time difference of 14.5 hours&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4-manipulating-dates-time-spans&#34;&gt;4. Manipulating dates: Time spans&lt;/h2&gt;
&lt;p&gt;A timespan is a length of time that may or may not be connected to a particular instant. For example, two months is a timespan. &lt;em&gt;lubridate&lt;/em&gt; has three timespan classes: Durations, Periods and Intervals.&lt;/p&gt;
&lt;h3 id=&#34;durations&#34;&gt;Durations&lt;/h3&gt;
&lt;p&gt;Durations measure the exact amount of time that occurs between two instants.&lt;/p&gt;
&lt;p&gt;Functions for working with durations include &lt;a href=&#34;http://lubridate.tidyverse.org/reference/duration.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;is.duration()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/as.duration.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;as.duration()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;http://lubridate.tidyverse.org/reference/duration.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;duration()&lt;/code&gt;&lt;/a&gt;. For specific lengths, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/duration.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dseconds()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/duration.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dminutes()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/duration.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dhours()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/duration.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ddays()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/duration.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dweeks()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;http://lubridate.tidyverse.org/reference/duration.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dyears()&lt;/code&gt;&lt;/a&gt; convenient lengths.&lt;/p&gt;
&lt;h3 id=&#34;periods&#34;&gt;Periods&lt;/h3&gt;
&lt;p&gt;Periods measure the change in clock time that occurs between two instants.&lt;/p&gt;
&lt;p&gt;Functions for working with periods include &lt;a href=&#34;http://lubridate.tidyverse.org/reference/period.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;is.period()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/as.period.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;as.period()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;http://lubridate.tidyverse.org/reference/period.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;period()&lt;/code&gt;&lt;/a&gt;. &lt;a href=&#34;http://lubridate.tidyverse.org/reference/period.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;seconds()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/period.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;minutes()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/period.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;hours()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/period.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;days()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/period.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;weeks()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://rdrr.io/r/base/weekday.POSIXt.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;months()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;http://lubridate.tidyverse.org/reference/period.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;years()&lt;/code&gt;&lt;/a&gt; quickly create periods of convenient lengths.&lt;/p&gt;
&lt;h3 id=&#34;intervals&#34;&gt;Intervals&lt;/h3&gt;
&lt;p&gt;Intervals are timespans that begin at a specific instant and end at a specific instant. Intervals retain complete information about a timespan. They provide the only reliable way to convert between periods and durations.&lt;/p&gt;
&lt;p&gt;Functions for working with intervals include &lt;a href=&#34;http://lubridate.tidyverse.org/reference/interval.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;is.interval()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/as.interval.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;as.interval()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/interval.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;interval()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/interval.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;int_shift()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/interval.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;int_flip()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/interval.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;int_aligns()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/interval.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;int_overlaps()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Let us look at an example&lt;/em&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# John was born on 19841014. How old is John&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;h_age&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/now.html&#39;&gt;today&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/ymd.html&#39;&gt;ymd&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;19841014&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;h_age&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Time difference of 13427 days&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Time difference in years&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/as.duration.html&#39;&gt;as.duration&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;h_age&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;1160092800s (~36.76 years)&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;5-plotting-the-bird-data&#34;&gt;5. Plotting the bird data&lt;/h2&gt;
&lt;p&gt;We will plot the bird data using &lt;em&gt;ggplot2&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;First, we plot a bar graph of days of the week:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;Wday &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/day.html&#39;&gt;wday&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;eventDate&lt;/span&gt;, label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Wday&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_bar&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-11-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Second, we&amp;rsquo;ll plot the relative abundance of different bird orders by day of the week:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;Wday &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/day.html&#39;&gt;wday&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;eventDate&lt;/span&gt;, label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Wday&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;order&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_bar&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;6-breakout-rooms&#34;&gt;6. Breakout rooms!&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;Jane was born on January 31st, 1992. How old is Jane today?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use the functions &lt;a href=&#34;http://lubridate.tidyverse.org/reference/now.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;today()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;http://lubridate.tidyverse.org/reference/ymd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mdy()&lt;/code&gt;&lt;/a&gt;, and &lt;a href=&#34;http://lubridate.tidyverse.org/reference/as.duration.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;as.duration()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;Jane_age&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/now.html&#39;&gt;today&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/ymd.html&#39;&gt;mdy&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;January 31st, 1992&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/as.duration.html&#39;&gt;as.duration&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Jane_age&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;929836800s (~29.46 years)&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;p&gt;Calculate the time differences between the last four time zones with the current time.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You can get the last four time zones using the &lt;a href=&#34;https://rdrr.io/r/utils/head.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tail()&lt;/code&gt;&lt;/a&gt; function in combination with the &lt;a href=&#34;https://rdrr.io/r/base/timezones.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;OlsonNames()&lt;/code&gt;&lt;/a&gt; functions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Then, you can compare the current time (&lt;a href=&#34;http://lubridate.tidyverse.org/reference/now.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;now()&lt;/code&gt;&lt;/a&gt;) with times in different time zones using the &lt;a href=&#34;http://lubridate.tidyverse.org/reference/force_tz.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;force_tz()&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Current time &lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;C_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/now.html&#39;&gt;now&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Last four time zones&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;tail&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/timezones.html&#39;&gt;OlsonNames&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;UTC&#34;  &#34;W-SU&#34; &#34;WET&#34;  &#34;Zulu&#34;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Calculate time for UTC time zone &lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;UTC_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/force_tz.html&#39;&gt;force_tz&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;C_time&lt;/span&gt;, tzone &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;UTC&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Calculate time difference&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;C_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;UTC_time&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Time difference of 4 hours&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Calculate time for W-SU time zone &lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;WSU_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/force_tz.html&#39;&gt;force_tz&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;C_time&lt;/span&gt;, tzone &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;W-SU&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;WSU_time&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2021-07-19 20:54:29 MSK&#34;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Calculate time difference&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;C_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;WSU_time&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Time difference of 7 hours&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;C_time&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;2021-07-19 20:54:29 EDT&#34;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Calculate time for WET time zone &lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;WET_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/force_tz.html&#39;&gt;force_tz&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;C_time&lt;/span&gt;, tzone &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;WET&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Calculate time difference&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;C_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;WET_time&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Time difference of 5 hours&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Calculate time for Zulu time zone &lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;Zulu_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/force_tz.html&#39;&gt;force_tz&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;C_time&lt;/span&gt;, tzone &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Zulu&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Calculate time difference&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;C_time&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Zulu_time&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Time difference of 4 hours&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;bonus-exercise&#34;&gt;Bonus exercise&lt;/h3&gt;
&lt;p&gt;Remove the order &amp;ldquo;Passeriformes&amp;rdquo; from the bird data, and plot relative abundance of order based on days of the week.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use the functions &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;mutate()&lt;/code&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Remove Passeriformes:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;order&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;!=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Passeriformes&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Create the plot:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;Wday &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/day.html&#39;&gt;wday&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;eventDate&lt;/span&gt;, label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Wday&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;order&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_bar&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-15-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Session 15: Plotly</title>
      <link>https://biodash.github.io/codeclub/15_plotly/</link>
      <pubDate>Wed, 24 Mar 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/15_plotly/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;prep-homework&#34;&gt;Prep homework&lt;/h2&gt;
&lt;h3 id=&#34;basic-computer-setup&#34;&gt;Basic computer setup&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/04_ggplot2/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll help you troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;new-to-ggplot&#34;&gt;New to ggplot?&lt;/h3&gt;
&lt;p&gt;Check out the three Code Club pages for &lt;a href=&#34;https://biodash.github.io/codeclub/04_ggplot2/&#34;&gt;Session 4&lt;/a&gt;, &lt;a href=&#34;https://biodash.github.io/codeclub/05_ggplot-round-2/&#34;&gt;Session 5&lt;/a&gt; and &lt;a href=&#34;https://biodash.github.io/codeclub/10_faceting-animating/&#34;&gt;Session 10&lt;/a&gt; which are all about &lt;code&gt;ggplot2&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;ve never used &lt;code&gt;ggplot2&lt;/code&gt; before (or even if you have), you may find &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this cheat sheet&lt;/a&gt; useful.&lt;/p&gt;
&lt;br&gt;
&lt;h2 id=&#34;getting-started&#34;&gt;Getting Started&lt;/h2&gt;
&lt;h3 id=&#34;rmarkdown-for-todays-session&#34;&gt;RMarkdown for today&amp;rsquo;s session&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# directory for Code Club Session 15:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S15&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# directory for our RMarkdown&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# (&#34;recursive&#34; to create two levels at once.)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S15/Rmd/&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# save the url location for today&#39;s script&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;todays_Rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/15_plotly/Plotly-withOUT-answers.Rmd&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# indicate the name of the new Rmd&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;Session15_Rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;S15/Rmd/Session15_plotly.Rmd&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# go get that file! &lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;todays_Rmd&lt;/span&gt;,
              destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Session15_Rmd&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---what-is-plotly&#34;&gt;1 - What is plotly?&lt;/h2&gt;
&lt;p&gt;Today we are going to talk about making interactive plots using &lt;a href=&#34;https://plotly.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Plotly&lt;/a&gt;. Plotly exists in a variety of programming languages, but today we will be just talking about using it in &lt;a href=&#34;https://plotly.com/r/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R&lt;/a&gt;. All of the plotly documentation can be found &lt;a href=&#34;https://cran.r-project.org/web/packages/plotly/plotly.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you have never used &lt;code&gt;plotly&lt;/code&gt; before, install it with the code below.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;plotly&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here are some useful links to find info about using &lt;code&gt;ggplotly&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://plotly.com/ggplot2/#layout-options&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Basic ggplot2 charts&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://plotly.com/r/plotly-fundamentals/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Plotly R library fundamentals&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://plotly-r.com/overview.html#intro-ggplotly&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Intro to &lt;code&gt;ggplotly()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://plotly.com/r/reference/layout/#&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Using &lt;code&gt;layout()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://plotly-r.com/controlling-tooltips.html#tooltip-text-ggplotly&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplotly()&lt;/code&gt; tooltips&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Before we start, there are two basic ways to use plot in R using plotly:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Using &lt;a href=&#34;https://www.rdocumentation.org/packages/plotly/versions/4.9.3/topics/ggplotly&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplotly()&lt;/code&gt;&lt;/a&gt; - this is what we will go over today because it has the same syntax as &lt;code&gt;ggplot()&lt;/code&gt; which we have already learned&lt;/li&gt;
&lt;li&gt;Using &lt;a href=&#34;https://www.rdocumentation.org/packages/plotly/versions/4.9.3/topics/plot_ly&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;plot_ly()&lt;/code&gt;&lt;/a&gt; - there is slightly more functionality in this function, but the syntax is all new, so I&amp;rsquo;d suggest if you can do what you want with &lt;a href=&#34;https://docs.ropensci.org/plotly/reference/ggplotly.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplotly()&lt;/code&gt;&lt;/a&gt;, do that. The syntax is not particularly hard so don&amp;rsquo;t be scared to use it if interactive plots are something you&amp;rsquo;re very interested in.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When you are googling about using plotly, you will find a combination of &lt;a href=&#34;https://docs.ropensci.org/plotly/reference/ggplotly.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplotly()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://docs.ropensci.org/plotly/reference/plot_ly.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;plot_ly()&lt;/code&gt;&lt;/a&gt; approaches, and some parts of the code are interchangable. The easiesy way to see which parts are, is to try.&lt;/p&gt;
&lt;p&gt;Also note, Google gets a bit confused when googling &amp;ldquo;ggplotly&amp;rdquo; and often returns information about just ggplot, so read extra carefully when problem solving.&lt;/p&gt;
&lt;p&gt;This is an example of work from my group where we have found plotly to be particularly useful.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-397812645&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./apples.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-397812645&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt; Data from &lt;a href=&#34;https://www.biorxiv.org/content/10.1101/2021.02.18.431481v1&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Bilbrey et al., bioRxiv 2021&lt;/a&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2---load-libraries-get-data&#34;&gt;2 - Load libraries, get data&lt;/h2&gt;
&lt;p&gt;Lets load the libraries we are using for today.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://plotly-r.com&#39;&gt;plotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for making interactive plots&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/ramnathv/htmlwidgets&#39;&gt;htmlwidgets&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for saving html files&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for our penguins data&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s look at &lt;code&gt;penguins_raw&lt;/code&gt; this time, a df that has a bit more data than the &lt;code&gt;penguins&lt;/code&gt; df.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_raw&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 17&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   studyName `Sample Number` Species Region Island Stage `Individual ID`&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;               &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; PAL0708                 1 Adelie… Anvers Torge… Adul… N1A1           &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; PAL0708                 2 Adelie… Anvers Torge… Adul… N1A2           &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; PAL0708                 3 Adelie… Anvers Torge… Adul… N2A1           &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; PAL0708                 4 Adelie… Anvers Torge… Adul… N2A2           &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; PAL0708                 5 Adelie… Anvers Torge… Adul… N3A1           &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; PAL0708                 6 Adelie… Anvers Torge… Adul… N3A2           &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 10 more variables: `Clutch Completion` &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, `Date Egg` &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;date&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   `Culmen Length (mm)` &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, `Culmen Depth (mm)` &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, `Flipper Length&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   (mm)` &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, `Body Mass (g)` &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, Sex &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, `Delta 15 N (o/oo)` &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   `Delta 13 C (o/oo)` &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, Comments &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g sex  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;           &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.1          18.7              181        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;750 male &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.5          17.4              186        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;800 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Adelie  Torge…           40.3          18                195        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;250 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Adelie  Torge…           &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Adelie  Torge…           36.7          19.3              193        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;450 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.3          20.6              190        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;650 male &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1 more variable: year &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3---create-base-ggplot-object&#34;&gt;3 - Create base ggplot object&lt;/h2&gt;
&lt;p&gt;Using the &lt;code&gt;penguins_raw&lt;/code&gt; dataset and make a scatter plot with Culmen Length on the y, and Culmen Depth on the x.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_raw&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Length (mm)`&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Depth (mm)`&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-5-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4---make-it-interactive-with-ggplotly&#34;&gt;4 - Make it interactive with &lt;code&gt;ggplotly()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;You can learn more about the &lt;a href=&#34;https://docs.ropensci.org/plotly/reference/ggplotly.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplotly()&lt;/code&gt;&lt;/a&gt; function, including its arguments &lt;a href=&#34;https://www.rdocumentation.org/packages/plotly/versions/4.9.3/topics/ggplotly&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-267391584&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./penguins1.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-267391584&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Wow that was easy!&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s add a title and change the theme to make our plot a little prettier before we progress.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_raw&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Length (mm)`&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Depth (mm)`&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Understanding Penguin Bill Dimensions&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-681947325&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./penguins2.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-681947325&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;5---using-tooltip&#34;&gt;5 - Using tooltip&lt;/h2&gt;
&lt;p&gt;Using tooltip helps you to indicate what appears when you hover over different parts of your plot. You can learn more about controlling &lt;code&gt;tooltip&lt;/code&gt; &lt;a href=&#34;https://plotly-r.com/controlling-tooltips.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;What if we want to hover over each point and be able to tell which &lt;code&gt;Island&lt;/code&gt; the penguin was found on?&lt;/p&gt;
&lt;p&gt;To do this, we indicate what we want to hover with using &lt;code&gt;text =&lt;/code&gt; in our aesthetic mappings. Then, we indicate &lt;code&gt;tooltip = &amp;quot;text&amp;quot;&lt;/code&gt; to tell &lt;a href=&#34;https://docs.ropensci.org/plotly/reference/ggplotly.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplotly()&lt;/code&gt;&lt;/a&gt; what we want to hover.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_raw&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Length (mm)`&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Depth (mm)`&lt;/span&gt;,
             text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Understanding Penguin Bill Dimensions&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;,
         tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-482379516&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./penguins3.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-482379516&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You can play around a lot with tooltip to get it to be exactly how you want, and you can include multiple things in your hover text.&lt;/p&gt;
&lt;p&gt;You can also indicate to hover with data that is not inherently in your plot by mapping it to a &lt;code&gt;group&lt;/code&gt; aesthetic.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_raw&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Length (mm)`&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Depth (mm)`&lt;/span&gt;,
             text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Island&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Individual ID`&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Understanding Penguin Bill Dimensions&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;,
         tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Individual ID&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# hover test will be in this order&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: `group_by_()` was deprecated in dplyr 0.7.0.&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Please use `group_by()` instead.&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; See vignette(&#39;programming&#39;) for more help&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-518472936&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./penguins4.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-518472936&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;You may also want to paste in some text to your hover info to provide additional clarity on what you are showing.&lt;/p&gt;
&lt;p&gt;You can use &lt;code&gt;paste&lt;/code&gt; to add some information you&amp;rsquo;d like to see in each of the hover texts, here, we are indicating Island: &lt;code&gt;Island&lt;/code&gt;. You can also add multiple variables within text, and it will populate in the hover text in the way you indicate. There is an example of how to do this in Bonus 1.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_raw&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Length (mm)`&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Depth (mm)`&lt;/span&gt;,
             text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/paste.html&#39;&gt;paste&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Island:&#34;&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Understanding Penguin Bill Dimensions&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;,
         tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-581469723&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./penguins5.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-581469723&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;6---hover-label-aesthetics&#34;&gt;6 - Hover label aesthetics&lt;/h2&gt;
&lt;p&gt;You might not like the default hover text aesthetics, and can change them! You can do this using &lt;code&gt;style&lt;/code&gt; and &lt;code&gt;layout&lt;/code&gt; and adding these functions using the pipe &lt;a href=&#34;https://magrittr.tidyverse.org/reference/pipe.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;%&amp;gt;%&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# setting fonts for the plot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;font&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  family &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Roboto Condensed&#34;&lt;/span&gt;,
  size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;15&lt;/span&gt;,
  color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# setting hover label specs&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;label&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  bgcolor &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;#FF0000&#34;&lt;/span&gt;,
  bordercolor &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;transparent&#34;&lt;/span&gt;,
  font &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;font&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# we can do this bc we already set font&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# plotting like normal&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_raw&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Length (mm)`&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Depth (mm)`&lt;/span&gt;,
             text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/paste.html&#39;&gt;paste&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Island:&#34;&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;A Deep Dive (ha) Into \nUnderstanding Penguin Bill Dimensions&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# use\n to bring your text to another line&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# amending our ggplotly call to include new fonts and hover label specs&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;, tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/style.html&#39;&gt;style&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hoverlabel &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;label&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/layout.html&#39;&gt;layout&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;font &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;font&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-754981236&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./penguins6.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-754981236&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;7---dynamic-ticks&#34;&gt;7 - Dynamic ticks&lt;/h2&gt;
&lt;p&gt;Keep your axis labels so when you zoom, you can see where you are on your plot. Remember, you can zoom and pan around your plot!&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;,
         tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;,
         dynamicTicks &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-243978651&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./penguins7.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-243978651&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;8---animating&#34;&gt;8 - Animating&lt;/h2&gt;
&lt;p&gt;Add &lt;code&gt;frame&lt;/code&gt; in your aesthetics mapping to tell plotly what column to animate over. You can then play your animation, or toggle from one view to another.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# add frame&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_raw&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Length (mm)`&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Culmen Depth (mm)`&lt;/span&gt;,
             frame &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Island&lt;/span&gt;, text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;`Individual ID`&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Understanding Penguin Bill Dimensions&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;,
         tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-728546913&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./penguins8.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-728546913&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I know this plot isn&amp;rsquo;t animating &amp;ndash; for an animated version, &lt;a href=&#34;https://biodash.github.io/codeclub/15_plotly/Plotly-with-answers.html#23_Animating&#34;&gt;see this page&lt;/a&gt;. Also, if you do this in R yourself, you will find the code works.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;9---everything-you-know-about-ggplot-still-applies&#34;&gt;9 - Everything you know about &lt;em&gt;ggplot&lt;/em&gt; still applies!&lt;/h2&gt;
&lt;p&gt;Don&amp;rsquo;t forget you can use things like faceting, that we have gone over previously in &lt;a href=&#34;https://biodash.github.io/codeclub/10_faceting-animating/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Session 10&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
             text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/paste.html&#39;&gt;paste&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Island:&#34;&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Understanding Penguin Bill Dimensions&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Culmen Bill Length (mm)&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Culmen Bill Depth (mm)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;~&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;,
         tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-793652184&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./penguins9.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-793652184&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;10---saving-your-plots&#34;&gt;10 - Saving your plots&lt;/h2&gt;
&lt;p&gt;Now that you&amp;rsquo;ve made a beautiful interactive plot, you probably want to save it.&lt;/p&gt;
&lt;p&gt;Assign the plot you want to save to an object, and use the function &lt;a href=&#34;https://rdrr.io/pkg/htmlwidgets/man/saveWidget.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;saveWidget()&lt;/code&gt;&lt;/a&gt; to save it. You can find the documentation &lt;a href=&#34;https://www.rdocumentation.org/packages/htmlwidgets/versions/1.5.3/topics/saveWidget&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# assign ggplotly plot to an object&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;ggplotly_to_save&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_length&lt;/span&gt;,
                             tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# save&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/htmlwidgets/man/saveWidget.html&#39;&gt;saveWidget&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;widget &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ggplotly_to_save&lt;/span&gt;,
           file &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ggplotlying.html&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout rooms&lt;/h2&gt;
&lt;p&gt;We are going to use the birds dataset from previous weeks, and gapminder data for the bonus.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s grab the birds data.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# create directory for data to go&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;data/birds/&#39;&lt;/span&gt;, recursive &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# preparing to download&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# denote bird file url&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_url&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt;
&lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# denote file name&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# get file&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_url&lt;/span&gt;, 
              destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Read in data.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# read in birds data&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;file &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;──&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;font-weight: bold;&#39;&gt;Column specification&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #00BBBB;&#39;&gt;────────────────────────────────────────────────────────&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; cols(&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   order = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   family = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   genus = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   locality = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   stateProvince = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLatitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLongitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   eventDate = &lt;span style=&#39;color: #0000BB;&#39;&gt;col_datetime(format = &#34;&#34;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species_en = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   range = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; )&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Look at your new df.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 12&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class order family genus species locality stateProvince decimalLatitude&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Aves  Pass… Corvi… Cyan… Cyanoc… 44805 A… Ohio                     40.9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Aves  Pass… Corvi… Cyan… Cyanoc… 45244 C… Ohio                     39.1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Aves  Pass… Corvi… Cyan… Cyanoc… 44132 E… Ohio                     41.6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Aves  Pass… Corvi… Cyan… Cyanoc… 45242 C… Ohio                     39.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Aves  Pass… Corvi… Cyan… Cyanoc… 45246 C… Ohio                     39.3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Aves  Pass… Corvi… Cyan… Cyanoc… 44484 W… Ohio                     41.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 4 more variables: decimalLongitude &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, eventDate &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   species_en &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, range &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;For a knitted HTML with answers, you can also see &lt;a href=&#34;https://biodash.github.io/codeclub/15_plotly/Plotly-with-answers.html#31_Exercise_1&#34;&gt;this page&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Filter your new &lt;code&gt;birds&lt;/code&gt; df to only include bald eagles. Check to see how many bald eagle sightings there were in Ohio.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
Try using a [`filter()`](https://dplyr.tidyverse.org/reference/filter.html), and consider filtering based on `species_en` &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bald_eagle&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bald Eagle&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# what do we have?&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bald_eagle&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 12&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class order family genus species locality stateProvince decimalLatitude&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Aves  Acci… Accip… Hali… Haliae… Mentor   Ohio                     41.7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Aves  Acci… Accip… Hali… Haliae… 45742 L… Ohio                     39.3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Aves  Acci… Accip… Hali… Haliae… Morelan… Ohio                     41.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Aves  Acci… Accip… Hali… Haliae… Eastlake Ohio                     41.7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Aves  Acci… Accip… Hali… Haliae… 44060 M… Ohio                     41.7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Aves  Acci… Accip… Hali… Haliae… 44839 H… Ohio                     41.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 4 more variables: decimalLongitude &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, eventDate &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   species_en &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, range &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# check our df dimensions&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bald_eagle&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 381  12&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Create a map that plots all the bald eagles found around Ohio. Color the points blue. Make sure the aspect ratio of Ohio looks reasonable to you.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
Go back to Sessions [11](https://biodash.github.io/codeclub/11_ggplot-maps/) and [12](https://biodash.github.io/codeclub/12_loops/) to re-remember how maps work. Don&#39;t forget to call [`library(maps)`](https://rdrr.io/r/base/library.html). &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Attaching package: &#39;maps&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; The following object is masked from &#39;package:purrr&#39;:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     map&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# get map of the states&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;state&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# filter states to only include ohio&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;ohio&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://dplyr.tidyverse.org/reference/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;region&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ohio&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# plot&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio&lt;/span&gt;,
       &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;   
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bald_eagle&lt;/span&gt;,                 
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;decimalLongitude&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;decimalLatitude&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;blue&#34;&lt;/span&gt;, alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Bald Eagles Around Ohio&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-29-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Make your plot interactive so you can hover and and see the locality of each bald eagle observation.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
You may want to call `text` within `geom_point()`. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;bald_eagles_ohio&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio&lt;/span&gt;,
         &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;   
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bald_eagle&lt;/span&gt;,                 
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;decimalLongitude&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;decimalLatitude&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;,
                 text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;locality&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;blue&#34;&lt;/span&gt;, alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Bald Eagles Around Ohio&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bald_eagles_ohio&lt;/span&gt;,
         tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-697285134&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./ohio1.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-697285134&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Change the hover text so that the background color is red, clean up your axis labels, and make all the fonts for the plot Arial.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
You can set fonts either within your `ggplot()` call, or setting `font` within [`layout()`](https://docs.ropensci.org/plotly/reference/layout.html). You can customize the hover label with [`style()`](https://docs.ropensci.org/plotly/reference/style.html). &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# setting fonts for the plot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;eagle_font&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  family &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Arial&#34;&lt;/span&gt;,
  size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;15&lt;/span&gt;,
  color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# setting hover label specs&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;eagle_label&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  bgcolor &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;red&#34;&lt;/span&gt;,
  bordercolor &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;transparent&#34;&lt;/span&gt;,
  font &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;eagle_font&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# we can do this bc we already set font&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;bald_eagles_ohio&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio&lt;/span&gt;,
         &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;   
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bald_eagle&lt;/span&gt;,                 
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;decimalLongitude&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;decimalLatitude&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;,
                 text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;locality&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;blue&#34;&lt;/span&gt;, alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Bald Eagles Around Ohio&#39;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Latitude&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Longitude&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# amending our ggplotly call to include new fonts and hover label specs&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bald_eagles_ohio&lt;/span&gt;, tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/style.html&#39;&gt;style&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hoverlabel &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;eagle_label&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/layout.html&#39;&gt;layout&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;font &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;eagle_font&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-736592481&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./ohio2.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-736592481&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;bonus&#34;&gt;Bonus&lt;/h2&gt;
&lt;h3 id=&#34;bonus-1&#34;&gt;Bonus 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Let&amp;rsquo;s go back to the Gapminder data we looked at in the instructional part of &lt;a href=&#34;https://biodash.github.io/codeclub/10_faceting-animating/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Session 10&lt;/a&gt; on faceting, animating, and multi-plotting.&lt;/p&gt;
&lt;p&gt;Make a bubble-style plot that shows the life expectancy vs. GDP per capita over 1952 to 2007 for all countries. Color by continent, and indicate population by size. Use your knowledge of making plots to alter it such that you think it is descriptive and aesthetic.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Set &lt;code&gt;text&lt;/code&gt; to what you want to hover (try adding multiple variables in there!), play around with &lt;code&gt;theme&lt;/code&gt; and scaling, change fonts and aesthetics until you are pleased. You can download the &lt;code&gt;gapminder&lt;/code&gt; data like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;gapminder&#34;) # if you weren&#39;t at Session 10&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/jennybc/gapminder&#39;&gt;gapminder&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;gapminder&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country     continent  year lifeExp      pop gdpPercap&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Afghanistan Asia       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;952    28.8  8&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;425&lt;/span&gt;&lt;span&gt;333      779.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Afghanistan Asia       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;957    30.3  9&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;240&lt;/span&gt;&lt;span&gt;934      821.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Afghanistan Asia       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;962    32.0 10&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;267&lt;/span&gt;&lt;span&gt;083      853.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Afghanistan Asia       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;967    34.0 11&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;537&lt;/span&gt;&lt;span&gt;966      836.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Afghanistan Asia       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;972    36.1 13&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;079&lt;/span&gt;&lt;span&gt;460      740.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Afghanistan Asia       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;977    38.4 14&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;880&lt;/span&gt;&lt;span&gt;372      786.&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;gapminder_font&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  family &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Roboto Condensed&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;gapminder_bubble&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gapminder&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gdpPercap&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lifeExp&lt;/span&gt;, 
             fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;continent&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop&lt;/span&gt;, 
             text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/paste.html&#39;&gt;paste&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
               &lt;span class=&#39;s&#39;&gt;&#34;Country:&#34;&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;,
               &lt;span class=&#39;s&#39;&gt;&#34;\nLife expectancy:&#34;&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Round.html&#39;&gt;round&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;lifeExp&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
               &lt;span class=&#39;s&#39;&gt;&#34;\nGDP per capita:&#34;&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Round.html&#39;&gt;round&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;gdpPercap&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;frame &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;21&lt;/span&gt;, stroke &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;scale_x_log10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;plot.title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;18&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Changing Life Expectancy and GDP Per Capita Worldwide \nFrom 1952 to 2007&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;GDP per capita (in International Dollars)&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Life Expectancy (years)&#34;&lt;/span&gt;,
       fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;&#34;&lt;/span&gt;,
       size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/ggplotly.html&#39;&gt;ggplotly&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;gapminder_bubble&lt;/span&gt;, 
         tooltip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;text&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/plotly/reference/layout.html&#39;&gt;layout&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;font &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gapminder_font&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;

&lt;div id=&#34;chart-479153286&#34; class=&#34;chart&#34;&gt;&lt;/div&gt;
&lt;script&gt;
  (function() {
    let a = setInterval( function() {
      if ( typeof window.Plotly === &#39;undefined&#39; ) {
        return;
      }
      clearInterval( a );

      Plotly.d3.json(&#34;./gapminder.json&#34;, function(chart) {
        Plotly.plot(&#39;chart-479153286&#39;, chart.data, chart.layout, {responsive: true});
      });
    }, 500 );
  })();
&lt;/script&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; I know this plot isn&amp;rsquo;t animating &amp;ndash; for an animated version, &lt;a href=&#34;https://biodash.github.io/codeclub/15_plotly/Plotly-with-answers.html#4_Bonus&#34;&gt;see this page&lt;/a&gt;. Also, if you do this in R yourself, you will find the code works.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Session 14: Writing your own Functions</title>
      <link>https://biodash.github.io/codeclub/14_functions/</link>
      <pubDate>Tue, 16 Mar 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/14_functions/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New To Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has some pointers that might be helpful if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Please open RStudio before Code Club to test things out &amp;ndash; if you run into issues, join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Learn another way to avoid repetition in your code by creating your own functions.&lt;/li&gt;
&lt;li&gt;Learn the basic &lt;strong&gt;template&lt;/strong&gt; of a function in R.&lt;/li&gt;
&lt;li&gt;Learn to incorporate your own functions into &lt;code&gt;for&lt;/code&gt; loops and functionals like &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;map()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Learn all the advantages of using functions instead of copied code blocks.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;p&gt;We&amp;rsquo;ll be using &lt;code&gt;tibble()&lt;/code&gt; and &lt;code&gt;map()&lt;/code&gt; from the tidyverse packages, so we need to load that first.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching packages&lt;/span&gt;&lt;span&gt; ─────────────────────────────────────── tidyverse 1.3.0 ──&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2&lt;/span&gt;&lt;span&gt; 3.3.2     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;purrr  &lt;/span&gt;&lt;span&gt; 0.3.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;tibble &lt;/span&gt;&lt;span&gt; 3.0.4     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr  &lt;/span&gt;&lt;span&gt; 0.8.5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr  &lt;/span&gt;&lt;span&gt; 1.0.3     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stringr&lt;/span&gt;&lt;span&gt; 1.4.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;readr  &lt;/span&gt;&lt;span&gt; 1.3.1     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;forcats&lt;/span&gt;&lt;span&gt; 0.5.0&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt;&lt;span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt;&lt;span&gt; masks &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;&lt;span&gt;::filter()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;&lt;span&gt;    masks &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;&lt;span&gt;::lag()&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;why-write-functions&#34;&gt;Why write functions?&lt;/h2&gt;
&lt;h3 id=&#34;copying-your-code-is-not-good&#34;&gt;Copying your code is &lt;em&gt;not good&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;The first motivation for writing a function is when you find yourself cut-and-pasting code blocks with slight alterations each time.&lt;/p&gt;
&lt;p&gt;Say we have the following toy tidyverse data frame, where each column is a vector of 10 random numbers from a normal distribution, with &lt;code&gt;mean = 0&lt;/code&gt; and &lt;code&gt;sd = 1&lt;/code&gt; (the defaults for &lt;code&gt;rnorm&lt;/code&gt;):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;tibble&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  a &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  b &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  c &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
  d &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 10 x 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;         a      b       c       d&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt;  0.388  0.736  2.26   -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.302&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt;  1.19  -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.131&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;2.17&lt;/span&gt;&lt;span&gt;   -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.053&lt;/span&gt;&lt;span style=&#39;color: #BB0000;text-decoration: underline;&#39;&gt;7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt;  0.971  0.919  0.032&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;9&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.227&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.147&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;1.43&lt;/span&gt;&lt;span&gt;   1.15   -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;2.09&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt;  1.87   0.566 -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.935&lt;/span&gt;&lt;span&gt;   0.601 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;1.07&lt;/span&gt;&lt;span&gt;   0.941  1.56   -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.413&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt;  1.22   0.637  1.62    0.976 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.142&lt;/span&gt;&lt;span&gt;  1.02   1.98    1.22  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;2.02&lt;/span&gt;&lt;span&gt;   0.499 -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;1.93&lt;/span&gt;&lt;span&gt;   -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.091&lt;/span&gt;&lt;span style=&#39;color: #BB0000;text-decoration: underline;&#39;&gt;7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt;  0.177  0.347  1.79    1.55&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In previous Code Clubs we&amp;rsquo;ve seen how you can apply a built-in function like &lt;code&gt;median&lt;/code&gt; to each column using a &lt;code&gt;for&lt;/code&gt; loop or &lt;code&gt;lapply&lt;/code&gt;. But say we wanted to do something a bit fancier that is not part of core R. For example, we can &lt;em&gt;normalize&lt;/em&gt; the values in a column so they range from 0 to 1 using the following code block:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.6193844 0.8252053 0.7693140 0.4817556 1.0000000 0.2453463 0.8345409&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [8] 0.4828838 0.0000000 0.5650749&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This code is a literal translation of the mathematical formula for normalization:&lt;/p&gt;
&lt;p&gt;$$z_{i} = \frac{x_{i} - min(x)}{max(x)-min(x)}$$ OK, so how can we do this for each column? Here is a first attempt:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;min&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 10 x 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;        a       b      c     d&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; 0.619  0.301  1      0.491&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; 0.825 -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.053&lt;/span&gt;&lt;span style=&#39;color: #BB0000;text-decoration: underline;&#39;&gt;5&lt;/span&gt;&lt;span&gt; 0      0.559&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; 0.769  0.376  0.497  0.512&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; 0.482 -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.582&lt;/span&gt;&lt;span&gt;  0.749  0    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; 1      0.231  0.278  0.739&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; 0.245  0.384  0.843  0.461&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; 0.835  0.260  0.855  0.842&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; 0.483  0.418  0.938  0.910&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; 0      0.204  0.053&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt; 0.549&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; 0.565  0.142  0.895  1&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This works, but it caused me mental anguish to type it out. Even with cut and paste! All those manual textual substitutions!! And manual data entry is prone to mistakes, especially repetitive tasks like this. And say you had 1,000 columns&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;And it didn&amp;rsquo;t work!!&lt;/strong&gt; Honestly, I swear that mistake was totally real: I didn&amp;rsquo;t notice it until I looked at the output. Can you spot the mistake?&lt;/p&gt;
&lt;p&gt;It turns out R has a &lt;code&gt;range&lt;/code&gt; function that returns the minimum and maximum of a vector, which somewhat simplifies the coding:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The result is a vector something like &lt;a href=&#34;https://rdrr.io/r/base/c.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;c(-1.2129504, 2.1011248)&lt;/code&gt;&lt;/a&gt; (it varies run to run, since the columns values are random) which we can index, and so we only do the min/max computation once for each column, instead of three times, so we get the following block of code for each column:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Does this help?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Still pretty horrible, and arguably worse since we add a line for each column.&lt;/p&gt;
&lt;p&gt;How can we distill this into a function to avoid all that repetition?&lt;/p&gt;
&lt;h3 id=&#34;encapsulation-of-code-in-a-function&#34;&gt;Encapsulation of code in a function&lt;/h3&gt;
&lt;p&gt;The secret to function writing is abstracting the &lt;em&gt;constant&lt;/em&gt; from the &lt;em&gt;variable&lt;/em&gt;. (Using the &lt;code&gt;range&lt;/code&gt; function does throw into sharper relief what is constant and what is varying at least.) The constant part is the &lt;strong&gt;body&lt;/strong&gt; of the function: the template or boiler-plate you use over and over again. The variable parts are the &lt;strong&gt;arguments&lt;/strong&gt; of the function. We also need to give the function a &lt;strong&gt;name&lt;/strong&gt;, so we can call it and reuse it. The template for a function is then:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;name&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;function&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;arg1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;arg2...&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;o&#34;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;body&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;# do something with arg1, arg2&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The arguments go inside &lt;code&gt;(...)&lt;/code&gt;. The body is the block of code you want to reuse, and it&amp;rsquo;s contained in curly brackets &lt;code&gt;{...}&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s what it looks like in this case:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;normalize&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/range.html&#39;&gt;range&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;rng&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Pretty cool, right? Here &lt;code&gt;normalize&lt;/code&gt; is the descriptive name we give the function.&lt;/p&gt;
&lt;p&gt;We &lt;strong&gt;assign&lt;/strong&gt; the function to the name using &lt;a href=&#34;https://rdrr.io/r/base/assignOps.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;lt;-&lt;/code&gt;&lt;/a&gt; just like any other value. This means that now &lt;code&gt;normalize&lt;/code&gt; is a function object, just like you create vector objects, or list or data frame objects, when you assigned them to names. Notice too that in RStudio they appear in the Global Environment in a special section, and clicking on them shows the code. This means that if you have a large file of code with many functions defined, you don&amp;rsquo;t have to go back searching for the function definition in the code itself.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;environment_pane.jpg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;x&lt;/code&gt; is the &lt;strong&gt;argument&lt;/strong&gt; of the function. In the current case this is a data frame column vector, but we can potentially use this function on &lt;em&gt;any&lt;/em&gt; vector, so let&amp;rsquo;s not be too specific. The more generally you can write your function, the more useful it will be.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;test_vec&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;pi&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;8.657&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;80&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;test_vec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.000000000 0.051948052 0.001838866 0.073467532 1.000000000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;When we &lt;strong&gt;call&lt;/strong&gt; the function, the value we use in the function call is &lt;strong&gt;assigned&lt;/strong&gt; to &lt;code&gt;x&lt;/code&gt; and is &lt;strong&gt;passed in&lt;/strong&gt; to the body of the function. So if we call the function on the first column, it gets passed in to the body, and returns the result:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;tibble&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;a &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/Normal.html&#39;&gt;rnorm&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.8726863 1.0000000 0.8764474 0.5618469 0.6111361 0.4147958 0.2889830&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [8] 0.2683500 0.7181709 0.0000000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;A couple of things to note:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Including that extra line &lt;code&gt;rng &amp;lt;- range(x)&lt;/code&gt; is no longer a problem, since we just type it once. If you are typing things out over and over you might prefer brevity. &lt;em&gt;When you write a function, you should prefer clarity.&lt;/em&gt; It&amp;rsquo;s good practice to break the the function down into logical steps, and name them properly. It&amp;rsquo;s much easier for others to &amp;lsquo;read&amp;rsquo; your function, and much easier for you when you come back to it in a couple of years. This is the principle of making your code &amp;lsquo;self-annotated&amp;rsquo;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Functions should be simple, clear, and do &lt;em&gt;one thing well&lt;/em&gt;. You create programs by combining simple functions in a modular manner.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;There&amp;rsquo;s something very important but rather subtle about this use of the argument. As noted in &lt;a href=&#34;https://biodash.github.io/codeclub/12_loops/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CodeClub 12&lt;/a&gt;, once a &lt;code&gt;for&lt;/code&gt; loop completes, the variable you&amp;rsquo;re using &lt;em&gt;keeps the value it had&lt;/em&gt; at the last iteration of the loop, which persists in the global environment. Below we&amp;rsquo;ll compare that behavior to what happens with the function&amp;rsquo;s &lt;code&gt;x&lt;/code&gt; argument.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Our original horrible code can now be rewritten as:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;c&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;d&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Which is an improvement, but the real power comes from the fact that we can use our new function in &lt;code&gt;for&lt;/code&gt; loops and &lt;code&gt;apply&lt;/code&gt; statements. Here is the data from the previous couple of Clubs:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;17&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;93&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;56&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;19&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;175&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;40&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;69&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;267&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;91&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;87&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;143&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;103&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;223&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;106&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;18&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;87&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;72&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;59&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s first sanity check that our new function behaves sensibly on these vectors:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.04942966 0.33840304 0.19771863 0.05703422 0.65019011 0.13688213&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [7] 0.24714829 1.00000000 0.00000000 0.33079848&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.37614679 0.63302752 0.44954128 1.00000000 0.46330275 0.05963303&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [7] 0.37614679 0.30733945 0.24770642 0.00000000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And while we&amp;rsquo;re here, let&amp;rsquo;s circle back to the assignment of the &lt;code&gt;x&lt;/code&gt; argument outside and inside the function. Below we first assign a value to &lt;code&gt;x&lt;/code&gt; outside the function; pass in a value to &lt;code&gt;x&lt;/code&gt; inside the function; then reevaluate &lt;code&gt;x&lt;/code&gt; outside the function call, to see what happens:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pi&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3.141593&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;             &lt;span class=&#39;c&#39;&gt;# inside the function, x &amp;lt;- dists_Mar5&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.37614679 0.63302752 0.44954128 1.00000000 0.46330275 0.05963303&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [7] 0.37614679 0.30733945 0.24770642 0.00000000&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3.141593&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Whatever value &lt;code&gt;x&lt;/code&gt; has outside the function does not affect, and is not affected by, the value of &lt;code&gt;x&lt;/code&gt; inside the function. In computer science terms we say the variable(s) used inside the function are &lt;strong&gt;local&lt;/strong&gt; to the function. They are freshly minted inside it, and safely destroyed before you leave it. So there is no chance of weird or unexpected conflicts with whatever variable values are set outside. In contrast, the variable in the for loop is &lt;strong&gt;global&lt;/strong&gt;. It &amp;lsquo;leaks out&amp;rsquo; from where you actually used it, with perhaps unforeseen consequences. This is extremely important when you start embedding your own functions in larger programs.&lt;/p&gt;
&lt;h3 id=&#34;default-values-for-arguments&#34;&gt;Default values for arguments&lt;/h3&gt;
&lt;p&gt;In R, we can assign a default value for an argument using &lt;a href=&#34;https://rdrr.io/r/base/assignOps.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;=&lt;/code&gt;&lt;/a&gt; assignment. This means the argument will be called automatically, but can be overridden if explicitly called. First we create a function in the usual way:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;variable_power&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;  
  &lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;**&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;               &lt;span class=&#39;c&#39;&gt;# raises x to the power p&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;variable_power&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And now we create a version with a default value for the power:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;variable_power_2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;**&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;variable_power_2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;variable_power_2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;functions-in-for-loops&#34;&gt;Functions in &lt;code&gt;for&lt;/code&gt; loops&lt;/h3&gt;
&lt;p&gt;Here is how we can use our new function in a &lt;code&gt;for&lt;/code&gt; loop over a data frame. In our previous examples of &lt;code&gt;for&lt;/code&gt; loops &lt;code&gt;median&lt;/code&gt; was a summary statistic and we return a single value for each column, so we created an empty vector of the desired length to hold the values for each column. Here we want to modify the original data frame with the same dimensions and column names. The following code copies the original data frame (so we don&amp;rsquo;t destroy it) and then modifies the copy &amp;lsquo;in place&amp;rsquo;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dist_df_norm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;ncol&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;dist_df_norm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dist_df_norm&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dists_Mar4 dists_Mar5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1  0.04942966 0.37614679&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2  0.33840304 0.63302752&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3  0.19771863 0.44954128&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4  0.05703422 1.00000000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5  0.65019011 0.46330275&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6  0.13688213 0.05963303&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 7  0.24714829 0.37614679&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 8  1.00000000 0.30733945&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 9  0.00000000 0.24770642&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 10 0.33079848 0.00000000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Copying an entire data frame &lt;em&gt;could&lt;/em&gt; take a lot of time. So we can also create an empty data frame (of the same dimensions) and populate it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;empty_vec&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/vector.html&#39;&gt;vector&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;length &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dist_df_norm_2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;tibble&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;norm_Mar4 &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;empty_vec&lt;/span&gt;, norm_Mar5 &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;empty_vec&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;ncol&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;dist_df_norm_2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dist_df_norm_2&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 10 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    norm_Mar4 norm_Mar5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt;    0.049&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;4&lt;/span&gt;&lt;span&gt;    0.376 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt;    0.338     0.633 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt;    0.198     0.450 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt;    0.057&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;0&lt;/span&gt;&lt;span&gt;    1     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt;    0.650     0.463 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt;    0.137     0.059&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt;    0.247     0.376 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt;    1         0.307 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt;    0         0.248 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt;    0.331     0&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;By writing our own function, we&amp;rsquo;ve effectively extended what R can do. And this is all that packages are: libraries of new functions that extend the capabilities of base R. In fact, if there are functions you design for your particular subject area and find yourself using all the time, you can make your own package and load it, and all your favorite functions will be right there (but that&amp;rsquo;s for another day&amp;hellip;)&lt;/p&gt;
&lt;h2 id=&#34;functional-programming-with-your-own-functions&#34;&gt;Functional programming with your own functions&lt;/h2&gt;
&lt;p&gt;We saw above that you assign the function object to a name, just as you would a vector, list or data frame. In R, functions are &amp;lsquo;first class citizens&amp;rsquo;, which means you can &lt;strong&gt;pass them as arguments to another function&lt;/strong&gt;. This is a very powerful idea, and part of the program of &lt;strong&gt;functional programming&lt;/strong&gt; (we introduced this idea in &lt;a href=&#34;https://biodash.github.io/codeclub/13_apply/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Session 13&lt;/a&gt;):&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;In functional programming, functions are treated as first-class citizens, meaning that they can be bound to names&amp;hellip;, passed as arguments, and returned from other functions, just as any other data type can.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Functions that take other functions as arguments are sometimes referred to as &lt;strong&gt;functionals&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;In the previous session we showed how to use built-in functions like &lt;code&gt;median&lt;/code&gt; as arguments to functionals. The functions you write yourself can also be used in exactly the same way.&lt;/p&gt;
&lt;h3 id=&#34;lapply&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;We introduced this functional in &lt;a href=&#34;https://biodash.github.io/codeclub/13_apply/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Session 13&lt;/a&gt;: it always returns a list:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;lapply_norm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/lapply.html&#39;&gt;lapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;lapply_norm&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; $dists_Mar4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.04942966 0.33840304 0.19771863 0.05703422 0.65019011 0.13688213&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [7] 0.24714829 1.00000000 0.00000000 0.33079848&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $dists_Mar5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.37614679 0.63302752 0.44954128 1.00000000 0.46330275 0.05963303&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [7] 0.37614679 0.30733945 0.24770642 0.00000000&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;lapply_norm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;list&#34;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;lapply_norm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ dists_Mar4: num [1:10] 0.0494 0.3384 0.1977 0.057 0.6502 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ dists_Mar5: num [1:10] 0.376 0.633 0.45 1 0.463 ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sapply()&lt;/code&gt;&lt;/a&gt; attempts to simplify the outputs. Here both lists are of type &lt;code&gt;num&lt;/code&gt;, and the same length, so in this case R simplifies to a &lt;strong&gt;matrix&lt;/strong&gt; data structure with a single type:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;sapply_norm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/lapply.html&#39;&gt;sapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;sapply_norm&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;       dists_Mar4 dists_Mar5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1,] 0.04942966 0.37614679&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [2,] 0.33840304 0.63302752&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [3,] 0.19771863 0.44954128&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [4,] 0.05703422 1.00000000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [5,] 0.65019011 0.46330275&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [6,] 0.13688213 0.05963303&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [7,] 0.24714829 0.37614679&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [8,] 1.00000000 0.30733945&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [9,] 0.00000000 0.24770642&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [10,] 0.33079848 0.00000000&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sapply_norm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;double&#34;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sapply_norm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 10  2&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sapply_norm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  num [1:10, 1:2] 0.0494 0.3384 0.1977 0.057 0.6502 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  - attr(*, &#34;dimnames&#34;)=List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ : NULL&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ : chr [1:2] &#34;dists_Mar4&#34; &#34;dists_Mar5&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; yields a named list, &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sapply()&lt;/code&gt;&lt;/a&gt; yields a named matrix.&lt;/p&gt;
&lt;h3 id=&#34;purrrmap&#34;&gt;&lt;code&gt;purrr::map()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;The functional &lt;code&gt;map()&lt;/code&gt; from the &lt;strong&gt;purrr&lt;/strong&gt; package behaves the same as &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt;, it always returns a list (purrr is automatically loaded as part of the tidyverse):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;map_norm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;map_norm&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; $dists_Mar4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.04942966 0.33840304 0.19771863 0.05703422 0.65019011 0.13688213&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [7] 0.24714829 1.00000000 0.00000000 0.33079848&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $dists_Mar5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 0.37614679 0.63302752 0.44954128 1.00000000 0.46330275 0.05963303&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [7] 0.37614679 0.30733945 0.24770642 0.00000000&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;map_norm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;list&#34;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;map_norm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ dists_Mar4: num [1:10] 0.0494 0.3384 0.1977 0.057 0.6502 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ dists_Mar5: num [1:10] 0.376 0.633 0.45 1 0.463 ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice another advantage of both &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;map()&lt;/code&gt;: &lt;em&gt;we don&amp;rsquo;t need to explicitly preallocate any kind of data structure to collect the results&lt;/em&gt;. The allocation is done behind the scenes as part of the implementation of &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;map()&lt;/code&gt;, which makes sure they run efficiently. In fact, R implements these functionals as a &lt;code&gt;for&lt;/code&gt; loop behind the scenes, and in &lt;code&gt;map()&lt;/code&gt; that &lt;code&gt;for&lt;/code&gt; loop is implemented in C, so it optimizes performance.&lt;/p&gt;
&lt;p&gt;If we want the output to be a data frame to match the input, we can simply &lt;strong&gt;coerce&lt;/strong&gt; it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;map_norm_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;normalize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nv&#39;&gt;as_tibble&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;map_norm_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; tibble [10 × 2] (S3: tbl_df/tbl/data.frame)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ dists_Mar4: num [1:10] 0.0494 0.3384 0.1977 0.057 0.6502 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ dists_Mar5: num [1:10] 0.376 0.633 0.45 1 0.463 ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;advantages-of-using-functions&#34;&gt;Advantages of using functions&lt;/h3&gt;
&lt;p&gt;Functions:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;avoid duplication, save time&lt;/li&gt;
&lt;li&gt;avoid coding errors in repetitive code&lt;/li&gt;
&lt;li&gt;localize variables, avoiding unexpected assignment surprises&lt;/li&gt;
&lt;li&gt;let you modify code in a single place, not multiple places&lt;/li&gt;
&lt;li&gt;lets you reuse code, since a single function can often be used on multiple inputs (vectors, lists and data frames), and can be imported from a package, instead of copy and paste.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout rooms&lt;/h2&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;R does not have a built-in function for calculating the &lt;a href=&#34;https://en.m.wikipedia.org/wiki/Coefficient_of_variation&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;coefficient of variation&lt;/a&gt;, aka the &lt;strong&gt;RSD&lt;/strong&gt; (relative standard deviation). This is defined as &lt;em&gt;the ratio of the standard deviation to the mean&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Create a function that computes this, and test it on a couple of vectors.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;The relevant R built-ins are &lt;code&gt;sd()&lt;/code&gt; and &lt;code&gt;mean()&lt;/code&gt;. The function should have one argument, which is assumed to be a vector. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;cv&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;v&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/sd.html&#39;&gt;sd&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;v&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;/&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;v&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;cv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;200&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 0.5759123&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Write a function &lt;code&gt;equalish()&lt;/code&gt; which compares two numbers &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;, and checks if they are &amp;lsquo;equal enough&amp;rsquo; according to some threshold &lt;code&gt;epsilon&lt;/code&gt;. Set a &lt;strong&gt;default&lt;/strong&gt; threshold of 0.000001. The function should return TRUE if the absolute value of the difference is inside this threshold.&lt;/p&gt;
&lt;p&gt;Check that it works on a couple of test numbers.&lt;/p&gt;
&lt;p&gt;Now pass in a couple of test vectors. Is this new function vectorized?&lt;/p&gt;
&lt;p&gt;Now call the function explicitly with a different threshold.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;You&#39;ll need to use the absolute value function &lt;code&gt;abs()&lt;/code&gt;, and the logical comparison operator for &#34;less than&#34;. &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;equalish&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;epsilon&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.000001&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/MathFun.html&#39;&gt;abs&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;b&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;epsilon&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;equalish&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4.0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4.01&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] FALSE&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;equalish&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4.0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4.000000001&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] TRUE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;v1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4.000000001&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;v2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4.0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;equalish&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;v1&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;v2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  TRUE FALSE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;equalish&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;v1&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;v2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;0.000000000000001&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] FALSE FALSE&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;The &lt;a href=&#34;https://en.m.wikipedia.org/wiki/FASTQ_format&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;fastq&lt;/a&gt; file format for DNA sequencing uses a letter/punctuation code for the quality of the base called at each position (the fourth line below) which is in one-to-one relationship to the bases in the second line:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;@SIM:1:FCX:1:15:6329:1045 1:N:0:2
TCGCACTCAACGCCCTGCATATGACAAGACAGAATC
+
&amp;lt;&amp;gt;;##=&amp;gt;&amp;lt;9=AAAAAAAAAA9#:&amp;lt;#&amp;lt;;&amp;lt;&amp;lt;&amp;lt;????#=
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;To translate a letter code into a numerical &lt;a href=&#34;https://en.m.wikipedia.org/wiki/Phred_quality_score&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;phred quality score&lt;/a&gt; we have to do two things: (i) translate the &lt;strong&gt;character&lt;/strong&gt; to an &lt;strong&gt;integer&lt;/strong&gt; using the &lt;a href=&#34;http://www.asciitable.com&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ASCII code&lt;/a&gt; look up table (ii) subtract 33 from that value (!).&lt;/p&gt;
&lt;p&gt;For the first step, R has a function that converts a character into an integer according to that table, for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/utf8Conversion.html&#39;&gt;utf8ToInt&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;!&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 33&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Write a function &lt;code&gt;phred_score()&lt;/code&gt; that computes the phred score for any character. Check that it returns 0 for &amp;ldquo;!&amp;rdquo;.&lt;/p&gt;
&lt;p&gt;Apply your function to our example string&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;&amp;gt;;##=&amp;gt;&amp;lt;9=AAAAAAAAAA9#:&amp;lt;#&amp;lt;;&amp;lt;&amp;lt;&amp;lt;????#=&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;to convert it to phred quality scores.&lt;/p&gt;
&lt;p&gt;Mini Bonus: Why is &amp;ldquo;33&amp;rdquo; the magic number?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt;Remember when you pass the value to the function it has to be an R character string.&lt;/p&gt;
&lt;p&gt;Mini Bonus: look at the &lt;strong&gt;position&lt;/strong&gt; of &amp;ldquo;!&amp;rdquo; in the ASCII table linked above and its raw ASCII integer value. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;phred_score&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;character&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/utf8Conversion.html&#39;&gt;utf8ToInt&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;character&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;33&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;phred_score&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;&amp;lt;&amp;gt;;##=&amp;gt;&amp;lt;9=AAAAAAAAAA9#:&amp;lt;#&amp;lt;;&amp;lt;&amp;lt;&amp;lt;????#=&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 27 29 26  2  2 28 29 27 24 28 32 32 32 32 32 32 32 32 32 32 24  2 25 27  2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [26] 27 26 27 27 27 30 30 30 30  2 28&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&amp;ldquo;!&amp;rdquo; is the first &lt;strong&gt;printing character&lt;/strong&gt; in the ASCII table. The previous characters were used historically to control the behavior of teleprinters: &amp;ldquo;the original ASCII specification included 33 non-printing control codes which originated with Teletype machines; most of these are now obsolete&amp;rdquo;. If the ASCII table started with &amp;ldquo;!&amp;rdquo; we wouldn&amp;rsquo;t need the correction (!). &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Session 13: Applying The Apply Functions</title>
      <link>https://biodash.github.io/codeclub/13_apply/</link>
      <pubDate>Tue, 09 Mar 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/13_apply/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;List the functions in the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; family of functions from base R.&lt;/li&gt;
&lt;li&gt;Describe how the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; functions relate to loops in R.&lt;/li&gt;
&lt;li&gt;Identify the input and output formats associated with different &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; functions.&lt;/li&gt;
&lt;li&gt;Identify appropriate &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; functions for different scenarios.&lt;/li&gt;
&lt;li&gt;Use &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; functions to explore some US state temperature data.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;intro-the-apply-functions&#34;&gt;Intro: The &lt;code&gt;apply()&lt;/code&gt; Functions&lt;/h2&gt;
&lt;p&gt;R is sometimes referred to as a functional programming language, and the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; family of functions from base R is an example of this functional programming. Let&amp;rsquo;s first take a look at some available functions - they include&amp;hellip;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sapply()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/tapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tapply()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rdrr.io/r/base/mapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mapply()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Last week in &lt;a href=&#34;https://biodash.github.io/codeclub/12_loops/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;session 12&lt;/a&gt;, Jelmer introduced for loops as one method for iterating over some set of things in R. Let&amp;rsquo;s briefly revisit one of his examples. First, we&amp;rsquo;ll recreate his distance dataset&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#distance data (km) for two dates&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;17&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;93&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;56&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;19&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;175&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;40&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;69&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;267&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;91&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;87&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;143&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;103&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;223&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;106&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;18&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;87&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;72&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;59&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#view the data frame&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;    dists_Mar4 dists_Mar5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1          17         87&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2          93        143&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3          56        103&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4          19        223&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5         175        106&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6          40         18&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 7          69         87&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 8         267         72&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 9           4         59&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 10         91          5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As he showed, one way to get the median distance traveled for each day (column) is to iterate over each column with a for loop, applying the &lt;a href=&#34;https://rdrr.io/r/stats/median.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;median()&lt;/code&gt;&lt;/a&gt; function to each one&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#create object to store the loop output&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/vector.html&#39;&gt;vector&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;length &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;ncol&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#for loop to calculate median for each column&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;ncol&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## We extract one column using &#34;dataframe_name[[column_number]]&#34;:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;column_median&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/median.html&#39;&gt;median&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## We add the single-column median to its associated position&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## in the vector:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;column_median&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#view the result&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 62.5 87.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s think of this loop as the &amp;ldquo;programming&amp;rdquo; part of the functional programming I mentioned earlier - we&amp;rsquo;ve written, or programmed, some code the computer will execute for us - we&amp;rsquo;ll get to the &amp;ldquo;functional&amp;rdquo; part of functional programming shortly.&lt;/p&gt;
&lt;p&gt;Unless you&amp;rsquo;re brand new to R, you&amp;rsquo;ve probably realized by now that there are a few data structures you find yourself working with pretty frequently. These include data frames, matrices, and lists. Not only do these get used a lot, but there are also certain operations that get performed pretty frequently on each of those types of objects. For example, doing something like iterating over either the rows or columns of a data frame and applying some function to each, like we did with the median function in the data frame above, is pretty common. That means lots of people would end up independently writing for loops that would look a lot like the one in our example. This is where the &amp;ldquo;functional&amp;rdquo; part of &amp;ldquo;functional programming&amp;rdquo; starts to come in. Instead of everyone independently writing that same basic loop over and over, it can be written one time in a general form and packaged into a function that can be called instead. And this is what the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; functions do. Then, going one step further, functional programming allows us to pass individual functions as arguments to other functions, as we&amp;rsquo;re going to see shortly. Let&amp;rsquo;s take a look at some examples.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;h3 id=&#34;apply&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;We&amp;rsquo;ll start with the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; function, which we can use to iterativey apply some function to the margins (rows or columns) of an object that has &amp;ldquo;row by column&amp;rdquo;&amp;quot; structure. There are three arguments that have to be passed to &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; - the object containing the data, the margin the function will be applied to (rows are designated with &amp;lsquo;1&amp;rsquo;, columns with &amp;lsquo;2&amp;rsquo;), and the function of interest.&lt;/p&gt;
&lt;p&gt;In the example above, we used a loop to apply the &lt;a href=&#34;https://rdrr.io/r/stats/median.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;median()&lt;/code&gt;&lt;/a&gt; function to each column of the data frame. Here, we&amp;rsquo;ll do the same thing with &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt;, by passing the &lt;a href=&#34;https://rdrr.io/r/stats/median.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;median()&lt;/code&gt;&lt;/a&gt; function as an argument to &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt;&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;apply_out&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/apply.html&#39;&gt;apply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;median&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#view the result&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;apply_out&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; dists_Mar4 dists_Mar5 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;       62.5       87.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice how much less code it required here to do the same thing we did with the for loop above!&lt;/p&gt;
&lt;p&gt;Notice too that the output here is a vector (specifically, a named numeric vector). The &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; function determined this was most appropriate in this case, since the output of each iteration consisted of a single value. Here&amp;rsquo;s another scenario&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;apply_out_quantiles&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/apply.html&#39;&gt;apply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;, 
                             &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, 
                             &lt;span class=&#39;nv&#39;&gt;quantile&lt;/span&gt;, 
                             probs &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0.25&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;0.75&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#view the result&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;apply_out_quantiles&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;     dists_Mar4 dists_Mar5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 25%      24.25      62.25&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 50%      62.50      87.00&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 75%      92.50     105.25&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This time, the function output consisted of 3 values for each iteration, or column of the data frame. In this case, the output from apply is a matrix.&lt;/p&gt;
&lt;p&gt;A quick additional note about how the function above is structured. In it, we applied the &lt;a href=&#34;https://rdrr.io/r/stats/quantile.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;quantile()&lt;/code&gt;&lt;/a&gt; function to each column, passing the &lt;em&gt;probs&lt;/em&gt; argument to it to define the specific quantiles we wanted it to return. If we were running &lt;a href=&#34;https://rdrr.io/r/stats/quantile.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;quantile()&lt;/code&gt;&lt;/a&gt; by itself (not in the context of &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt;), it might look like this&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/quantile.html&#39;&gt;quantile&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt;, probs &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0.25&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;0.50&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;0.75&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   25%   50%   75% &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 24.25 62.50 92.50&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice the slight difference in how the &lt;em&gt;probs&lt;/em&gt; argument is passed to the &lt;a href=&#34;https://rdrr.io/r/stats/quantile.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;quantile()&lt;/code&gt;&lt;/a&gt; function here versus inside the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; function above. Here, &lt;em&gt;probs&lt;/em&gt; is inside a set of parentheses associated with the function. But inside the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; function, any arguments associated with the function get passed as a separate argument (separated from the function by a comma). If you check out the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; documentation, this is indicated with the &amp;ldquo;&amp;hellip;&amp;rdquo; argument, which is described as &amp;ldquo;optional arguments to FUN&amp;rdquo;. You&amp;rsquo;ll see this kind of thing show up in other functions too.&lt;/p&gt;
&lt;p&gt;So, what about the other types of &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; functions? Well, the different types are designed for different types of input. For example&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;lapply&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;Remember that &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; requires you to define whether you&amp;rsquo;ll apply the function in a row-wise or column-wise manner. But lists aren&amp;rsquo;t set up as rows and columns. So, if we want to iterate over the elements of a list, &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; won&amp;rsquo;t work. An alternative is &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;In the next example, we&amp;rsquo;ll add some new distance data in for two additional dates. The number of observations are different this time though, so the data can&amp;rsquo;t be combined in a data frame (you might remember that a data frame is a special kind of list where each of the list elements are the same length). Since we have different lengths here, we&amp;rsquo;ll store the data as a list&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#create a list that includes the new distance data&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;dists_Mar11&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;45&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;34&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;40&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;29&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;88&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;84&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;102&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dists_Mar12&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;90&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;19&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;123&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;77&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;13&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;70&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;dist_ls&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dists_Mar11&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dists_Mar12&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#view the list&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dist_ls&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  17  93  56  19 175  40  69 267   4  91&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  87 143 103 223 106  18  87  72  59   5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[3]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  45  34 100  40  29  88  84 102&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[4]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  90  50  19 123  77  13  70&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now we&amp;rsquo;ll apply the &lt;a href=&#34;https://rdrr.io/r/stats/median.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;median()&lt;/code&gt;&lt;/a&gt; function to each element of the list. Again, we could write a for loop to iterate over each list element, but &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; will do the same thing with much less code to write&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;lapply_out&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/lapply.html&#39;&gt;lapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_ls&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;median&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#view the output&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;lapply_out&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 62.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 87&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[3]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 64.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[4]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 70&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This time, the output is a list - &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; always gives output in list format. But in this specific case, the output could just as easily (and maybe more simply) be stored as a vector of four values - one for each list element. &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sapply()&lt;/code&gt;&lt;/a&gt; is an alternative to &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; that, like &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt; still works on list input, but that attempts to simplify the output where possible&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;sapply&#34;&gt;&lt;code&gt;sapply()&lt;/code&gt;&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;sapply_out&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/lapply.html&#39;&gt;sapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_ls&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;median&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#view the output&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;sapply_out&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 62.5 87.0 64.5 70.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Those three: &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;lapply()&lt;/code&gt;&lt;/a&gt;, and &lt;a href=&#34;https://rdrr.io/r/base/lapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sapply()&lt;/code&gt;&lt;/a&gt; are the apply functions you&amp;rsquo;ll likely encounter most frequently, but there are others that apply in more specific cases - we&amp;rsquo;ll take a look at at least one more later in the Bonus section.&lt;/p&gt;
&lt;br&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout Rooms&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;ll work with a new temperature dataset for the Breakout Room Exercises. I&amp;rsquo;ve filtered and cleaned these data from the original dataset that&amp;rsquo;s available from &lt;a href=&#34;ftp://ftp.ncdc.noaa.gov/pub/data/cirs/climdiv/&#34;&gt;climate.gov&lt;/a&gt; They consist of maximum average temperature values for three states - Colorado, Ohio, and Virginia, with years in rows and months in columns. You can download the data with this code&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;temp_url&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/data/temperature/co_oh_va_max_temp.txt&#39;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;temp_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;state_max_temps.tsv&#39;&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;temp_url&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;temp_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;First let&amp;rsquo;s load the dataset and assign it to an object named &amp;lsquo;maxtemps&amp;rsquo;. Then preview the dataset and determine its dimensions (number of rows and columns). As the &amp;lsquo;.tsv&amp;rsquo; extension on the file suggests, this is a tab delimited file.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;code&gt;read_tsv()&lt;/code&gt; to load the dataset. The functions &lt;a href=&#34;https://rdrr.io/r/utils/head.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;head()&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;glimpse()&lt;/code&gt; are a couple good options for previewing the data. If you don&amp;rsquo;t get the dimensions from the function you preview the data with, the &lt;a href=&#34;https://rdrr.io/r/base/dim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dim()&lt;/code&gt;&lt;/a&gt; function will provide this info. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;state_max_temps.tsv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Parsed with column specification:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; cols(&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   STATE = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   YEAR = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   JAN = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   FEB = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   MAR = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   APR = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   MAY = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   JUN = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   JUL = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   AUG = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   SEP = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   OCT = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   NOV = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   DEC = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; )&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 378&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 14&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ STATE &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;CO&#34;, &#34;CO&#34;, &#34;CO&#34;, &#34;CO&#34;, &#34;CO&#34;, &#34;CO&#34;, &#34;CO&#34;, &#34;CO&#34;, &#34;CO&#34;, &#34;CO&#34;, &#34;CO…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ YEAR  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 1895, 1896, 1897, 1898, 1899, 1900, 1901, 1902, 1903, 1904, 190…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ JAN   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 33.6, 41.2, 34.2, 32.6, 34.0, 40.8, 39.4, 38.4, 37.5, 36.6, 33.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ FEB   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 33.3, 41.3, 36.8, 43.4, 29.4, 39.1, 37.9, 43.2, 28.3, 47.3, 33.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ MAR   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 46.1, 44.8, 42.8, 43.5, 43.7, 51.9, 46.0, 44.3, 44.1, 51.4, 48.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ APR   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 60.8, 58.3, 55.8, 59.0, 58.7, 52.4, 55.5, 59.0, 55.6, 58.3, 53.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ MAY   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 66.5, 68.0, 70.5, 61.8, 66.5, 68.1, 67.6, 68.7, 63.8, 65.5, 61.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ JUN   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 74.0, 80.2, 77.4, 76.6, 77.2, 80.1, 76.8, 78.8, 69.8, 71.7, 77.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ JUL   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 77.7, 80.9, 82.0, 81.9, 80.2, 82.9, 86.7, 80.3, 80.9, 79.0, 79.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AUG   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 80.0, 81.2, 79.6, 82.0, 79.8, 81.9, 80.7, 80.8, 80.3, 77.8, 81.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SEP   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 75.7, 70.1, 75.2, 72.2, 74.9, 70.2, 72.7, 72.3, 70.0, 72.2, 73.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ OCT   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 60.3, 59.2, 59.8, 57.7, 58.0, 62.9, 63.1, 61.8, 62.4, 60.2, 57.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ NOV   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 42.3, 42.8, 48.5, 43.0, 50.5, 49.3, 52.9, 46.7, 49.7, 53.0, 48.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ DEC   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 33.9, 43.1, 33.4, 30.9, 35.0, 41.5, 38.6, 36.4, 41.8, 39.8, 35.…&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 378  14&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;The dataset is currently in tibble form. This is the default object type created by the &lt;code&gt;read_tsv()&lt;/code&gt; command from &lt;em&gt;readr&lt;/em&gt; (common in tidy workflows). The apply functions are not associated with the tidyverse, and it turns out they sometimes don&amp;rsquo;t work well with tibbles. So, before we go any further, let&amp;rsquo;s convert the tibble to a data frame.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;Use the &lt;a href=&#34;https://rdrr.io/r/base/as.data.frame.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;as.data.frame()&lt;/code&gt;&lt;/a&gt; function to convert the tibble to a data frame.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/as.data.frame.html&#39;&gt;as.data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;class&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;data.frame&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Calculate the average temperature for each month across the whole dataset (using the data for all three states together).&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Choose an appropriate function from the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; family of functions and use the &lt;a href=&#34;https://rdrr.io/r/base/mean.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mean()&lt;/code&gt;&lt;/a&gt; function to calculate the mean value for each column of temperatures in the dataset (cols 3 through 14). Remember that when you&amp;rsquo;re designating the margin to apply the function to, &amp;lsquo;1&amp;rsquo; means rows and &amp;lsquo;2&amp;rsquo; means columns. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;mean_monthly&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/apply.html&#39;&gt;apply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#OR&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;mean_monthly&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/lapply.html&#39;&gt;sapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#Remember that a data frame is just a special case of a list (one that&#39;s structured in rows and columns), so either `apply()` or `sapply()` will work here&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#view results&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mean_monthly&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;      JAN      FEB      MAR      APR      MAY      JUN      JUL      AUG &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 38.89206 41.93598 50.73148 61.35608 71.26111 79.95503 84.17460 82.23571 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      SEP      OCT      NOV      DEC &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 75.92857 64.56296 51.49921 41.11508&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now let&amp;rsquo;s get the average annual (max) temperatures for Ohio for all the years available in the dataset (1895-2020) and view the temperatures for the first 5 years of the dataset (1895-1899). Since it&amp;rsquo;s not really obvious what each of these values correspond to, try converting this vector to a named vector with the years serving as the names.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use the same &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://rdrr.io/r/base/mean.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mean()&lt;/code&gt;&lt;/a&gt; functions as above, but this time, filter the dataset for just the &amp;ldquo;OH&amp;rdquo; entries, and also apply the function by rows. Remember that a two-dimensional object like a data frame or matrix is indexed with the form [rows, columns]. Alternatively, you can use tidy notation (i.e. filter, select). Then index the resulting vector with the square bracket notation &lt;a href=&#34;https://biodash.github.io/codeclub/09_subsetting/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;(Session 9)&lt;/a&gt; to get the first five items. The &lt;a href=&#34;https://rdrr.io/r/base/names.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;names()&lt;/code&gt;&lt;/a&gt; function will allow you to add names to the vector elements.&lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#base R indexing...&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mean_annual_oh&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/apply.html&#39;&gt;apply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;STATE&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;OH&#34;&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#OR &lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#a more tidy approach (actually a hybrid approach here - the apply function is still base R)...&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mean_annual_oh&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;STATE&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;OH&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;JAN&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;DEC&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/apply.html&#39;&gt;apply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#view first 5 items&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mean_annual_oh&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 60.23333 60.74167 61.20833 61.42500 61.59167&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#add names to the vector&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/names.html&#39;&gt;names&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mean_annual_oh&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1895&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2020&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#view first 5 items&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mean_annual_oh&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;     1895     1896     1897     1898     1899 &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 60.23333 60.74167 61.20833 61.42500 61.59167&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-1&#34;&gt;Bonus 1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;What if we wanted to compare the mean max July temperatures for each of the three states? Use an appropriate &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; function to calculate the mean values for July separately for CO, OH, and VA.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; &lt;a href=&#34;https://rdrr.io/r/base/tapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tapply()&lt;/code&gt;&lt;/a&gt; allows you to apply a function to subsets of a vector that are defined by a set of grouping variables (factors). Check the help page for &lt;a href=&#34;https://rdrr.io/r/base/tapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tapply()&lt;/code&gt;&lt;/a&gt; and use the &amp;ldquo;STATE&amp;rdquo; column as the grouping factor. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/tapply.html&#39;&gt;tapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;,&lt;span class=&#39;s&#39;&gt;&#34;JUL&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;STATE&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;       CO       OH       VA &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 82.25238 84.53810 85.73333&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-2&#34;&gt;Bonus 2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now, instead of focusing on just July, let&amp;rsquo;s try to get the average max temperatures for each month for each of the three states separately.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hint 1 (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; The &lt;a href=&#34;https://rdrr.io/r/base/tapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tapply()&lt;/code&gt;&lt;/a&gt; function we used in Exercise 4 only works when the input is a single vector. Look toward the end of the &lt;a href=&#34;https://rdrr.io/r/base/tapply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tapply()&lt;/code&gt;&lt;/a&gt; documentation for a suggested related function that might apply here. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Hint 2 (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Give the &lt;a href=&#34;https://rdrr.io/r/stats/aggregate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;aggregate()&lt;/code&gt;&lt;/a&gt; function a try. Notice that the grouping variable (the &amp;ldquo;by&amp;rdquo; argument in the function) has to be provided in the form of a list. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/aggregate.html&#39;&gt;aggregate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maxtemps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;STATE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Group.1      JAN      FEB      MAR      APR      MAY      JUN      JUL&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1      CO 36.85238 40.45952 47.44444 56.49762 66.00952 76.75238 82.25238&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2      OH 35.15476 37.99444 48.45238 61.05714 72.28571 80.70000 84.53810&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3      VA 44.66905 47.35397 56.29762 66.51349 75.48810 82.41270 85.73333&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;        AUG      SEP      OCT      NOV      DEC&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 79.99286 72.51508 60.87381 47.09365 37.73333&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 82.60952 76.72619 64.47778 50.32698 38.54365&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3 84.10476 78.54444 68.33730 57.07698 47.06825&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;purrr-an-alternative-tidy-approach-to-apply-functions&#34;&gt;Purrr: An Alternative (Tidy) Approach To &lt;code&gt;apply()&lt;/code&gt; Functions&lt;/h2&gt;
&lt;p&gt;In the second exercise, we converted back from a tibble to a data frame, as the &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; functions we&amp;rsquo;ve worked with here are part of base R, and some aren&amp;rsquo;t compatible with tibbles. It&amp;rsquo;s worth mentioning that there are &lt;em&gt;tidy&lt;/em&gt; alternatives to the apply functions - they&amp;rsquo;re part of the &lt;em&gt;purrr&lt;/em&gt; package, which might be the topic of a future code club session. We decided to go with &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt; in this session since there were a couple requests for it, and it still does get used enough that you&amp;rsquo;re likely to at least run across it, even if you don&amp;rsquo;t use it yourself. For now though, if you want more details on &lt;em&gt;purrr&lt;/em&gt; you can find them &lt;a href=&#34;https://purrr.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Session 12: Vectorization and loops in R</title>
      <link>https://biodash.github.io/codeclub/12_loops/</link>
      <pubDate>Mon, 01 Mar 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/12_loops/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;setup&#34;&gt;Setup&lt;/h2&gt;
&lt;h4 id=&#34;new-to-code-club&#34;&gt;New to Code Club?&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/04_ggplot2/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also have pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll help you troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;session-goals&#34;&gt;Session goals&lt;/h4&gt;
&lt;p&gt;Today, you will learn:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;That you should avoid copying your code.&lt;/li&gt;
&lt;li&gt;What different strategies for &lt;em&gt;iteration&lt;/em&gt; exist in R.&lt;/li&gt;
&lt;li&gt;What &lt;em&gt;vectorization&lt;/em&gt; is and how to make use of it.&lt;/li&gt;
&lt;li&gt;How to write a &lt;code&gt;for&lt;/code&gt; loop.&lt;/li&gt;
&lt;li&gt;Best practices when using &lt;code&gt;for&lt;/code&gt; loops.&lt;/li&gt;
&lt;li&gt;When you should (not) use &lt;code&gt;for&lt;/code&gt; loops.&lt;/li&gt;
&lt;li&gt;Bonus: &lt;code&gt;if&lt;/code&gt; statements.&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;h3 id=&#34;dont-repeat-yourself&#34;&gt;Don&amp;rsquo;t Repeat Yourself&lt;/h3&gt;
&lt;p&gt;Sometimes, you have a block of code and you need to repeat the operations in that code &lt;em&gt;almost&lt;/em&gt; exactly. For instance, you may want to rerun a statistical model with different parameter values, rerun an analysis for a different batch of samples, or extract the same information for many different genes.&lt;/p&gt;
&lt;p&gt;Your first instinct may be to copy-and-paste the block of code, and make the necessary slight adjustments in the pasted block. However, &lt;em&gt;&lt;strong&gt;iterating&lt;/strong&gt;&lt;/em&gt; and &lt;em&gt;&lt;strong&gt;writing your own functions&lt;/strong&gt;&lt;/em&gt; are strategies that are clearer, less error-prone, and more flexible (and these two can also be combined). When the number of repeats are high, &lt;em&gt;iteration&lt;/em&gt; is needed. When the code that needs to be repeated is more than a line or two, &lt;em&gt;writing your own functions&lt;/em&gt; becomes useful.&lt;/p&gt;
&lt;h3 id=&#34;iteration&#34;&gt;Iteration&lt;/h3&gt;
&lt;p&gt;&lt;em&gt;&lt;strong&gt;Loops&lt;/strong&gt;&lt;/em&gt; are the most universal iteration tool and the one we will focus on today. However, R has &amp;ldquo;functional programming&amp;rdquo; iteration methods that are less verbose and that can also be quicker to execute. These are the &lt;code&gt;apply&lt;/code&gt; family of functions, and a more recent &lt;em&gt;tidyverse&lt;/em&gt; approach implemented in the &lt;em&gt;purrr&lt;/em&gt; package: we will learn more about those in the two upcoming Code Club sessions.&lt;/p&gt;
&lt;p&gt;Loops are still a very good place to start using iteration because they make the iteration explicit and are therefore more intuitive than functional alternatives. In addition, they can easily accommodate longer blocks of code without the need to &lt;em&gt;also&lt;/em&gt; write your own function.&lt;/p&gt;
&lt;p&gt;Today, we will talk about the most common type of loop: the &lt;code&gt;for&lt;/code&gt; loops. (Other types of loops in R are &lt;code&gt;while&lt;/code&gt; loops and &lt;code&gt;repeat&lt;/code&gt; loops. Related to loops are &lt;code&gt;if&lt;/code&gt; statements, see the &lt;a href=&#34;#bonus-exercise-if-statements&#34;&gt;bonus exercise&lt;/a&gt; for some basics.)&lt;/p&gt;
&lt;h4 id=&#34;but-first&#34;&gt;But first&amp;hellip;&lt;/h4&gt;
&lt;p&gt;Before we tackle loops we should take a step back and explore &lt;em&gt;&lt;strong&gt;vectorization&lt;/strong&gt;&lt;/em&gt; a bit more, which was briefly introduced by Michael in &lt;a href=&#34;https://biodash.github.io/codeclub/09_subsetting/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Code Club session 9&lt;/a&gt;. Besides functional programming methods, &lt;em&gt;vectorization is the other reason that loops are not as widely used in R as in other programming languages&lt;/em&gt;.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;i-vectorization&#34;&gt;I: Vectorization&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s say we have a &lt;em&gt;vector&lt;/em&gt; (i.e., a collection of values) that consists of distances in miles:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dists_miles&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;24&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;81&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;48&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;29&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;177&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;175&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;11&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;62&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;156&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Of course, we can&amp;rsquo;t science with miles, so we&amp;rsquo;ll have to convert these distances to kilometers by multiplying each value in the vector by 1.61. You may or may not know that this can be done &lt;em&gt;really easily&lt;/em&gt; in R:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dists_km&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dists_miles&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1.61&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dists_km&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  38.64 130.41  77.28  46.69 284.97 281.75  32.20  17.71  99.82 251.16&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What is happening here is called a &lt;em&gt;&lt;strong&gt;vectorized operation&lt;/strong&gt;&lt;/em&gt;: &lt;code&gt;1.61&lt;/code&gt; is automatically recycled as many times as needed to be multiplied with &lt;em&gt;each individual value&lt;/em&gt; in the &lt;code&gt;dist_miles&lt;/code&gt; vector. This is a pretty unique and very useful feature of R!&lt;/p&gt;
&lt;p&gt;In many other languages, we would need a &lt;em&gt;&lt;strong&gt;loop&lt;/strong&gt;&lt;/em&gt; or a similar construct to iterate over each value in the vector and multiply by 1.61. In fact, under the hood, R &lt;em&gt;also&lt;/em&gt; uses a loop to do this! So does it even make a difference? Yes &amp;ndash; the advantages of using vectorization in R are:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You don&amp;rsquo;t have to write the loop, saving you a fair bit of typing and making the code clearer.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The under-the-hood-loop is being executed &lt;em&gt;much&lt;/em&gt; faster than a loop that you would write. This is because it is written in &lt;code&gt;C&lt;/code&gt;/&lt;code&gt;C++&lt;/code&gt; code which only has to be called once (instead of at least as many times as there are iterations in our loop).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;h3 id=&#34;other-vectorization-patterns&#34;&gt;Other vectorization patterns&lt;/h3&gt;
&lt;p&gt;Above, we saw an example of multiplying a vector by a single number. We can also use vectorized operations when both objects contain multiple items. For instance, say we have a vector with corresponding values for two dates:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;17&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;93&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;56&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;19&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;175&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;40&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;69&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;267&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;91&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;87&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;143&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;103&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;223&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;106&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;18&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;87&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;72&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;59&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To get the sum of these values at each position (index) of the two vectors (&lt;code&gt;17 + 87&lt;/code&gt;, &lt;code&gt;93 + 143&lt;/code&gt;, etc.), we can simply do the following:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 104 236 159 242 281  58 156 339  63  96&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;The two vectors don&amp;rsquo;t need to be of equal length, either:&lt;br&gt;
in the example below, we negate &lt;em&gt;&lt;strong&gt;every other&lt;/strong&gt;&lt;/em&gt; value in a vector:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;17&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;93&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;56&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;19&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;175&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;40&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;69&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;267&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;91&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]   17  -93   56  -19  175  -40   69 -267    4  -91&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;This also works for columns of a data frame, which we can extract using the &lt;code&gt;dataframe_name$column_name&lt;/code&gt; notation (see &lt;a href=&#34;https://biodash.github.io/codeclub/09_subsetting/#data-frames&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Code Club session 9&amp;rsquo;s section on data frames&lt;/a&gt;, and the Base R data frame indexing summary &lt;a href=&#34;#base-r-data-frame-indexing&#34;&gt;below&lt;/a&gt;). Let&amp;rsquo;s say we wanted the mean distance this time:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dists_mean&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   dists_Mar4 dists_Mar5 dists_mean&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1         17         87       52.0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2         93        143      118.0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3         56        103       79.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4         19        223      121.0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5        175        106      140.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6         40         18       29.0&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h3 id=&#34;vectorization-with-matrices&#34;&gt;Vectorization with matrices&lt;/h3&gt;
&lt;p&gt;Furthermore, we can also perform vectorized operations on &lt;em&gt;entire matrices&lt;/em&gt;. With the following matrix:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## We use the &#34;sample&#34; function to get 25 random values between 1 and a 100,&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;## and put those in a 5*5 matrix:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/matrix.html&#39;&gt;matrix&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/sample.html&#39;&gt;sample&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;100&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;25&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, nrow &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;, ncol &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mat&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      [,1] [,2] [,3] [,4] [,5]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1,]    2   55    8   28   24&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [2,]   81   30   99   33   12&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [3,]   22   67   41   54    6&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [4,]   48   84   42   35  100&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [5,]   57   47   93   10   31&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&amp;hellip;we could multiple all values by 10 or get the square of each value simply as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;mat_more&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mat_more&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      [,1] [,2] [,3] [,4] [,5]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1,]   20  550   80  280  240&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [2,]  810  300  990  330  120&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [3,]  220  670  410  540   60&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [4,]  480  840  420  350 1000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [5,]  570  470  930  100  310&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;mat_squared&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mat&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;mat_squared&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      [,1] [,2] [,3] [,4]  [,5]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1,]    4 3025   64  784   576&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [2,] 6561  900 9801 1089   144&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [3,]  484 4489 1681 2916    36&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [4,] 2304 7056 1764 1225 10000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [5,] 3249 2209 8649  100   961&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h3 id=&#34;vectorization-with-indices&#34;&gt;Vectorization with indices&lt;/h3&gt;
&lt;p&gt;We can also use vectorized solutions when we want to operate only on elements that satisfy a certain condition.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s say we consider any distance in one of our vectors that is below 50 to be insufficient, and we want to turn those values into negatives (a little harsh maybe, but we go with it).&lt;/p&gt;
&lt;p&gt;To do so, we make use of R&amp;rsquo;s ability to index a vector with a logical vector:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## &#34;not_far_enough&#34; will be a vector of logicals:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;not_far_enough&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;not_far_enough&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  TRUE FALSE FALSE  TRUE FALSE  TRUE FALSE FALSE  TRUE FALSE&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## When we index the original vector with a logical vector,&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;## we get only those values for which &#34;not_far_enough&#34; is TRUE:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;not_far_enough&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 17 19 40  4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;With the following syntax, we can replace just those low distances in our original vector:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;not_far_enough&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;not_far_enough&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dists_Mar4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] -17  93  56 -19 175 -40  69 267  -4  91&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;In a simple case like this, we could also use the vectorized &lt;a href=&#34;https://rdrr.io/r/base/ifelse.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ifelse()&lt;/code&gt;&lt;/a&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/ifelse.html&#39;&gt;ifelse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;dists_Mar5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1]  87 143 103 223 106 -18  87  72  59  -5&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;ii-for-loops&#34;&gt;II: For loops&lt;/h2&gt;
&lt;p&gt;While it is important to use vectorization whenever possible, it can only be applied to a specific set of problems. A more universal solution when you need to repeat operations is the &lt;code&gt;for&lt;/code&gt; loop. &lt;code&gt;for&lt;/code&gt; loops iterate over a collection of values, allowing you to perform one or more actions for each value in the collection.&lt;/p&gt;
&lt;p&gt;The basic syntax is as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;for &lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;variable_name&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;collection_name&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;{&lt;/span&gt;
  &lt;span class=&#34;c1&#34;&gt;#...do things for each item (variable_name) in the collection, one at a time...&lt;/span&gt;
&lt;span class=&#34;p&#34;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;On the first line, you initialize the &lt;code&gt;for&lt;/code&gt; loop, telling it to assign each item in the collection to a variable (here, &lt;code&gt;variable_name&lt;/code&gt;) &lt;strong&gt;one at a time&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The &lt;em&gt;variable name&lt;/em&gt; is arbitrary, and the &lt;em&gt;collection&lt;/em&gt; is whatever you want to loop over. However, &lt;code&gt;for&lt;/code&gt;, the parentheses &lt;code&gt;()&lt;/code&gt;, &lt;code&gt;in&lt;/code&gt;, and the curly braces &lt;code&gt;{}&lt;/code&gt; are all fixed elements of &lt;code&gt;for&lt;/code&gt; loops. A simple example will help to understand the synax:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## A loop to print negated values:&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;# We iterate over 1, 2, 3, 4&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;             &lt;span class=&#39;c&#39;&gt;# Multiply each number by -1&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note that we don&amp;rsquo;t &lt;em&gt;have to&lt;/em&gt; use the variable that we are looping over: we could also use a &lt;code&gt;for&lt;/code&gt; loop as a roundabout way to simply repeat something as many times as there are values in our collection:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dummy&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Yes!&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;                     &lt;span class=&#39;c&#39;&gt;# Print &#34;Yes!&#34; in each of our four iterations &lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Yes!&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Yes!&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Yes!&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Yes!&#34;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;As mentioned, the &lt;strong&gt;variable name&lt;/strong&gt; that we assign is arbitrary: we could use anything, as long as we reference it with the same name inside the loop:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Example 1 with a different variable name: &#34;positive_number&#34;&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;positive_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;positive_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -4&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Example 2 with a different variable name: &#34;i&#34;&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note that the variable as it was last assigned in the loop does &lt;strong&gt;persist in your environment&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;em&gt;&lt;strong&gt;curly braces&lt;/strong&gt;&lt;/em&gt; are not strictly necessary for one-liners like this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -4&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h3 id=&#34;for-loop-output&#34;&gt;&lt;code&gt;for&lt;/code&gt; loop output&lt;/h3&gt;
&lt;p&gt;Note that we need the &lt;a href=&#34;https://rdrr.io/r/base/print.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;print()&lt;/code&gt;&lt;/a&gt; function to print anything to screen &amp;ndash; nothing will be printed if we omit this:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;i&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Similarly, if we want the output to be saved in an object of some kind, we need to explicitly make an assignment in each iteration of the loop. &lt;em&gt;This is where we need to start paying attention to the design of our loop.&lt;/em&gt; Unless computational speed is of no concern at all, you should &lt;strong&gt;avoid growing an object in each iteration of the loop&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;For example, you might be inclined to do the following if you wanted to compute the median of each column in a data frame:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## We initialize a vector in which we collect the column medians:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/vector.html&#39;&gt;vector&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;ncol&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## We extract one column using &#34;dataframe_name[[column_number]]&#34;:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;column_median&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/median.html&#39;&gt;median&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## We add the single-column median to our vector of medians:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;column_median&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 62.50 87.00 78.75&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Similarly, you may be tempted to add a column (with &lt;a href=&#34;https://rdrr.io/r/base/cbind.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;cbind()&lt;/code&gt;&lt;/a&gt;) or a row (with &lt;a href=&#34;https://rdrr.io/r/base/cbind.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;rbind()&lt;/code&gt;&lt;/a&gt;) to a data frame in each iteration of the loop. However, the problem with these approaches is that &lt;strong&gt;R has to create an entirely new object in each iteration of the loop&lt;/strong&gt;, because the object&amp;rsquo;s memory requirements keep increasing.&lt;/p&gt;
&lt;p&gt;Instead, you&amp;rsquo;ll want to give the final vector (here, &lt;code&gt;column_medians&lt;/code&gt;) the appropriate size before you start the loop:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/vector.html&#39;&gt;vector&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;length &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;ncol&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;ncol&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;column_median&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/median.html&#39;&gt;median&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dist_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;column_medians&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;column_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;column_median&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Note that for very small problems, such as the example above, there will not be a noticeable difference in computation time between pre-assigning a properly sized object versus growing an object inside the loop. However, it is still good to get into the habit of pre-assigning an object of the right size.&lt;/p&gt;
&lt;br&gt;
&lt;h3 id=&#34;summary-guidelines-when-speed-is-an-issue&#34;&gt;Summary guidelines (when speed is an issue)&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;Don&amp;rsquo;t use a loop when you can instead use vectorized operations.&lt;/li&gt;
&lt;li&gt;Don&amp;rsquo;t grow objects inside the loop. Instead, pre-assign an object large enough to contain all output of the loop and fill it in inside the loop.&lt;/li&gt;
&lt;li&gt;When you write a loop, avoid doing things &lt;em&gt;inside&lt;/em&gt; the loop that don&amp;rsquo;t need to be repeated.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Learning about how to create your own functions and/or to use functional programming techniques like &lt;em&gt;purrr&lt;/em&gt; and the &lt;code&gt;apply&lt;/code&gt; family of functions (upcoming Code Club sessions!) will likely reduce your reliance on loops. For instance, as we&amp;rsquo;ll see next week, computing the median of each column in a data frame can be done &lt;em&gt;much&lt;/em&gt; more succinctly with &lt;a href=&#34;https://rdrr.io/r/base/apply.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;apply()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Even for more experienced users, loops remain a more viable option when longer blocks of code need to be repeated: we will practice with that in the exercises.&lt;/strong&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout rooms!&lt;/h2&gt;
&lt;p&gt;For the exercises, you can download an R Markdown file with some code to get set up (I recommend coding in that document to get a nice overview of the maps that you will make):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;S12&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;todays_rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/12_loops/exercises.Rmd&#39;&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;todays_rmd&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;S12/exercises.Rmd&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The following code is already in your R Markdown file, which will download and read the bird dataset and the necessary packages:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Download the file with bird data:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_url&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/data/birds/backyard-birds_sample_error.tsv&#39;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;backyard-birds_sample_error.tsv&#39;&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_url&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Load the tidyverse:&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Read the file with bird data:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Load the maps package and get the state map:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# install.packages(&#39;maps&#39;)   # first install if necessary&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;state&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Last week, we learned about making maps. If you attended one of the first few Code Club sessions, you&amp;rsquo;ll recall our &lt;strong&gt;Great Backyard Birdcount data set&lt;/strong&gt;. Here, we&amp;rsquo;ll use a country-wide random subset of this data (the full file is over 4 GB) to see where Carolina Chickadees were seen:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## With this line, we select only the rows where the column &#34;species_en&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;## (English species name) equals &#34;Carolina Chickadee&#34;,&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;## i.e. we are getting just the records for the Carolina Chickadee:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;caro_chickadee&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Carolina Chickadee&#39;&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Or in tidyverse-speak:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# caro_chickadee &amp;lt;- birds %&amp;gt;% filter(species_en == &#39;Carolina Chickadee&#39;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Next, we create a map much like we did last week:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt;,                               &lt;span class=&#39;c&#39;&gt;# Use &#34;states&#34; for underlying map&lt;/span&gt;
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Black state outlines, white fill&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;caro_chickadee&lt;/span&gt;,                 &lt;span class=&#39;c&#39;&gt;# Plot points from bird data set&lt;/span&gt;
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;green4&#34;&lt;/span&gt;, alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;       &lt;span class=&#39;c&#39;&gt;# Green points, somewhat transparent&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;                                &lt;span class=&#39;c&#39;&gt;# Fix projection&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Carolina Chickadee&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-24-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Uh-oh! Something appears to have gone wrong. In the first exercise, you&amp;rsquo;ll use vectorization to fix the coordinates in the bird data set.&lt;/p&gt;
&lt;p&gt;In the second exercise, you&amp;rsquo;ll use a loop to quickly produce similar plots for several other species.&lt;/p&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1-vectorization&#34;&gt;Exercise 1: Vectorization&lt;/h3&gt;
&lt;p&gt;Try to fix the coordinates using vectorized operations, and recreate the map to see if it worked.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Start with the &lt;strong&gt;latitude&lt;/strong&gt;, which is wrong for all points.&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You&amp;rsquo;ll need to modify the &lt;code&gt;caro_chickadee&lt;/code&gt; data frame, while you can keep the plotting code exactly the same.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Simply prepending the latitude column with a minus sign (&lt;a href=&#34;https://rdrr.io/r/base/Arithmetic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;-&lt;/code&gt;&lt;/a&gt;) will negate the values.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Equivalent base R ways to refer to the column with latitudes are &lt;code&gt;caro_chickadee$lat&lt;/code&gt; and &lt;code&gt;caro_chickadee[[&#39;lat&#39;]]&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;First we fix the latitude, which was simply negated:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;caro_chickadee&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;caro_chickadee&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Or equivalently:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# caro_chickadee[[&#39;lat&#39;]] &amp;lt;- -caro_chickadee[[&#39;lat&#39;]]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Or a tidyverse way of doing this:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# caro_chickadee &amp;lt;- caro_chickadee %&amp;gt;% mutate(lat = -lat)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Create the first map with the same code as the example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;caro_chickadee&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;green4&#34;&lt;/span&gt;, alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Carolina Chickadee&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-26-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Once you have fixed the latitude, you should notice that &lt;em&gt;for one state&lt;/em&gt;, there is a problem with the &lt;strong&gt;longitude&lt;/strong&gt; (the offset is 10 decimal degrees).&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The displaced state is North Carolina.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The state of each sighting is in the &lt;code&gt;stateProvince&lt;/code&gt; column, and North Carolina&amp;rsquo;s name is simply &amp;ldquo;North Carolina&amp;rdquo; in that column.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;It may help to first create a logical vector indicating whether for each row in the &lt;code&gt;caro_chickadee&lt;/code&gt; data frame, &lt;code&gt;stateProvincefor&lt;/code&gt; equals &amp;ldquo;North Carolina&amp;rdquo;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Your final map will look nicer if you get rid of the plotting canvas by adding&lt;br&gt;
&lt;code&gt;+ theme_void()&lt;/code&gt; to the code for the plot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;It turns out that North Carolina&amp;rsquo;s chickadees are above the Atlantic. Let&amp;rsquo;s perform a rescue operation by fixing the longitudes, which are offset by 10 degrees, &lt;strong&gt;just for North Carolina&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## Get a vector of logicals, indicating which rows are from North Carolina:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;NC_rows&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;caro_chickadee&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;stateProvince&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;North Carolina&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Only for North Carolina rows, change the longitude:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;caro_chickadee&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NC_rows&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;caro_chickadee&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NC_rows&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Or with ifelse in one line:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# caro_chickadee$long &amp;lt;- ifelse(caro_chickadee$stateProvince == &#34;North Carolina&#34;,&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#                               caro_chickadee$long - 10,&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#                               caro_chickadee$long)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Or with mutate and ifelse:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# caro_chickadee %&amp;gt;%&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#   mutate(long = ifelse(stateProvince == &#34;North Carolina&#34;, long - 10, long))&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And we create the final map:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;caro_chickadee&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;green4&#34;&lt;/span&gt;, alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Carolina Chickadee&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_void&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-28-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Nice!&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2-for-loops&#34;&gt;Exercise 2: for loops&lt;/h3&gt;
&lt;p&gt;Find the 10 most commonly observed bird species in the data set, and save their English names (found in the &lt;code&gt;species_en&lt;/code&gt; column) in a vector.&lt;/p&gt;
&lt;p&gt;Feel free to check out the solution if you&amp;rsquo;re not sure how, because the focus here is on the next step: trying to create a loop.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;top10&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;, sort &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;# Produces a sorted count table for &#34;species_en&#34;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;pull&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;                &lt;span class=&#39;c&#39;&gt;# Extracts the &#34;species_en&#34; column&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;                        &lt;span class=&#39;c&#39;&gt;# Take the top 10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;p&gt;Next, loop over the top-10 species to produce a plot for each one of them.&lt;br&gt;
Start with the code for the Carolina Chickadee, including the subsetting operation, and modify that.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;In the subsetting operation where you select data for the focal species, replace &amp;ldquo;Carolina Chickadee&amp;rdquo; with whatever you name the variable (indicating an individual species) that you loop over.&lt;/p&gt;
&lt;p&gt;Because this is a variable name, and not a string like &amp;ldquo;Carolina Chickadee&amp;rdquo;, don&amp;rsquo;t forget to omit the quotes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You&amp;rsquo;ll also need to change the title with the looping variable.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_species&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;top10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Select just the data for one species:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;one_bird_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;one_species&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;## Or in tidyverse-speak:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# one_bird_data &amp;lt;- birds %&amp;gt;% filter(species_en == one_species)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt;,
            mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;one_bird_data&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;green4&#34;&lt;/span&gt;, alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;one_species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;# Make sure to change this to the looping variable&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_void&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-30-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-30-2.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-30-3.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-30-4.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-30-5.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-30-6.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-30-7.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-30-8.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-30-9.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-30-10.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;bonus-exercise-if-statements&#34;&gt;Bonus exercise: if statements&lt;/h3&gt;
&lt;p&gt;&lt;code&gt;if&lt;/code&gt; statements are similar in syntax to &lt;code&gt;for&lt;/code&gt; loops, and are also considered a &amp;ldquo;control flow&amp;rdquo; structure. But their purpose is different from loops: instead of iterating, &lt;strong&gt;&lt;code&gt;if&lt;/code&gt; statements do something once and they &lt;em&gt;only&lt;/em&gt; do it when a condition is fulfilled.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;For instance, we may want to check in a script whether a certain directory (folder) exists on our computer, and if it doesn&amp;rsquo;t, then we create the directory:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.exists&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;path/to/my/dir&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/warning.html&#39;&gt;warning&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Oh my, the output directory doesn&#39;t exist yet!&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;path/to/my/dir&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Inside the parentheses &lt;code&gt;()&lt;/code&gt; after &lt;code&gt;if&lt;/code&gt; should be a statement that evaluates to either &lt;code&gt;TRUE&lt;/code&gt; or &lt;code&gt;FALSE&lt;/code&gt; (&lt;a href=&#34;https://rdrr.io/r/base/files2.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dir.exists()&lt;/code&gt;&lt;/a&gt; will be &lt;code&gt;TRUE&lt;/code&gt; if the directory exists, and &lt;code&gt;FALSE&lt;/code&gt; if it does not). If it is &lt;code&gt;TRUE&lt;/code&gt;, whatever is inside the curly braces &lt;code&gt;{}&lt;/code&gt; will be executed, and if it is &lt;code&gt;FALSE&lt;/code&gt;, what is inside the curly braces will be ignored.&lt;/p&gt;
&lt;p&gt;&lt;code&gt;if&lt;/code&gt; statements are commonly combined with &lt;code&gt;for&lt;/code&gt; loops: we may want to only execute the functions in our loop for items in our collection that fulfill a certain condition:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_number&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_number&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_number&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 9&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 10&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In the example above, &lt;code&gt;one number &amp;gt; 7&lt;/code&gt; will only be &lt;code&gt;TRUE&lt;/code&gt; for numbers larger than 7. This example is quite contrived, as it would have been easier (and faster!) to remove these items from the vector before the loop, but it hopefully gets the point across of how an &lt;code&gt;if&lt;/code&gt; statement works.&lt;/p&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Many of the maps we produced in the previous exercise looked quite similar, with most species very widespread and a few restricted to the east of the US. Maybe if we select species that haven&amp;rsquo;t been seen in Ohio, we can find some other distributional patterns.&lt;/p&gt;
&lt;p&gt;First, select the the top 50 most observed bird species, just like you did in exercise 2.&lt;/p&gt;
&lt;p&gt;Then, use an &lt;code&gt;if&lt;/code&gt; statement to create plots only for those top-50 birds that have &lt;em&gt;not&lt;/em&gt; been seen in Ohio.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Select the top-50 birds:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;all_species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;, sort &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;pull&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;50&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Loop over the species:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;for&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_species&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;in&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;all_species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;

  &lt;span class=&#39;c&#39;&gt;## Select the focal species:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;one_bird&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;one_species&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
  
  &lt;span class=&#39;c&#39;&gt;## Create a data frame with only records from Ohio:&lt;/span&gt;
  &lt;span class=&#39;nv&#39;&gt;one_bird_ohio&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;one_bird&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_bird&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;stateProvince&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Ohio&#39;&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

  &lt;span class=&#39;c&#39;&gt;## Test whether the data frame with only records from Ohio has any rows.&lt;/span&gt;
  &lt;span class=&#39;c&#39;&gt;## If it does not, we create the map for the species in question: &lt;/span&gt;
  &lt;span class=&#39;kr&#39;&gt;if&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;one_bird_ohio&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  
    &lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt;,
           mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;one_bird&lt;/span&gt;,
                 &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                 color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;green4&#34;&lt;/span&gt;, alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;one_species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
      &lt;span class=&#39;nf&#39;&gt;theme_void&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    &lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-34-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-34-2.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;img src=&#34;figs/unnamed-chunk-34-3.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;going-further&#34;&gt;Going further&lt;/h2&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;base-r-data-frame-indexing&#34;&gt;Base R data frame indexing&lt;/h3&gt;
&lt;p&gt;Extract a column &lt;em&gt;as a vector&lt;/em&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## By name:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;lat&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# Equivalent, $ notation is shorthand&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## By index (column number):&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Extract one or more columns &lt;em&gt;as a data frame&lt;/em&gt; using &lt;code&gt;[row, column]&lt;/code&gt; notation,&lt;br&gt;
with a leading comma (&lt;code&gt;[, column]&lt;/code&gt;) meaning all rows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;## By name:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#39;lat&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;   &lt;span class=&#39;c&#39;&gt;# dataframe[&#39;row_name&#39;, &#39;column_name&#39;]&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;lat&#39;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#39;long&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## By index (column numbers):&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;       &lt;span class=&#39;c&#39;&gt;# dataframe[row_number, column_number]&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;9&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Subset rows by a condition, with a trailing comma (&lt;code&gt;[row, ]&lt;/code&gt;) meaning all columns:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;25&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Carolina Chickadee&#39;&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;seq_along&#34;&gt;&lt;code&gt;seq_along()&lt;/code&gt;&lt;/h4&gt;
&lt;p&gt;To loop over column indices, we have used &lt;code&gt;1:ncol()&lt;/code&gt; above, and to loop over vector indices, you could similarly use &lt;code&gt;1:length()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;However, an alternative is &lt;a href=&#34;https://rdrr.io/r/base/seq.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;seq_along()&lt;/code&gt;&lt;/a&gt;, which will create an index for you.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;titmouse&#39;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#39;chickadee&#39;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#39;cardinal&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/seq.html&#39;&gt;seq_along&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The advantage of &lt;a href=&#34;https://rdrr.io/r/base/seq.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;seq_along()&lt;/code&gt;&lt;/a&gt; is thtat it will behave better when your vector accidentally has length 0 (because &lt;code&gt;1:length()&lt;/code&gt; will have &lt;code&gt;1&lt;/code&gt; and &lt;code&gt;0&lt;/code&gt; when the length is 0, and you&amp;rsquo;ll get odd-seeming errors).&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;further-reading&#34;&gt;Further reading&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;http://www.noamross.net/archives/2014-04-16-vectorization-in-r-why/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Vectorization in R: Why?&lt;/a&gt; (Noam Ross, 2014)&lt;/li&gt;
&lt;li&gt;The &lt;a href=&#34;https://r4ds.had.co.nz/iteration.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Iteration chapter&lt;/a&gt; in Hadley Wickham&amp;rsquo;s R for Data Science (2017)&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>Session 11: Spatial data visualization with ggplot2</title>
      <link>https://biodash.github.io/codeclub/11_ggplot-maps/</link>
      <pubDate>Wed, 24 Feb 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/11_ggplot-maps/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;prep-and-setup&#34;&gt;Prep and setup&lt;/h2&gt;
&lt;h3 id=&#34;new-to-code-club&#34;&gt;New to Code Club?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/04_ggplot2/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll help you troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;new-to-ggplot2&#34;&gt;New to &lt;em&gt;ggplot2&lt;/em&gt;?&lt;/h3&gt;
&lt;p&gt;Check out the two Code Club pages for &lt;a href=&#34;https://biodash.github.io/codeclub/04_ggplot2/&#34;&gt;Session 4&lt;/a&gt; and &lt;a href=&#34;https://biodash.github.io/codeclub/05_ggplot-round-2/&#34;&gt;Session 5&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;ve never used &lt;code&gt;ggplot2&lt;/code&gt; before (or even if you have), you may find &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this cheat sheet&lt;/a&gt; useful.&lt;/p&gt;
&lt;h3 id=&#34;download-the-csv-file-on-ohio&#34;&gt;Download the CSV file on Ohio&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;ohio_csv&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/11_ggplot-maps/Ohio.csv&#39;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio_csv&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Ohio.csv&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;creating-maps-in-r&#34;&gt;Creating maps in R&lt;/h2&gt;
&lt;p&gt;Today, we will cover the visualization of spatial data in R using the layered grammar of graphics implementation of ggplot2 in conjunction with the contextual information of static maps from world maps in the &lt;em&gt;maps&lt;/em&gt; package.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Before we look at mapping using ggplot2, let us define some terms.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Areal data&lt;/em&gt; &lt;br/&gt; Areal data is data which corresponds to geographical extents with polygonal boundaries.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The layered grammar of graphics&lt;/em&gt; &lt;br/&gt; By definition, the layered grammar demands that every plot consist of five components: &lt;br/&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;a default dataset with aesthetic mappings,&lt;br/&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;one or more layers, each with either a geometric object (&amp;ldquo;geom&amp;rdquo;), a statistical transformation (&amp;ldquo;stat&amp;rdquo;), etc.&lt;br/&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;a scale for each aesthetic mapping (which can be automatically generated),&lt;br/&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;a coordinate system, and &lt;br/&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;a facet specification. &lt;br/&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Since &lt;em&gt;ggplot2&lt;/em&gt; is an implementation of the layered grammar of graphics, every plot made with ggplot2 has each of the above elements. Consequently, map plots also have these elements, but certain elements are ﬁxed to map components: the &lt;code&gt;x&lt;/code&gt; aesthetic is ﬁxed to longitude, the &lt;code&gt;y&lt;/code&gt; aesthetic is ﬁxed to latitude.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Drawing a map&lt;/strong&gt; &lt;br/&gt; Drawing a map in R requires two things. &lt;strong&gt;First&lt;/strong&gt;, we have to draw the map using data that directs R to draw the polygon shapes that constitute the map. Then we &lt;strong&gt;add&lt;/strong&gt; information to our map to plot color and marks. It&amp;rsquo;s the same basic logic that we have used in ggplot figures. The key thing is to have datasets that link that geographic data with the information that we want to put on the plot.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;The maps package in R&lt;/em&gt; &lt;br/&gt; The &amp;ldquo;maps&amp;rdquo; package in R contains a set of maps of the United States and the world drawn using longitude and latitude data. With world map, the USA map with the individual states you can accomplish a lot of the mapping tasks using the maps package. The maps package contains a lot of outlines of continents, countries, states, and counties&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Making dataframes from map outlines by ggplot2&lt;/strong&gt; &lt;br/&gt; Recall that ggplot2 operates on dataframes. Therefore, we need some way to translate the maps data into a data frame format the ggplot can use. The package &lt;em&gt;ggplot2&lt;/em&gt; provides the &lt;code&gt;map_data()&lt;/code&gt; function. The function turns a series of points along an outline into a data frame of those points. The package ggplot2 uses the following syntax: &lt;code&gt;map_data(&amp;quot;name&amp;quot;)&lt;/code&gt; where &amp;ldquo;name&amp;rdquo; is a quoted string of the name of a map in the &lt;em&gt;maps&lt;/em&gt; package.&lt;br/&gt;&lt;/p&gt;
&lt;h2 id=&#34;our-first-maps&#34;&gt;Our first maps&lt;/h2&gt;
&lt;p&gt;Let us start by drawing maps of the World, USA, states, Ohio, Ohio and Indiana, and part of Europe using the &lt;em&gt;maps&lt;/em&gt; package.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;maps&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://scales.r-lib.org&#39;&gt;scales&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://stringr.tidyverse.org&#39;&gt;stringr&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Let us get a world map using the &#34;map_data&#34; function &lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;world&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;world&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;## Let us get a US map:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;usa&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;usa&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Let us get the states:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;state&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Select Ohio using the filter function:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;ohio&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;region&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ohio&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Let us plot a world map:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;world&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
 &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-3-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Let us plot a map of the US:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
 &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-4-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Let us plot a map of the US with states:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
 &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;blue&#34;&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-5-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Let us plot a map of Ohio:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio&lt;/span&gt;,
       mapping&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;green&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-6-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;We can also plot a map for an arbitrary selection of states:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# We can select data for two states, for example Ohio and Indiana:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;ohio_indiana&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;region&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ohio&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;region&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;indiana&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Plot the map of Ohio and Indiana:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio_indiana&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;green&#34;&lt;/span&gt; , color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;red&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-7-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;We can also plot only a specific region by filtering by latitude and longitude:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;world&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;world&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;a_region&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;world&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;15.1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;32&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;55&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;a_region&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-8-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&#34;the-structure-of-the-dataframe-ohio&#34;&gt;The structure of the dataframe &lt;code&gt;ohio&lt;/code&gt;.&lt;/h2&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ohio&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;        long      lat group order region subregion&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 -80.51776 40.64563    42 10440   ohio      &amp;lt;NA&amp;gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 -80.55787 40.63990    42 10441   ohio      &amp;lt;NA&amp;gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3 -80.62089 40.63417    42 10442   ohio      &amp;lt;NA&amp;gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4 -80.66100 40.61698    42 10443   ohio      &amp;lt;NA&amp;gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5 -80.66673 40.60552    42 10444   ohio      &amp;lt;NA&amp;gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6 -80.67245 40.58833    42 10445   ohio      &amp;lt;NA&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Look at the variables in &lt;em&gt;ohio&lt;/em&gt;, note what they refer to: &lt;br/&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;long&lt;/code&gt; = longitude. Lines of longitude, or meridians, run between the North and South Poles and measure east-west positions. While prime meridian is assigned the value of 0 degrees, and runs through Greenwich (England), meridians to the west of the prime meridian are measured in degrees west (up to 180 degrees) and those to the east of the prime meridian are measured to in degrees east (up to 180 degrees).&lt;br/&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;lat&lt;/code&gt; = latitude. Lines of latitude measure north-south position between the poles with the equator defined as 0 degrees, the North Pole defined as 90 degrees north, and the South Pole defined as 90 degrees south. &lt;br/&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;group&lt;/code&gt; = an identifier that is unique for each subregion (here the counties). Group is very important! ggplot2&amp;rsquo;s functions can take a group argument which controls (amongst other things) whether adjacent points should be connected by lines. If they are in the same group, then they get connected, but if they are in different groups then they don&amp;rsquo;t. &lt;br/&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;order&lt;/code&gt; = an identifier that indicates the order in which the boundary lines should be drawn &lt;br/&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;region&lt;/code&gt; = string indicator for regions (here the states) &lt;br/&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;subregion&lt;/code&gt; = string indicator for sub-regions (here the county names) &lt;br/&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;add-information-to-the-maps&#34;&gt;Add information to the maps&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;The second part of mapping in R, is to add information on the map created in the first part.&lt;/strong&gt; &lt;br/&gt; In drawing the map, the &amp;ldquo;&lt;em&gt;maps&lt;/em&gt;&amp;rdquo; package creates the backbone for visualizations. Then we add additional information to show colors and shapes. &lt;br/&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;We will:&lt;/em&gt; &lt;br/&gt; - fill a map by region, &lt;br/&gt; - draw a Bubble map using city population, &lt;br/&gt; - make a point for every city, &lt;br/&gt; - vary size of point by city size and vary the color of the dots, and &lt;br/&gt; - add external data to the map. &lt;br/&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Let us fill by region and make sure the the lines of state borders are white:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;states&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
 &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;region&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
              color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
 &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
 &lt;span class=&#39;nf&#39;&gt;guides&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# Do this to omit the legend&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-10-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Let us draw a &amp;ldquo;Bubble map&amp;rdquo;:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# The maps package has city data&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;maps&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/maps/man/world.cities.html&#39;&gt;world.cities&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;                 name country.etc   pop   lat  long capital&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 &#39;Abasan al-Jadidah   Palestine  5629 31.31 34.34       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 &#39;Abasan al-Kabirah   Palestine 18999 31.32 34.35       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3       &#39;Abdul Hakim    Pakistan 47788 30.55 72.11       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4 &#39;Abdullah-as-Salam      Kuwait 21817 29.36 47.98       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5              &#39;Abud   Palestine  2456 32.03 35.07       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6            &#39;Abwein   Palestine  3434 32.03 35.20       0&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;my_cities&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;maps&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/maps/man/world.cities.html&#39;&gt;world.cities&lt;/a&gt;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;usa_cities&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;my_cities&lt;/span&gt;,&lt;span class=&#39;nv&#39;&gt;country.etc&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;USA&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;usa_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;      name country.etc    pop   lat    long capital&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 Abilene         USA 113888 32.45  -99.74       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2   Akron         USA 206634 41.08  -81.52       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3 Alameda         USA  70069 37.77 -122.26       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4  Albany         USA  45535 44.62 -123.09       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5  Albany         USA  75510 31.58  -84.18       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6  Albany         USA  93576 42.67  -73.80       0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Make a point for every city:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
 &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
 &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa_cities&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;red&#34;&lt;/span&gt;,
            &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Let&amp;rsquo;s pick just the big cities:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;usa_big_cities&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;my_cities&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;country.etc&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;USA&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;500000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa&lt;/span&gt;, mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa_big_cities&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;red&#34;&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Vary size of point by city size:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa&lt;/span&gt;, mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa_big_cities&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;red&#34;&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Now vary the color of the dots:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;usa_big_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;qual&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/sample.html&#39;&gt;sample&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;LETTERS&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;usa_big_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                              replace &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa&lt;/span&gt;, mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa_big_cities&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;qual&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-15-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Tweak the map:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# No scientific notation in legend r ggplot:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# scales package adds the &#34;scale_size_continuous&#34; function, and we can set label=comma&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://scales.r-lib.org&#39;&gt;scales&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Change the column name to make the legend nicer&#34;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;usa_big_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Population&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa_big_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pop&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;usa_big_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Qualitative&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa_big_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;qual&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Do some additional refining:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa&lt;/span&gt;, mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa_big_cities&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;,
                 color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Qualitative&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Population&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;scale_size_continuous&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;comma&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-16-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Work with Ohio counties with external data:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Get basic map data for all USA counties:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;usa_counties&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;county&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;span class=&#39;c&#39;&gt;# Subset to counties in Ohio:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;oh&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/subset.html&#39;&gt;subset&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;usa_counties&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;region&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ohio&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;oh&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;            long      lat group order region subregion&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 59960 -83.66902 39.02989  2012 59960   ohio     adams&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 59961 -83.56590 39.02989  2012 59961   ohio     adams&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 59962 -83.37109 39.06426  2012 59962   ohio     adams&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 59963 -83.30806 39.06426  2012 59963   ohio     adams&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 59964 -83.30233 39.05280  2012 59964   ohio     adams&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 59965 -83.25649 39.01842  2012 59965   ohio     adams&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Plot ohio counties&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;oh&lt;/span&gt;,
               &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;subregion&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
               color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;guides&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggtitle&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Ohio counties&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-18-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Read population data for Ohio counties:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# The data of the estimated population of each  county in 2021 and percent change from 2010&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;Ohio&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_csv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Ohio.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Ohio&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   county       Pop  Perc Town         x_1   y_1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;      &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;      &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adams      &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;27&lt;/span&gt;&lt;span&gt;706 -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;2.91&lt;/span&gt;&lt;span&gt; West Union -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;83.5&lt;/span&gt;&lt;span&gt;  38.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Allen     &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;101&lt;/span&gt;&lt;span&gt;603 -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;4.47&lt;/span&gt;&lt;span&gt; Lima       -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;84.1&lt;/span&gt;&lt;span&gt;  40.7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Ashland    &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;53&lt;/span&gt;&lt;span&gt;040 -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.53&lt;/span&gt;&lt;span&gt; Ashland    -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;82.3&lt;/span&gt;&lt;span&gt;  40.9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Ashtabula  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;96&lt;/span&gt;&lt;span&gt;549 -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;4.79&lt;/span&gt;&lt;span&gt; Jefferson  -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;80.8&lt;/span&gt;&lt;span&gt;  41.7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Athens     &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;64&lt;/span&gt;&lt;span&gt;943 -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.35&lt;/span&gt;&lt;span&gt; Athens     -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;82.1&lt;/span&gt;&lt;span&gt;  39.3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Auglaize   &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;45&lt;/span&gt;&lt;span&gt;496 -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;0.88&lt;/span&gt;&lt;span&gt; Wapakoneta -&lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;84.2&lt;/span&gt;&lt;span&gt;  40.6&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Prepare the data for plotting:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Create a new  column called  &#34;county&#34; so that counties start with capital letters&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# using str_to_title function &lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;oh&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;county&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://stringr.tidyverse.org/reference/case.html&#39;&gt;str_to_title&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;oh&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;subregion&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Merge population data with counties data by county variable using inner_join&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# function, and named the new object &#34;ohio_pop&#34;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;ohio_pop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;inner_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;oh&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Ohio&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;county&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Select counties with population greater than 100000&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;ohio_big_pop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ohio_pop&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Pop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Create the plot where we vary point size by population size:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;###  vary size of point by population size&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio_pop&lt;/span&gt;, mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio_big_pop&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;red&#34;&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;x_1&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y_1&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;guides&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# Omit the legend&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-21-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Improve the graph by creating groups of population using quantile.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;ApplyQuintiles&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/cut.html&#39;&gt;cut&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;, breaks &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/quantile.html&#39;&gt;quantile&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ohio_pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Pop&lt;/span&gt;, probs &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/seq.html&#39;&gt;seq&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
      labels &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;0-20&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;20-40&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;40-60&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;60-80&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;80-100&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
      include.lowest &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;ohio_pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;grouped_pop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/lapply.html&#39;&gt;sapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ohio_pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Pop&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;ApplyQuintiles&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ohio_pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;        long      lat group order region subregion county   Pop  Perc       Town&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 -83.66902 39.02989  2012 59960   ohio     adams  Adams 27706 -2.91 West Union&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 -83.56590 39.02989  2012 59961   ohio     adams  Adams 27706 -2.91 West Union&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3 -83.37109 39.06426  2012 59962   ohio     adams  Adams 27706 -2.91 West Union&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4 -83.30806 39.06426  2012 59963   ohio     adams  Adams 27706 -2.91 West Union&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5 -83.30233 39.05280  2012 59964   ohio     adams  Adams 27706 -2.91 West Union&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6 -83.25649 39.01842  2012 59965   ohio     adams  Adams 27706 -2.91 West Union&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;         x_1      y_1 grouped_pop&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 -83.54616 38.79483        0-20&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 -83.54616 38.79483        0-20&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3 -83.54616 38.79483        0-20&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4 -83.54616 38.79483        0-20&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5 -83.54616 38.79483        0-20&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6 -83.54616 38.79483        0-20&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;Plot the map:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio_pop&lt;/span&gt;,
               &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;grouped_pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
               color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;scale_fill_brewer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;palette &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Reds&#34;&lt;/span&gt;, direction &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Population Quantiles&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-23-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout rooms&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;Use the dataset of 2021 Ohio county&amp;rsquo;s population to plot counties with % positive population growth.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Solution (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Get basic map data for all USA counties:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;usa_counties&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;county&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;    

&lt;span class=&#39;c&#39;&gt;# Subset to counties in Ohio:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;oh&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/subset.html&#39;&gt;subset&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;usa_counties&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;region&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ohio&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  

&lt;span class=&#39;c&#39;&gt;# Read population data:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;Ohio&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_csv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Ohio.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;span class=&#39;c&#39;&gt;# Create a new  column called  &#34;county&#34; so that counties start with capital&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# letters using str_to_title function &lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;oh&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;county&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://stringr.tidyverse.org/reference/case.html&#39;&gt;str_to_title&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;oh&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;subregion&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Merge counties with population:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;ohio_pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;inner_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;oh&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Ohio&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;county&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Select counties with % positive population growth:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;ohio_pos_pop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ohio_pop&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Perc&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio_pop&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio_pos_pop&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;red&#34;&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;x_1&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y_1&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Perc&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;guides&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;#  Omit the legend&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-24-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;p&gt;Use the same data to plot counties with % negative population growth with quantile of 0-20, 20-40, 40-60, 60-80, and 80-100.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Solution (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;ohio_neg_pop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ohio_pop&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Perc&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio_pop&lt;/span&gt;, mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;,fill&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio_neg_pop&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;red&#34;&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;x_1&lt;/span&gt;,y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;y_1&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Perc&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;guides&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# Omit the legend&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-25-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;ApplyQuintiles_n&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;kr&#39;&gt;function&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;#123;&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/cut.html&#39;&gt;cut&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;, breaks &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/quantile.html&#39;&gt;quantile&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ohio_neg_pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Perc&lt;/span&gt;, probs &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/seq.html&#39;&gt;seq&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
      labels &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;0-20&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;20-40&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;40-60&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;60-80&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;80-100&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
      include.lowest &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;&amp;#125;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;ohio_neg_pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;grouped_pop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/lapply.html&#39;&gt;sapply&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ohio_neg_pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Perc&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;ApplyQuintiles_n&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Plot the map&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;ohio_neg_pop&lt;/span&gt;,
               &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;grouped_pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
               color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;coord_fixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1.3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;scale_fill_brewer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;palette &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Set1&#34;&lt;/span&gt;, direction &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Negative population growth counties&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-26-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;h3 id=&#34;bonus-exercise&#34;&gt;Bonus exercise&lt;/h3&gt;
&lt;p&gt;Plot the cities of France with population greater than 100,000. Vary size of point by city size, and vary the color of the dots.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Solution (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;world&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;map_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;world&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;france&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;world&lt;/span&gt;,&lt;span class=&#39;nv&#39;&gt;region&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;France&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;france&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;France&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-27-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;
&lt;span class=&#39;c&#39;&gt;# The &#34;maps&#34; package has city data&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;maps&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/maps/man/world.cities.html&#39;&gt;world.cities&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;                 name country.etc   pop   lat  long capital&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 &#39;Abasan al-Jadidah   Palestine  5629 31.31 34.34       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 &#39;Abasan al-Kabirah   Palestine 18999 31.32 34.35       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3       &#39;Abdul Hakim    Pakistan 47788 30.55 72.11       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4 &#39;Abdullah-as-Salam      Kuwait 21817 29.36 47.98       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5              &#39;Abud   Palestine  2456 32.03 35.07       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6            &#39;Abwein   Palestine  3434 32.03 35.20       0&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;my_cities&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;maps&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/maps/man/world.cities.html&#39;&gt;world.cities&lt;/a&gt;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;france_cities&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;my_cities&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;country.etc&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;France&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;france_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;              name country.etc    pop   lat long capital&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1       Abbeville      France  26656 50.12 1.83       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2         Acheres      France  23219 48.97 2.06       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3            Agde      France  23477 43.33 3.46       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4            Agen      France  34742 44.20 0.62       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5 Aire-sur-la-Lys      France  10470 50.64 2.39       0&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6 Aix-en-Provence      France 148622 43.53 5.44       0&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Make a point for every city:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;france&lt;/span&gt;, mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;france_cities&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;red&#34;&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-27-2.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Let&#39;s pick just the big cities:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;france_big_cities&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;my_cities&lt;/span&gt;,&lt;span class=&#39;nv&#39;&gt;country.etc&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;France&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;amp;&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;100000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;france&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;france_big_cities&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;red&#34;&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-28-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# vary size of point by city size&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;france&lt;/span&gt;, mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;france_big_cities&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;red&#34;&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-29-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Now vary the color of the dots&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;france_big_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;qual&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/sample.html&#39;&gt;sample&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;LETTERS&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;,
                                 &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;france_big_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                                 replace &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;france&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;,fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;france_big_cities&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;qual&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-30-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Do some tweaking:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# no scientific notation in legend r ggplot&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# scales package adds the &#34;scale_size_continuous&#34; function to our arsenal, and we can set label=comma&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://scales.r-lib.org&#39;&gt;scales&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Change the column name to make the legend nicer:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;france_big_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Population&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;france_big_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;pop&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;france_big_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Qualitative&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;france_big_cities&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;qual&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Do some additional refining:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;france&lt;/span&gt;,
       mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;group&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_polygon&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;white&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;france_big_cities&lt;/span&gt;,
             &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;long&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lat&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NULL&lt;/span&gt;,
                 color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Qualitative&lt;/span&gt;, size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Population&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;scale_size_continuous&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;comma&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-31-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
</description>
    </item>
    
    <item>
      <title>Session 10: Faceting, multi-plots, and animating</title>
      <link>https://biodash.github.io/codeclub/10_faceting-animating/</link>
      <pubDate>Wed, 17 Feb 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/10_faceting-animating/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;prep-homework&#34;&gt;Prep homework&lt;/h2&gt;
&lt;h3 id=&#34;basic-computer-setup&#34;&gt;Basic computer setup&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/04_ggplot2/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll help you troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;new-to-ggplot&#34;&gt;New to ggplot?&lt;/h3&gt;
&lt;p&gt;Check out the two Code Club pages for &lt;a href=&#34;https://biodash.github.io/codeclub/04_ggplot2/&#34;&gt;Session 4&lt;/a&gt; and &lt;a href=&#34;https://biodash.github.io/codeclub/05_ggplot-round-2/&#34;&gt;Session 5&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;ve never used &lt;code&gt;ggplot2&lt;/code&gt; before (or even if you have), you may find &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this cheat sheet&lt;/a&gt; useful.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;getting-started&#34;&gt;Getting Started&lt;/h2&gt;
&lt;h3 id=&#34;rmarkdown-for-todays-session&#34;&gt;RMarkdown for today&amp;rsquo;s session&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# directory for Code Club Session 2:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S10&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# directory for our RMarkdown&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# (&#34;recursive&#34; to create two levels at once.)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S10/Rmd/&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# save the url location for today&#39;s script&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;todays_R_script&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; 
  &lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/10_faceting-animating/Session10_faceting_animating_multifigs.Rmd&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# indicate the name of the new script file&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;Session10_Rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;S10/Rmd/Session10_faceting_animating_multifigs.Rmd&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# go get that file! &lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;todays_R_script&lt;/span&gt;,
              destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Session10_Rmd&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---how-can-i-do-more-with-my-figures&#34;&gt;1 - How can I do more with my figures?&lt;/h2&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=ggplot2_exploratory.png width=&#34;95%&#34; alt=&#34;ggplot2 exploratory cartoon&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Artwork by &lt;a href=&#34;https://github.com/allisonhorst/stats-illustrations&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Sometimes we have so much data that it is difficult to make sense of it if we look at it all at once. One way to get around this is to create &lt;a href=&#34;https://r4ds.had.co.nz/data-visualisation.html?q=facet#facets&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;facets&lt;/a&gt; in your data &amp;ndash; small subplots that help you to see different relationships among different variables in your dataset.&lt;/p&gt;
&lt;p&gt;Today we will be using &lt;a href=&#34;https://ggplot2.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplot2&lt;/code&gt;&lt;/a&gt; to make a series of plots that help us better understand the underlying structure in our dataset.&lt;/p&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;&lt;strong&gt;What will we go over today&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;These functions or packages will help you to get better visualize with your data.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/facet_wrap.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;facet_wrap()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/facet_grid.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;facet_grid()&lt;/code&gt;&lt;/a&gt;- makes small multiple plots based on some variable.&lt;/li&gt;
&lt;li&gt;set &lt;code&gt;scales&lt;/code&gt; to indicate the linked or not-linked nature of your axes in a faceted plot&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://www.rdocumentation.org/packages/gghighlight/versions/0.1.0&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;gghighlight()&lt;/code&gt;&lt;/a&gt; - allows you to direct focus on a particular portion of your data.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://patchwork.data-imaginist.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;patchwork&lt;/code&gt;&lt;/a&gt; - to compose super easy multi-plot figures&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://gganimate.com/articles/gganimate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;gganimate&lt;/code&gt;&lt;/a&gt; - to make your plots gif!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I will also go over a few tricks along the way.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2---accessing-our-data&#34;&gt;2 - Accessing our data&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Let&amp;rsquo;s get set up and grab some data so that we can learn more about this world (and ggplot2)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You can do this locally, or at OSC. You can find instructions if you are having trouble &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;First load your libraries. We are using a lot of new packages today.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;ve never downloaded these packages before, use the chunk below.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;gghighlight&#34;&lt;/span&gt;,
                   &lt;span class=&#39;s&#39;&gt;&#34;gganimate&#34;&lt;/span&gt;,
                   &lt;span class=&#39;s&#39;&gt;&#34;magick&#34;&lt;/span&gt;,
                   &lt;span class=&#39;s&#39;&gt;&#34;patchwork&#34;&lt;/span&gt;,
                   &lt;span class=&#39;s&#39;&gt;&#34;ggrepel&#34;&lt;/span&gt;,
                   &lt;span class=&#39;s&#39;&gt;&#34;gapminder&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Once you have the packages above downloaded, load your libraries.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/yutannihilation/gghighlight/&#39;&gt;gghighlight&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for bringing attention to certain parts of your plot&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://gganimate.com&#39;&gt;gganimate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for animating&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://docs.ropensci.org/magick/&#39;&gt;magick&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for rendering gifs and saving them&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://patchwork.data-imaginist.com&#39;&gt;patchwork&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for making multi-panel plots&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/slowkow/ggrepel&#39;&gt;ggrepel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for getting labels to not be on top of your points&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# data for today&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://github.com/jennybc/gapminder&#39;&gt;gapminder&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then let&amp;rsquo;s access the dataset &lt;code&gt;gapminder&lt;/code&gt;, which is both the name of the package, and the name of the dataset. It contains a subset of data from &lt;a href=&#34;https://www.gapminder.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Gapminder.org&lt;/a&gt;, an educational non-profit aimed to fight global misconceptions about statistics of our world.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=mega_gapminder.png width=&#34;95%&#34; alt=&#34;a big bubble plot showing the relationship between income and health of nations, with bubble size indicated by population size, and colored by region of the world&#34;&gt;
&lt;/p&gt;
&lt;p&gt;From &lt;a href=&#34;www.gapminder.org&#34;&gt;Gapminder.org&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s look at the data in &lt;code&gt;gapminder&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# look at the first 6 rows, all columns&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;gapminder&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   country     continent  year lifeExp      pop gdpPercap&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Afghanistan Asia       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;952    28.8  8&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;425&lt;/span&gt;&lt;span&gt;333      779.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Afghanistan Asia       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;957    30.3  9&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;240&lt;/span&gt;&lt;span&gt;934      821.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Afghanistan Asia       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;962    32.0 10&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;267&lt;/span&gt;&lt;span&gt;083      853.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Afghanistan Asia       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;967    34.0 11&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;537&lt;/span&gt;&lt;span&gt;966      836.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Afghanistan Asia       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;972    36.1 13&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;079&lt;/span&gt;&lt;span&gt;460      740.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Afghanistan Asia       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;977    38.4 14&lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;880&lt;/span&gt;&lt;span&gt;372      786.&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# check the structure&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# this tell us what is contained within our df&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;gapminder&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 1,704&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 6&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ country   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Afghanistan, Afghanistan, Afghanistan, Afghanistan, Afghani…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ continent &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia, Asia,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 1952, 1957, 1962, 1967, 1972, 1977, 1982, 1987, 1992, 1997,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ lifeExp   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 28.801, 30.332, 31.997, 34.020, 36.088, 38.438, 39.854, 40.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ pop       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 8425333, 9240934, 10267083, 11537966, 13079460, 14880372, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ gdpPercap &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 779.4453, 820.8530, 853.1007, 836.1971, 739.9811, 786.1134,…&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This dataset contains the following measurements about the life expectancy, population, and GDP per capita for 142 countries from 1952 to 2007. It includes the following variables:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;country&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;continent&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;year&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;lifeExp&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;pop&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;gdpPercap&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;em&gt;Note, this data is already in tidy-style format&lt;/em&gt; meaning:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Each variable must have its own column.&lt;/li&gt;
&lt;li&gt;Each observation must have its own row.&lt;/li&gt;
&lt;li&gt;Each value must have its own cell.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Learn more about tidy data &lt;a href=&#34;https://r4ds.had.co.nz/tidy-data.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To make things a bit less complex, let&amp;rsquo;s look at data just from the Americas (i.e., North and South America). To do that, we can use &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; like we learned using &lt;code&gt;dplyr&lt;/code&gt; back in &lt;a href=&#34;https://biodash.github.io/codeclub/02_dplyr-core-verbs/&#34;&gt;Code Club Session 2&lt;/a&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# make a df with data only from the Americas&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;gapminder_americas&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gapminder&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;continent&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Americas&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# what countries do we have?&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;gapminder_americas&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] Argentina           Bolivia             Brazil             &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [4] Canada              Chile               Colombia           &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [7] Costa Rica          Cuba                Dominican Republic &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [10] Ecuador             El Salvador         Guatemala          &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [13] Haiti               Honduras            Jamaica            &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [16] Mexico              Nicaragua           Panama             &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [19] Paraguay            Peru                Puerto Rico        &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [22] Trinidad and Tobago United States       Uruguay            &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [25] Venezuela          &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 142 Levels: Afghanistan Albania Algeria Angola Argentina Australia ... Zimbabwe&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3---life-expectancy-vstime&#34;&gt;3 - Life expectancy vs. time&lt;/h2&gt;
&lt;p&gt;We will plot the relationship between &lt;code&gt;lifeExp&lt;/code&gt; and &lt;code&gt;year&lt;/code&gt; with the goal of understanding how life expectancy has changed in the second half of the 20th century. We will use &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_path.html#:~:text=geom_line%28%29%20connects%20them%20in,which%20cases%20are%20connected%20together.&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_line()&lt;/code&gt;&lt;/a&gt; to make a line plot.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;gapminder_americas&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lifeExp&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_line&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-6-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This plot has so many countries, and we can only visually distinguish colors so well, that it makes this a bit of a mess. We can do better!&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4---highlighting&#34;&gt;4 - Highlighting&lt;/h2&gt;
&lt;p&gt;What if we want to highlight one country of interest, with the backdrop of all the data in the Americas? We can do this using &lt;a href=&#34;https://www.rdocumentation.org/packages/gghighlight/versions/0.1.0&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;gghighlight()&lt;/code&gt;&lt;/a&gt;, which will distinguish our country of interest, from the rest of the countries which will be indicated in gray.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s highlight the United States, and since we are at it, let&amp;rsquo;s also add x and y axis labels, a title, subtitle, and caption with &lt;code&gt;labs()&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;gapminder_americas&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lifeExp&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_line&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/gghighlight/man/gghighlight.html&#39;&gt;gghighlight&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;United States&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Year&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Life Expectancy (years)&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Life Expectancy in Countries in the Americas&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;From 1952 to 2007&#34;&lt;/span&gt;,
       caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data from gapminder.org&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Tried to calculate with group_by(), but the calculation failed.&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Falling back to ungrouped filter operation...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; label_key: country&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-7-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;5---faceting&#34;&gt;5 - Faceting&lt;/h2&gt;
&lt;p&gt;What if we want to see all the data at once, but just be able to better attribute each line to the correct country? We can use the &lt;a href=&#34;https://en.wikipedia.org/wiki/Small_multiple#&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;principle of small multiples&lt;/a&gt;, popularized by Edward Tufte, to make a series of charts all on the same scale to allow comparison between them easily.&lt;/p&gt;
&lt;p&gt;We can facet using &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/facet_wrap.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;facet_wrap&lt;/code&gt;&lt;/a&gt; to create small plots for each country. If you want a certain number of rows or columns you can indicate them by including &lt;code&gt;ncol&lt;/code&gt; and &lt;code&gt;nrow&lt;/code&gt; in the &lt;code&gt;facet_wrap()&lt;/code&gt; statement.&lt;/p&gt;
&lt;p&gt;I have also made the strip text, or the label on top of each of the facets bigger using &lt;code&gt;theme&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;gapminder_americas&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lifeExp&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_line&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;strip.text.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# facet_wrap(~country) also works&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Year&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Life Expectancy (years)&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Life Expectancy in Countries in the Americas&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;From 1952 to 2007&#34;&lt;/span&gt;,
       caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data from gapminder.org&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-8-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Now our legend is not necessary, so let&amp;rsquo;s remove it. Let&amp;rsquo;s also remove the gray background since its not really doing much for us. We will also change to &lt;code&gt;theme_minimal()&lt;/code&gt; to get rid of the grey background which I don&amp;rsquo;t think we need.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;gapminder_americas&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lifeExp&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_line&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;,
        strip.text.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;~&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Year&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Life Expectancy (years)&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Life Expectancy in Countries in the Americas&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;From 1952 to 2007&#34;&lt;/span&gt;,
       caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data from gapminder.org&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-9-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Wow better! But now its a bit hard to contextualize the line for each country to the whole dataset. We can fix this too.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;6---highlighting-plus-faceting&#34;&gt;6 - Highlighting plus faceting&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s bring the rest of data back in, and highlight in each facet the country of interest. We can do this by just adding &lt;a href=&#34;https://rdrr.io/pkg/gghighlight/man/gghighlight.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;gghighlight()&lt;/code&gt;&lt;/a&gt; to our &lt;code&gt;ggplot&lt;/code&gt; call.&lt;/p&gt;
&lt;p&gt;Note: if you want to assign something in R to an object, and then view it, you can put the whole thing in parentheses, without having to call that object back at the end.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;americas_lifeexp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gapminder_americas&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lifeExp&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_line&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/gghighlight/man/gghighlight.html&#39;&gt;gghighlight&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;,
        strip.text.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;~&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Year&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Life Expectancy (years)&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Life Expectancy in Countries in the Americas&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;From 1952 to 2007&#34;&lt;/span&gt;,
       caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data from gapminder.org&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; label_key: country&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Too many data series, skip labeling&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-10-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Wow, we now have so much more information about our data!&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;7---adjusting-scales-while-faceting&#34;&gt;7 - Adjusting scales while faceting&lt;/h2&gt;
&lt;p&gt;The default in faceting is that the x and y-axes for each plot are all the same. This aids in the interpretation of each small plot in relation to the others, but sometimes you may want freedom to adjust your axes.&lt;/p&gt;
&lt;p&gt;For example, if we wanted to plot population over time, if we used the same scale, it would be really hard to see trends within a country.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;americas_pop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gapminder_americas&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_line&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;,
        strip.text.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;~&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Year&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Population&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Population in Countries in the Americas&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;From 1952 to 2007&#34;&lt;/span&gt;,
       caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data from gapminder.org&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-11-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s change the scales so that the y-axis is &amp;ldquo;free&amp;rdquo; - i.e., each plot will have an independent y-axis. Note, when you do this, you aren&amp;rsquo;t really using the principle of small multiples anymore, since the data isn&amp;rsquo;t all on comparable scales.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;gapminder_americas&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_line&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;none&#34;&lt;/span&gt;,
        strip.text.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;size &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;14&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;~&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;,
             scales &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;free_y&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Year&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Population&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Population of Countries in the Americas&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;From 1952 to 2007&#34;&lt;/span&gt;,
       caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data from gapminder.org&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The default for &lt;code&gt;scales&lt;/code&gt; is &lt;code&gt;&amp;quot;fixed&amp;quot;&lt;/code&gt;, but you can also set to be &lt;code&gt;&amp;quot;free_x&amp;quot;&lt;/code&gt;, &lt;code&gt;&amp;quot;free_y&amp;quot;&lt;/code&gt;, or &lt;code&gt;&amp;quot;free&amp;quot;&lt;/code&gt;, which means both x and y are free.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;8---multi-panel-plots&#34;&gt;8 - Multi-panel plots&lt;/h2&gt;
&lt;p&gt;What if I take plots I&amp;rsquo;ve already made and assemble them together? You can do that simply with the package &lt;a href=&#34;https://patchwork.data-imaginist.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;patchwork()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=patchwork_1.jpg width=&#34;95%&#34; alt=&#34;an illustration of how to use patchwork with cute little monsters&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Artwork by &lt;a href=&#34;https://github.com/allisonhorst/stats-illustrations&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;You can use the syntax:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;plot1 + plot2&lt;/code&gt; to get two plots next to each other&lt;/li&gt;
&lt;li&gt;&lt;code&gt;plot1 / plot2&lt;/code&gt; to get two plots stacked vertically&lt;/li&gt;
&lt;li&gt;&lt;code&gt;plot1 | (plot2 + plot3)&lt;/code&gt; to get plot1 in the first row, and plots 2 and 3 in a second row&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You can use &lt;a href=&#34;https://patchwork.data-imaginist.com/reference/plot_annotation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;plot_annotation()&lt;/code&gt;&lt;/a&gt; to indicate your plots with letters or numbers.&lt;/p&gt;
&lt;p&gt;I am going to make some quick plots so we can see how it works. Let&amp;rsquo;s look at some plots of the United States.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# make df with just United States data&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;gapminder_usa&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gapminder&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;United States&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# make some plots&lt;/span&gt;
&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;usa_lifeexp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gapminder_usa&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lifeExp&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;usa_gdppercap&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gapminder_usa&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gdpPercap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_line&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;usa_pop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gapminder_usa&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_col&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-15-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s make multi-panel plots. If you need to wrap around a line, make sure you don&amp;rsquo;t start your line with the +, it won&amp;rsquo;t work (this is true for all &lt;code&gt;ggplot2&lt;/code&gt; syntax).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;usa_lifeexp&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa_gdppercap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;usa_pop&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://patchwork.data-imaginist.com/reference/plot_annotation.html&#39;&gt;plot_annotation&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Some plots about the United States&#34;&lt;/span&gt;,
                  tag_levels &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;A&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-16-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;You can see how this would be really useful for publications!&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;9---animating&#34;&gt;9 - Animating&lt;/h2&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=gganimate_fireworks.png width=&#34;95%&#34; alt=&#34;an illustration including fireworks showing an application og gganimate to make action plots, also including cute monsters&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Artwork by &lt;a href=&#34;https://github.com/allisonhorst/stats-illustrations&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Since we have time-scale data here, we could also build an animation that would help us look at our data. What if we wanted to look at how life expectancy (&lt;code&gt;lifeExp&lt;/code&gt;) and population (&lt;code&gt;pop&lt;/code&gt;) change over time? We could animate over the variable &lt;code&gt;year&lt;/code&gt;, and do this by using the function &lt;a href=&#34;https://gganimate.com/reference/animate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;animate()&lt;/code&gt;&lt;/a&gt;, and set &lt;a href=&#34;https://gganimate.com/reference/transition_states.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;transition_states()&lt;/code&gt;&lt;/a&gt; to the variable we are giffing over.&lt;/p&gt;
&lt;p&gt;Note, I have included &lt;code&gt;closest_state&lt;/code&gt; in the subtitle so the viewer can see what is the year at any stage of the animation.&lt;/p&gt;
&lt;p&gt;To be able to tell which dot belongs to which country, I added a &lt;a href=&#34;https://www.rdocumentation.org/packages/ggrepel/versions/0.9.1/topics/geom_label_repel&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_text_repel()&lt;/code&gt;&lt;/a&gt; statement, which labels each point but is smart enough to not let the labels overlap.&lt;/p&gt;
&lt;p&gt;I have also set &lt;code&gt;pop&lt;/code&gt; to be on a log10 scale.&lt;/p&gt;
&lt;p&gt;If you want to increase the resolution of your gif, and set the code chunk to &lt;code&gt;cache = TRUE&lt;/code&gt; if the chunk runs slowly, so that it doesn&amp;rsquo;t re-run when knitting if nothing has been edited, you can do this in the curly brackets at the top of your chunk, like this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;{r, cache = TRUE, dpi = 600}&lt;/code&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;transformr&#34;) &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# if you are having problems with gganimate you may need to install transformr&lt;/span&gt;

&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;gapminder_americas&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;lifeExp&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;pop&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;, label &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;country&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;21&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/ggrepel/man/geom_text_repel.html&#39;&gt;geom_text_repel&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;scale_y_log10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;none&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Population and Life Expectancy in the Americas&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Year: &amp;#123;closest_state&amp;#125;&#39;&lt;/span&gt;, 
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Life Expectancy&#34;&lt;/span&gt;, 
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Log10 Population&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://gganimate.com/reference/transition_states.html&#39;&gt;transition_states&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=gapminder_gif.gif width=&#34;95%&#34;&gt;
&lt;/p&gt;
&lt;p&gt;There are many different ways to transition your data in &lt;code&gt;gganimate&lt;/code&gt; - and you can learn more about them &lt;a href=&#34;https://gganimate.com/reference/index.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Saving my gif&lt;/p&gt;
&lt;p&gt;Now I want to save my gif. We can do that simply with the function &lt;a href=&#34;https://gganimate.com/reference/anim_save.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;anim_save()&lt;/code&gt;&lt;/a&gt; which works a lot like &lt;code&gt;ggsave()&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# set parameters for your animation&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://gganimate.com/reference/animate.html&#39;&gt;animate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;p&lt;/span&gt;, 
        duration &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, 
        fps &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, 
        width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;700&lt;/span&gt;, 
        height &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;700&lt;/span&gt;,
        renderer &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://gganimate.com/reference/renderers.html&#39;&gt;magick_renderer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# save it&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://gganimate.com/reference/anim_save.html&#39;&gt;anim_save&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;filename &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;gapminder_gif.gif&#34;&lt;/span&gt;,
          animation &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://gganimate.com/reference/last_animation.html&#39;&gt;last_animation&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
          path &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;/Users/jessicacooperstoneimac&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;10---breakout-rooms&#34;&gt;10 - Breakout rooms&lt;/h2&gt;
&lt;h2 id=&#34;loading-data-and-get-set-up&#34;&gt;Loading data and get set up&lt;/h2&gt;
&lt;p&gt;Load the &lt;code&gt;palmerpenguins&lt;/code&gt; dataset, look at its structure, and view the beginning of the df.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; tibble [344 × 8] (S3: tbl_df/tbl/data.frame)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ species          : Factor w/ 3 levels &#34;Adelie&#34;,&#34;Chinstrap&#34;,..: 1 1 1 1 1 1 1 1 1 1 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ island           : Factor w/ 3 levels &#34;Biscoe&#34;,&#34;Dream&#34;,..: 3 3 3 3 3 3 3 3 3 3 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ bill_length_mm   : num [1:344] 39.1 39.5 40.3 NA 36.7 39.3 38.9 39.2 34.1 42 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ bill_depth_mm    : num [1:344] 18.7 17.4 18 NA 19.3 20.6 17.8 19.6 18.1 20.2 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ flipper_length_mm: int [1:344] 181 186 195 NA 193 190 181 195 193 190 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ body_mass_g      : int [1:344] 3750 3800 3250 NA 3450 3650 3625 4675 3475 4250 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ sex              : Factor w/ 2 levels &#34;female&#34;,&#34;male&#34;: 2 1 1 NA 1 2 1 2 NA NA ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ year             : int [1:344] 2007 2007 2007 2007 2007 2007 2007 2007 2007 2007 ...&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g sex  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;           &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.1          18.7              181        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;750 male &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.5          17.4              186        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;800 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Adelie  Torge…           40.3          18                195        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;250 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Adelie  Torge…           &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Adelie  Torge…           36.7          19.3              193        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;450 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.3          20.6              190        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;650 male &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1 more variable: year &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;main-exercises&#34;&gt;Main exercises&lt;/h3&gt;
&lt;h4 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Like we did in &lt;a href=&#34;https://biodash.github.io/codeclub/08_pivoting/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Code Club 7&lt;/a&gt;, convert the two columns about penguin bill dimensions &lt;code&gt;bill_length_mm&lt;/code&gt; and &lt;code&gt;bill_depth_mm&lt;/code&gt; to two columns called &lt;code&gt;bill_dimension&lt;/code&gt; and &lt;code&gt;value&lt;/code&gt;. Drop your NAs also. Save this as a new df called &lt;code&gt;penguins_long&lt;/code&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Use a combination of &lt;code&gt;drop_na()&lt;/code&gt; and &lt;code&gt;pivot_longer()&lt;/code&gt;, and it&amp;rsquo;s helpful if you also set &lt;code&gt;names_prefix&lt;/code&gt; in your &lt;code&gt;pivot_longer()&lt;/code&gt; statement but not totally necessary. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;pivot_longer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;,
               names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;bill_dimension&#34;&lt;/span&gt;,
               values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;value_mm&#34;&lt;/span&gt;,
               names_prefix &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;bill_&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_long&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island flipper_length_… body_mass_g sex    year bill_dimension&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;             &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie  Torge…              181        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;750 male   &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007 length_mm     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Adelie  Torge…              181        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;750 male   &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007 depth_mm      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Adelie  Torge…              186        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;800 fema…  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007 length_mm     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Adelie  Torge…              186        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;800 fema…  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007 depth_mm      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Adelie  Torge…              195        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;250 fema…  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007 length_mm     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Adelie  Torge…              195        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;250 fema…  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007 depth_mm      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1 more variable: value_mm &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Plot body mass (&lt;code&gt;body_mass_g&lt;/code&gt;) as related to bill length and depth.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Faceting will be useful here. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;value_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_dimension&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-21-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Take your plot from Exercise 2 and make it prettier. You can do things like change your axis labels, add title, change themes as you see fit. Color your points by &lt;code&gt;sex&lt;/code&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Pick a theme you like. &lt;code&gt;theme_classic()&lt;/code&gt; is a good place to start, and if you want to download the package &lt;code&gt;hrbrthemes&lt;/code&gt;, I really like the &lt;a href=&#34;https://rdrr.io/pkg/hrbrthemes/man/theme_ipsum_rc.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;theme_ipsum_rc()&lt;/code&gt;&lt;/a&gt;.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;p&gt;I&amp;rsquo;ve included some code that let&amp;rsquo;s you re-name the strip text, or the text that is above each of your facets. You do this with the &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/labeller.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;labeller()&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://github.com/hrbrmstr/hrbrthemes&#39;&gt;hrbrthemes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# for pretty &amp;amp; easy themes&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# formatting facet strip text labels&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dim_mm&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Culman Bill Depth&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Culman Bill Length&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/names.html&#39;&gt;names&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dim_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;depth_mm&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;length_mm&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# this is just one example&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;value_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/hrbrthemes/man/theme_ipsum_rc.html&#39;&gt;theme_ipsum_rc&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;axis.title.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
        axis.title.y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
        strip.text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Body Mass (g)&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;mm&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill length and depth vs. body mass in penguins&#34;&lt;/span&gt;,
       color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Sex&#34;&lt;/span&gt;,
       caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data from https://allisonhorst.github.io/palmerpenguins/&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_dimension&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
             labeller &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;labeller&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;bill_dimension &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dim_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-22-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Add a second dimension of faceting by &lt;code&gt;species&lt;/code&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;You do this within your &lt;code&gt;facet_wrap()&lt;/code&gt; call. You might want to try the formula syntax, which works like this: &lt;code&gt;var1~var2&lt;/code&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;value_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/hrbrthemes/man/theme_ipsum_rc.html&#39;&gt;theme_ipsum_rc&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;axis.title.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
        axis.title.y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
        strip.text &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Body Mass (g)&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;mm&#34;&lt;/span&gt;,
       title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill length and depth vs. body mass in penguins&#34;&lt;/span&gt;,
       color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Sex&#34;&lt;/span&gt;,
       caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data from https://allisonhorst.github.io/palmerpenguins/&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_dimension&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;~&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;,
             labeller &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;labeller&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;bill_dimension &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dim_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-23-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;exercise-5&#34;&gt;Exercise 5&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Using your plot from Exercise 3, highlight the datapoints coming from Dream Island in purple.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;You can use syntax inside &lt;a href=&#34;https://rdrr.io/pkg/gghighlight/man/gghighlight.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;gghighlight()&lt;/code&gt;&lt;/a&gt; just like you do in &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# what are our islands?&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_long&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] Torgersen Biscoe    Dream    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Levels: Biscoe Dream Torgersen&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;penguins_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;value_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;purple&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/gghighlight/man/gghighlight.html&#39;&gt;gghighlight&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Dream&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_dimension&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-24-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;exercise-6&#34;&gt;Exercise 6&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Using your sample plot for Exercise 3, highlight penguins that have a &lt;code&gt;body_mass_g&lt;/code&gt; less than 3500 g, in blue.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;You can use syntax inside &lt;a href=&#34;https://rdrr.io/pkg/gghighlight/man/gghighlight.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;gghighlight()&lt;/code&gt;&lt;/a&gt; just like you do in &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt;, and you can also use these filter functions like &lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;lt;&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;gt;&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://rdrr.io/r/base/Comparison.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;&amp;lt;=&lt;/code&gt;&lt;/a&gt;, &lt;a href=&#34;https://rdrr.io/r/base/Logic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;!&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;AND&lt;/code&gt; inside your call. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# what are our islands?&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_long&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] Torgersen Biscoe    Dream    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Levels: Biscoe Dream Torgersen&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;penguins_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;value_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;blue&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/gghighlight/man/gghighlight.html&#39;&gt;gghighlight&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Dream&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;facet_wrap&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;vars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_dimension&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-25-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-exercises&#34;&gt;Bonus exercises&lt;/h3&gt;
&lt;h4 id=&#34;bonus-1&#34;&gt;Bonus 1&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Plot &lt;code&gt;flipper_length_mm&lt;/code&gt; vs. &lt;code&gt;body_mass_g&lt;/code&gt; and animate the plot to show only one &lt;code&gt;species&lt;/code&gt; at a time.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Try animating over &lt;code&gt;species&lt;/code&gt;, using &lt;a href=&#34;https://gganimate.com/reference/transition_states.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;transition_states()&lt;/code&gt;&lt;/a&gt; and set &lt;code&gt;{closest_state}&lt;/code&gt; in your title or subtitle so you can tell what you&amp;rsquo;re looking at. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;flipper_by_BW&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;21&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;black&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;legend.position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;none&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Population and Life Expectancy in the Americas&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Penguin Species: &amp;#123;closest_state&amp;#125;&#39;&lt;/span&gt;, 
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Body Mass (g)&#34;&lt;/span&gt;, 
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Flipper Length (mm)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://gganimate.com/reference/transition_states.html&#39;&gt;transition_states&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://gganimate.com/reference/animate.html&#39;&gt;animate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flipper_by_BW&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=flippers_by_mass.gif width=&#34;95%&#34;&gt;
&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;bonus-2&#34;&gt;Bonus 2&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;You have now made an excellent gif, so save it!&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Use &lt;a href=&#34;https://gganimate.com/reference/anim_save.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;anim_save()&lt;/code&gt;&lt;/a&gt; to save your animation, which works in a similar way to &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/ggsave.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggsave()&lt;/code&gt;&lt;/a&gt;, which is another very useful function. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# set parameters for your animation&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://gganimate.com/reference/animate.html&#39;&gt;animate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;flipper_by_BW&lt;/span&gt;, 
        duration &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, 
        fps &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;, 
        width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;700&lt;/span&gt;, 
        height &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;700&lt;/span&gt;,
        renderer &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://gganimate.com/reference/renderers.html&#39;&gt;magick_renderer&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# save it&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://gganimate.com/reference/anim_save.html&#39;&gt;anim_save&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;filename &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;flippers_by_mass.gif&#34;&lt;/span&gt;,
          animation &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://gganimate.com/reference/last_animation.html&#39;&gt;last_animation&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
          path &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;YOUR_PATH_HERE&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;bonus-3&#34;&gt;Bonus 3&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Let&amp;rsquo;s practice making multi-panel plots. Plot:&lt;/p&gt;
&lt;p&gt;Boxplot of &lt;code&gt;body_mass_g&lt;/code&gt; by &lt;code&gt;sex&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Histogram of number of observations per &lt;code&gt;island&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Distribution of &lt;code&gt;flipper_length_mm&lt;/code&gt; by &lt;code&gt;species&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Tag your plots so each has a lowercase letter associated with it.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Use the syntax from the package &lt;code&gt;patchwork&lt;/code&gt;. You can learn more &lt;a href=&#34;https://patchwork.data-imaginist.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;. Also use &lt;a href=&#34;https://patchwork.data-imaginist.com/reference/plot_annotation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;plot_annotation()&lt;/code&gt;&lt;/a&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;title&lt;/code&gt; allows you to set a title&lt;/li&gt;
&lt;li&gt;&lt;code&gt;tag_levels&lt;/code&gt; allows you to determine how you want your panels to be tagged.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Boxplot of &lt;code&gt;body_mass_g&lt;/code&gt; by &lt;code&gt;sex&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_mass_by_sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;penguins_mass_by_sex&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-28-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Histogram of number of observations per &lt;code&gt;island&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_by_island&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_histogram&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;stat &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;count&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Ignoring unknown parameters: binwidth, bins, pad&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;penguins_by_island&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-29-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Distribution of &lt;code&gt;flipper_length_mm&lt;/code&gt; by &lt;code&gt;species&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_flipper_species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://ggplot2.tidyverse.org/reference/aes.html&#39;&gt;aes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;flipper_length_mm&lt;/span&gt;, group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_density&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;scale_fill_viridis_d&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;penguins_flipper_species&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-30-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_flipper_species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;/&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_mass_by_sex&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins_by_island&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://patchwork.data-imaginist.com/reference/plot_annotation.html&#39;&gt;plot_annotation&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Looking at penguins...&#34;&lt;/span&gt;,
                  tag_levels &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-31-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Session 9: Subsetting</title>
      <link>https://biodash.github.io/codeclub/09_subsetting/</link>
      <pubDate>Wed, 10 Feb 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/09_subsetting/</guid>
      <description>&lt;figure&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=&#34;shaker.png&#34; width=&#34;35%&#34;&gt;
&lt;figcaption&gt;
Image from &lt;a href=&#34;https://r4ds.had.co.nz&#34; class=&#34;uri&#34;&gt;https://r4ds.had.co.nz&lt;/a&gt;
&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New To Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has some pointers that might be helpful if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Please open RStudio before Code Club to test things out &amp;ndash; if you run into issues, join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Learn the uses of R&amp;rsquo;s three basic subsetting operators: &lt;code&gt;[ ]&lt;/code&gt;, &lt;code&gt;[[ ]]&lt;/code&gt;, and &lt;a href=&#34;https://rdrr.io/r/base/Extract.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;$&lt;/code&gt;&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Learn how the behavior of these operators varies depending on the &lt;strong&gt;data structure&lt;/strong&gt; you are subsetting (vector, matrix, list, or data frame).&lt;/li&gt;
&lt;li&gt;Prepare to learn how these resemble, and differ from, subsetting operators in Python.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;intro-what-is-subsetting-anyway&#34;&gt;Intro: What is &amp;lsquo;subsetting&amp;rsquo; anyway?&lt;/h2&gt;
&lt;p&gt;Subsetting (also known as indexing) is simply a formal way of pulling out specific pieces of a data structure. We&amp;rsquo;ve already seen two &lt;strong&gt;dplyr&lt;/strong&gt; verbs that perform this kind of operation for tibbles: &lt;code&gt;filter&lt;/code&gt; (to pull out specific rows) and &lt;code&gt;select&lt;/code&gt; (to pull out specific columns).&lt;/p&gt;
&lt;p&gt;But these are tidyverse commands, and only work with tibbles. R has two more-basic data structures, vectors and lists, and for these we need different subsetting operators. We&amp;rsquo;ll also see that matrices are simply a special kind of vector, that data frames are a special kind of list, and basic subsetting operators also work for these.&lt;/p&gt;
&lt;p&gt;Since the behavior of these operators depends on the actual data structure you are working with, it&amp;rsquo;s useful when experimenting to use them in conjunction with the &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; function, which compactly displays the internal structure of an arbitrary R object. A knowledge of the make-up of these data structures is also important when you come to write your own loops, iterations, and functions.&lt;/p&gt;
&lt;p&gt;The most important distinction between vectors and lists is that vectors are &lt;strong&gt;homogeneous&lt;/strong&gt;, while lists can be &lt;strong&gt;heterogeneous&lt;/strong&gt;.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;&lt;em&gt;Terminological note&lt;/em&gt;: &amp;lsquo;under-the-hood&amp;rsquo; both of these are vectors in the technical sense, and sometimes the distinction is referred to as &lt;strong&gt;atomic vectors&lt;/strong&gt; versus &lt;strong&gt;recursive vectors&lt;/strong&gt;. I&amp;rsquo;ll continue to use just &amp;lsquo;vector&amp;rsquo; and &amp;lsquo;list&amp;rsquo; here. This usage also lines-up with Python.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;vectors&#34;&gt;Vectors&lt;/h2&gt;
&lt;p&gt;A vector is absolutely the most basic data structure in R. Every value in a vector must be of the &lt;strong&gt;same type&lt;/strong&gt;. Strikingly, this sets R apart from Python. Using this kind of vector in Python requires loading a whole separate package: &lt;code&gt;numpy&lt;/code&gt;. The most basic data structure in Python is the list.&lt;/p&gt;
&lt;p&gt;There are four basic types of vector: integer, double, character, and logical. Vectors are created by hand with the &lt;a href=&#34;https://rdrr.io/r/base/c.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;c()&lt;/code&gt;&lt;/a&gt; (combine, concatenate) function. We can check the type with the &lt;a href=&#34;https://rdrr.io/r/base/typeof.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;typeof()&lt;/code&gt;&lt;/a&gt; operator. This is totally redundant if you just created the vector yourself, but when you are debugging code or creating a vector using an expression you might want to check exactly what type of vector is being used:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;vec_dbl&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_dbl&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;double&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;vec_int&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1L&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2L&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3L&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4L&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5L&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_int&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;integer&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;vec_which&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/seq.html&#39;&gt;seq&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_which&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;integer&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;vec_which2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_which2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;integer&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;vec_log&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_log&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;logical&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;vec_chr&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;b&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;c&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;d&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;e&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_chr&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;character&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What happens when we perform a basic mathematical operation on a vector?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;*&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;vec_int&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  2  4  6  8 10&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;(This is &lt;em&gt;completely different&lt;/em&gt; than what you obtain when multiplying a Python list).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;n&#34;&gt;L&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;3&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;4&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;mi&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;
&lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;L&lt;/span&gt;
&lt;span class=&#34;c1&#34;&gt;# [1, 2, 3, 4, 5, 1, 2, 3, 4, 5]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;So it&amp;rsquo;s not just that vectors are a basic R data structure, but R is a &lt;strong&gt;vectorised language&lt;/strong&gt;. In many cases applying an operation to a vector automagically applies the operation to every element in the vector. This means that for many basic operations &lt;code&gt;for&lt;/code&gt; loops and mapping functions, necessary in Python, are not needed in R (although if you write your own functions you will need these iteration tools). In Python we could use a &amp;lsquo;list comprehension&amp;rsquo; (a compact and fast version of a &lt;code&gt;for&lt;/code&gt; loop):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span class=&#34;p&#34;&gt;[&lt;/span&gt;&lt;span class=&#34;mi&#34;&gt;2&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;*&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;k&#34;&gt;for&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;i&lt;/span&gt; &lt;span class=&#34;ow&#34;&gt;in&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;L&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;]&lt;/span&gt;
&lt;span class=&#34;c1&#34;&gt;# [2, 4, 6, 8, 10]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Or install the &lt;code&gt;numpy&lt;/code&gt; package that makes vectors and vectorized functions available.&lt;/p&gt;
&lt;p&gt;Vectors have an insanely simple structure:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;vec_dbl&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  num [1:5] 1 2 3 4 5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; also displays the type, and RStudio displays the result of &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; in the Values pane.&lt;/p&gt;
&lt;p&gt;For such a simple structure, there are a surprisingly large number of ways to subset a vector. We&amp;rsquo;ll use the following example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2.1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4.2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3.3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5.4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;(Notice that the number after the decimal point indicates the position (index) of the element of the vector.)&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Positive integers&lt;/strong&gt; return elements at the specified positions. Any expression that evaluates to a vector of positive integers can be used as the index. The index operator is &lt;code&gt;[]&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3.3&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3.3 2.1&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.2 3.3 5.4&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/seq.html&#39;&gt;seq&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2.1 3.3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;(In R the indices run from 1 to the length of the object: in Python indices run from 0 to length-1).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Negative integers&lt;/strong&gt; exclude elements at the specified positions:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2.1 4.2 5.4&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.2 5.4&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.2 5.4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Logical vectors&lt;/strong&gt; select elements where the corresponding logical value is TRUE. This is most useful if you can write a &lt;strong&gt;comparison expression&lt;/strong&gt; &lt;code&gt;2 &amp;gt; 3&lt;/code&gt;, &lt;code&gt;4 == 4&lt;/code&gt;, that returns TRUE (or FALSE) for each element of the vector:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;, &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2.1 4.2&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.2 3.3 5.4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Attributes&lt;/strong&gt;. One of the unusual features of R as opposed to Python is that you can assign metadata of various kinds to the elements of vectors (and lists). For example, we can assign a &lt;strong&gt;name&lt;/strong&gt; to each element, and then use a character vector as the index expression:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;a &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2.1&lt;/span&gt;, b &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;4.2&lt;/span&gt;, c &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3.3&lt;/span&gt;, d &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5.4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Named num [1:4] 2.1 4.2 3.3 5.4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  - attr(*, &#34;names&#34;)= chr [1:4] &#34;a&#34; &#34;b&#34; &#34;c&#34; &#34;d&#34;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;d&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;c&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   d   c   a &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5.4 3.3 2.1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;(Again, Python has no direct equivalent of this, but we can get a similar effect using a &lt;em&gt;dictionary&lt;/em&gt; data structure, which explicitly assigns a name to each value).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Nothing&lt;/strong&gt; (&lt;code&gt;[]&lt;/code&gt;) returns the entire vector:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2.1 4.2 3.3 5.4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This is not useful for (one dimensional) vectors, but is behind the notation for extracting rows and columns from matrices. Keep in mind a &amp;ldquo;nothing&amp;rdquo; index returns &amp;ldquo;everything&amp;rdquo;.&lt;/p&gt;
&lt;h2 id=&#34;matrices&#34;&gt;Matrices&lt;/h2&gt;
&lt;p&gt;A matrix is simply a vector with a &lt;strong&gt;dimensions&lt;/strong&gt; attribute. Here we convert a vector to a two-dimensional matrix, with two rows and three columns, with &lt;a href=&#34;https://rdrr.io/r/base/dim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dim(rows, cols)&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;z&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2.1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4.2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3.3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5.4&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;8.5&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1.6&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;z&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;z&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;      [,1] [,2] [,3]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1,]  2.1  3.3  8.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [2,]  4.2  5.4  1.6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now we can index a specific value using comma notation, where the &lt;em&gt;first&lt;/em&gt; index specifies the row, and the &lt;em&gt;second&lt;/em&gt; index the &lt;em&gt;column&lt;/em&gt; (in Python this is reversed):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;z&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1.6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And in two dimensions the &lt;strong&gt;nothing&lt;/strong&gt; after the &lt;code&gt;,&lt;/code&gt; returns &lt;strong&gt;every&lt;/strong&gt; column for that row:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;z&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;,&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.2 5.4 1.6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And here is a way of selecting a submatrix (every row for all columns except the first):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;z&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;,&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;      [,1] [,2]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1,]  3.3  8.5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [2,]  5.4  1.6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;lists&#34;&gt;Lists&lt;/h2&gt;
&lt;p&gt;There are two main differences between vectors and lists: (i) lists can contain elements of &lt;strong&gt;different types&lt;/strong&gt;; and (ii) lists can contain &lt;strong&gt;other lists&lt;/strong&gt;. This is why lists are sometimes referred to as &lt;strong&gt;recursive vectors&lt;/strong&gt;. We will see examples of these below, but first let&amp;rsquo;s directly compare a &lt;em&gt;list&lt;/em&gt; of numbers to a &lt;em&gt;vector&lt;/em&gt; of numbers, and examine the structure. Lists are constructed with the &lt;a href=&#34;https://rdrr.io/r/base/list.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;list()&lt;/code&gt;&lt;/a&gt; function.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;l&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2.1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4.2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3.3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5.4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;l&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[3]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[4]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5.4&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;l&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 2.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 4.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 3.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 5.4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Here we see the appearance of a new subsetting operator &lt;code&gt;[[ ]]&lt;/code&gt;. What does it yield?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;ll_2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;l&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;ll_2&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.2&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ll_2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;double&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now compare this to the result of using the &lt;code&gt;[ ]&lt;/code&gt; operator:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;l_2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;l&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;l_2&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.2&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;l_2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;list&#34;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;l_2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 4.2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The behavior of the &lt;code&gt;[ ]&lt;/code&gt; operator is very different for lists: it selects the element(s) you request, but &lt;em&gt;it always returns a subsetted version of the original list&lt;/em&gt;. It &amp;lsquo;shrinks&amp;rsquo; the original list. There is nothing like this in Python; it&amp;rsquo;s quite unique to R. (The reason this is the case will become clear when we examine data frames.) The &lt;code&gt;[[ ]]&lt;/code&gt; operator on the other hand just returns the object you select.&lt;/p&gt;
&lt;p&gt;As mentioned above, it&amp;rsquo;s quite possible that an element of a list might itself be a list:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;m&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2.1&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4.21&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4.22&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3.3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5.4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;m&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]][[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.21&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]][[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.22&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[3]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[4]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5.4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This (print) output focuses on content, whereas the &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; function focuses on structure, and is very useful for nested lists:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;m&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 2.1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ :List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ : num 4.21&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ : num 4.22&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 3.3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 5.4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Once we combine nested lists and multiple types, things can get pretty hairy. There are various ways to visualize what&amp;rsquo;s going on. Here is one example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x3&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;img src=&#34;lists_structure.png&#34; style=&#34;width:75.0%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;However the printed form provides us a clue on how to extract an individual element from inside a nested list:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# m &amp;lt;- list(2.1, list(4.21, 4.22), 3.3, 5.4)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;m&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.21&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.22&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;m&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4.21&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In short, &lt;code&gt;[[ ]]&lt;/code&gt; drills down into a list, while &lt;code&gt;[ ]&lt;/code&gt; returns a diminished version of the original list.&lt;/p&gt;
&lt;p&gt;Here&amp;rsquo;s a visualization of various list subsetting operations:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;a string&#34;&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;pi&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;a string&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[3]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3.141593&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[4]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[4]][[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[4]][[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] -5&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;a&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : int [1:3] 1 2 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : chr &#34;a string&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : num 3.14&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ :List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ : num -1&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ : num -5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;figure&gt;&lt;img src=&#34;lists_subsetting.png&#34; style=&#34;width:75.0%&#34; alt=&#34;&#34; /&gt;&lt;figcaption&gt;Subsetting a list, visually.&lt;/figcaption&gt;&lt;/figure&gt;
&lt;p&gt;Here is a recursive pepper shaker, &lt;code&gt;p&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;shaker.png&#34; style=&#34;width:25.0%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Here is the first packet, but still inside the shaker, &lt;code&gt;p[1]&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;shaker_first_packet.png&#34; style=&#34;width:25.0%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Here is the first packet by itself, &lt;code&gt;p[[1]]&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;packet.png&#34; style=&#34;width:25.0%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;And here is the contents of that packet, &lt;code&gt;p[[1]][[1]]&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;pepper.png&#34; style=&#34;width:25.0%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll play with yet another type of visualization in the exercises.&lt;/p&gt;
&lt;h2 id=&#34;data-frames&#34;&gt;Data frames&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s look at a simple data frame:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;b&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;c&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/typeof.html&#39;&gt;typeof&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;list&#34;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &#39;data.frame&#39;:  3 obs. of  2 variables:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ x: int  1 2 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ y: chr  &#34;a&#34; &#34;b&#34; &#34;c&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;So a data frame is basically a list (of columns), with a names attribute for the column names; and with the extra condition that all the columns are of the same length. So we should be able to use our standard list subsetting operators on it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df_col_1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df_col_1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &#39;data.frame&#39;:  3 obs. of  1 variable:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ x: int  1 2 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Since a data frame is a list, subsetting using &lt;code&gt;[ ]&lt;/code&gt; returns the specified column still inside a data frame. What about &lt;code&gt;[[ ]]&lt;/code&gt;?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;col_1&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;col_1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  int [1:3] 1 2 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Using &lt;code&gt;[[ ]]&lt;/code&gt; returns the individual column.&lt;/p&gt;
&lt;p&gt;We can also subset a data frame by name:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df_name&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;x&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df_name&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &#39;data.frame&#39;:  3 obs. of  1 variable:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ x: int  1 2 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df_nname&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;x&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df_nname&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  int [1:3] 1 2 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Finally &lt;code&gt;df$x&lt;/code&gt; is simply a shorthand for &lt;code&gt;df[[&amp;quot;x&amp;quot;]]&lt;/code&gt; without the &lt;code&gt;[[ ]]&lt;/code&gt; and the &lt;code&gt;&amp;quot; &amp;quot;&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df_dollar_name&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df_dollar_name&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  int [1:3] 1 2 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Just as a matter of interest, in the grand scheme of things lists are just a special kind of vector (a &amp;lsquo;heterogeneous recursive vector&amp;rsquo;), so it should be possible to stick a list column into a data frame. We can, but we have to use the &lt;code&gt;I&lt;/code&gt; &amp;lsquo;identity&amp;rsquo; operator around the list:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;df_mixed&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, 
  y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/AsIs.html&#39;&gt;I&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;4L&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;7.2&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;string&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;df_mixed&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &#39;data.frame&#39;:  3 obs. of  2 variables:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ x: int  1 2 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ y:List of 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ : int 4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ : num 7.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ : chr &#34;string&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..- attr(*, &#34;class&#34;)= chr &#34;AsIs&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id=&#34;further-reading-and-acknowledgement&#34;&gt;Further reading and acknowledgement&lt;/h4&gt;
&lt;p&gt;For more details on subsetting see &lt;a href=&#34;https://r4ds.had.co.nz/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R for Data Science&lt;/a&gt; and &lt;a href=&#34;https://adv-r.hadley.nz&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Advanced R&lt;/a&gt; both by Hadley Wickham, from which much of the material in this module was borrowed.&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;A surprisingly useful operator for extracting elements of a numerical vector is the modulo operator &lt;code&gt;x %% y&lt;/code&gt;. This returns the remainder when &lt;code&gt;x&lt;/code&gt; is divided by &lt;code&gt;y&lt;/code&gt;. It is a vectorized operation, so we can apply it to a list.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;9&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%%&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] 1 2 0 1 2 0 1 2 0 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Use this operator to extract every third element of the above vector &lt;code&gt;x&lt;/code&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;&lt;br&gt;Check the example in the presentation about selecting elements when the logical comparison is TRUE. What is the logical test we need to identify every third element? &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solution (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;7&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;8&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;9&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%%&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3 6 9&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Here is a visualization of a list:&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;train_total.jpg&#34; style=&#34;width:75.0%&#34; /&gt;&lt;/p&gt;
&lt;p&gt;Create a list in R called &lt;code&gt;train&lt;/code&gt; that captures this structure. Print the list, and also display its structure.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;&lt;br&gt;This list has no nested lists, it&amp;rsquo;s just a list of vectors and individual values. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solution (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;train&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;train&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;a&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[3]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4 5 6&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;train&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : int [1:3] 1 2 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : chr &#34;a&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : int [1:3] 4 5 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;For each of the following sub-trains/carriages, determine the subsetting expression by eye, and then check that it works by subsetting your &lt;code&gt;train&lt;/code&gt; list from exercise 1.&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;trains_2.jpg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt; &lt;br&gt; There&#39;s more than one way to do these; you will have to use both `[ ]` and `[[ ]]` operators. The last two are tricky, experiment with them... &lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solution (click here) &lt;/summary&gt; &lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;train&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;train&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;train&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;a&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;train&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 4 5 6&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;train&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[1]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [[2]]&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;train&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;0&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; list()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;A common use of recursive structures in biology is to represent phylogenetic trees. Create a recursive list in R called &lt;code&gt;tree&lt;/code&gt; which captures the following visual representation&lt;/p&gt;
&lt;p&gt;&lt;img src=&#34;tree.jpg&#34; alt=&#34;&#34;&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt; &lt;br&gt;Start at the top and work down. Start with a simpler subtree, then expand terminals.
&lt;p&gt;Alternatively, start at the bottom with the smallest subtree, then work up, adding sisters into parent nodes.&lt;/p&gt;
&lt;p&gt;In either case, check your working with &lt;a href=&#34;https://rdrr.io/r/utils/str.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;str()&lt;/code&gt;&lt;/a&gt; as you incrementally add structure.&lt;/p&gt;
&lt;p&gt;Notice this is a binary branching tree, so the root node of every subtree should contain two elements.&lt;/p&gt;
&lt;p&gt;One of the tricks with these nested lists is to keep track of paired parentheses&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Stay calm and recurse.&lt;/strong&gt; &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solution (click here) &lt;/summary&gt; &lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;tree&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;a&#34;&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;b&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;c&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;d&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tree&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ : chr &#34;a&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ :List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ :List of 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ : chr &#34;b&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   .. ..$ : chr &#34;c&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   ..$ : chr &#34;d&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Session 8: Reshaping Your Data</title>
      <link>https://biodash.github.io/codeclub/08_pivoting/</link>
      <pubDate>Tue, 02 Feb 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/08_pivoting/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Describe differences in long data vs wide data.&lt;/li&gt;
&lt;li&gt;Identify scenarios where it might be helpful to have data in one format over another (longer vs. wider).&lt;/li&gt;
&lt;li&gt;Use the functions &lt;code&gt;pivot_longer()&lt;/code&gt; and &lt;code&gt;pivot_wider()&lt;/code&gt; to reshape data.&lt;/li&gt;
&lt;li&gt;Use NHANES data to address whether blood pressure values vary in a predictable way with successive measurements.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;intro-the-shape-of-a-dataset&#34;&gt;Intro: The Shape Of A Dataset&lt;/h2&gt;
&lt;p&gt;A single set of data can sometimes be stored in different ways, or in other words, it can have different shapes. Below is a small example. It&amp;rsquo;s a hypothetical dataset that stores the number of visitors at each of two parks over a long weekend, and we&amp;rsquo;ll look at two different versions of it&amp;hellip;&lt;/p&gt;
&lt;h3 id=&#34;wide-format&#34;&gt;Wide Format&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#create the dataset&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;visitors_wide&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;park&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;north_park&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;south_park&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
                   &lt;span class=&#39;s&#39;&gt;&#34;Fri&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;65&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;80&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                   &lt;span class=&#39;s&#39;&gt;&#34;Sat&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;184&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;160&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                   &lt;span class=&#39;s&#39;&gt;&#34;Sun&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;135&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;140&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                   &lt;span class=&#39;s&#39;&gt;&#34;Mon&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;87&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;71&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#view the dataset&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;visitors_wide&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;         park Fri Sat Sun Mon&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 north_park  65 184 135  87&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 south_park  80 160 140  71&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;long-format&#34;&gt;Long Format&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#create the dataset&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;visitors_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;park&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/rep.html&#39;&gt;rep&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;north_park&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;south_park&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
                   &lt;span class=&#39;s&#39;&gt;&#34;day&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Fri&#34;&lt;/span&gt;,&lt;span class=&#39;s&#39;&gt;&#34;Fri&#34;&lt;/span&gt;,&lt;span class=&#39;s&#39;&gt;&#34;Sat&#34;&lt;/span&gt;,&lt;span class=&#39;s&#39;&gt;&#34;Sat&#34;&lt;/span&gt;,&lt;span class=&#39;s&#39;&gt;&#34;Sun&#34;&lt;/span&gt;,&lt;span class=&#39;s&#39;&gt;&#34;Sun&#34;&lt;/span&gt;,&lt;span class=&#39;s&#39;&gt;&#34;Mon&#34;&lt;/span&gt;,&lt;span class=&#39;s&#39;&gt;&#34;Mon&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                   &lt;span class=&#39;s&#39;&gt;&#34;visitors&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;65&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;80&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;184&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;160&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;135&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;140&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;87&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;71&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#view the dataset&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;visitors_long&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;         park day visitors&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 north_park Fri       65&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 south_park Fri       80&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3 north_park Sat      184&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4 south_park Sat      160&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5 north_park Sun      135&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6 south_park Sun      140&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 7 north_park Mon       87&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 8 south_park Mon       71&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice that both datasets store the same information - it&amp;rsquo;s just formatted differently. These two datasets can be said to have different shapes. The first has a wider shape - it has more columns, stretching it out from left to right. The second has a longer shape, as it has fewer columns and more rows. Again, importantly, &lt;strong&gt;both datasets store the same information&lt;/strong&gt;.&lt;/p&gt;
&lt;h2 id=&#34;what-shape-should-your-data-be-in&#34;&gt;What Shape Should Your Data Be In?&lt;/h2&gt;
&lt;p&gt;The best answer to the question of what shape your data &lt;em&gt;should&lt;/em&gt; be in is probably something like &amp;lsquo;Whatever shape makes it easiest to accomplish your goals with the data at any given time&amp;rsquo;. For example, sometimes when you&amp;rsquo;re entering data - say in to a spreadsheet in Excel or a similar program, you might find the data entry process easier if the dataset is in a wider format. In contrast, longer formats will generally be better when analyzing your data. This is consistent with the idea of &lt;em&gt;tidy&lt;/em&gt; data we talked about in &lt;a href=&#34;https://biodash.github.io/codeclub/02_dplyr-core-verbs/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Session 2&lt;/a&gt;. For example, &lt;em&gt;tidy&lt;/em&gt; data will be long because a characteristic of &lt;em&gt;tidy&lt;/em&gt; data is that each variable has its own column. For these reasons, you might find it helpful or even necessary to reshape the data - possibly multiple times as you continue to work with the same dataset.&lt;/p&gt;
&lt;h2 id=&#34;how-to-reshape-data&#34;&gt;How To Reshape Data&lt;/h2&gt;
&lt;p&gt;R offers several approaches for reshaping data. Functions for doing so often come in pairs that transform from wider to longer, and longer to wider, respectively. Pairs of functions include &lt;code&gt;cast()&lt;/code&gt; and &lt;code&gt;melt()&lt;/code&gt;, &lt;code&gt;spread()&lt;/code&gt; and &lt;code&gt;gather()&lt;/code&gt;, and &lt;code&gt;pivot_longer()&lt;/code&gt; and &lt;code&gt;pivot_wider()&lt;/code&gt;. While any of these can be used, we&amp;rsquo;ll focus on the &amp;lsquo;pivot&amp;rsquo; pair that come from the package &lt;em&gt;tidyr&lt;/em&gt;, as they were written most recently with a goal of being the most user-friendly of the available functions so far.&lt;/p&gt;
&lt;h2 id=&#34;pivoting-resources&#34;&gt;Pivoting Resources&lt;/h2&gt;
&lt;p&gt;If you want to dig in to pivoting a bit more, R offers a very useful &lt;a href=&#34;https://tidyr.tidyverse.org/articles/pivot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;vignette on pivoting&lt;/a&gt;, which is worth a look - portions of today&amp;rsquo;s breakout sessions will come from there. &lt;a href=&#34;https://r4ds.had.co.nz/tidy-data.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Chapter 12 of &amp;ldquo;R For Data Science&amp;rdquo;&lt;/a&gt; by Wickham and Grolemund, which covers tidy data, also includes a nice section on pivoting.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;Let&amp;rsquo;s revisit the park visitors dataset for an example of how &lt;code&gt;pivot_longer()&lt;/code&gt; and &lt;code&gt;pivot_wider()&lt;/code&gt; work in their most basic form. Previously, I created each of the wide and long forms of this dataset by hand. It was manageable to do that, since it&amp;rsquo;s a very small dataset, but for most datasets, you&amp;rsquo;re not going to want to just recreate a data frame from scratch each time you need to reshape the data. Let&amp;rsquo;s start with the data in wide format&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#view the data frame&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;visitors_wide&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;         park Fri Sat Sun Mon&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 north_park  65 184 135  87&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 south_park  80 160 140  71&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What if we wanted to plot the total mean number of visitors per day across both parks? To get the mean values, we might think about applying some of the functions we&amp;rsquo;ve been working with in previous sessions like &lt;code&gt;group_by()&lt;/code&gt; and &lt;code&gt;summarize()&lt;/code&gt;. For example, we might want to try grouping by &lt;em&gt;day&lt;/em&gt; and then calculating the means from a column that stores the number of &lt;em&gt;visitors&lt;/em&gt;. However, in it&amp;rsquo;s current wide form, this dataset doesn&amp;rsquo;t have the &lt;em&gt;day&lt;/em&gt; and &lt;em&gt;visitors&lt;/em&gt; columns we need. &lt;code&gt;pivot_longer()&lt;/code&gt; can help us here. The command might look like this&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;visitors_longer&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;visitors_wide&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                   &lt;span class=&#39;nf&#39;&gt;pivot_longer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;park&lt;/span&gt;, 
                                names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;day&#34;&lt;/span&gt;,
                                values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;visitors&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;First, we need to point it to the dataset we&amp;rsquo;re interested in reshaping - I&amp;rsquo;m doing that by piping the &lt;code&gt;visitors_wide&lt;/code&gt; data frame to &lt;code&gt;pivot_longer()&lt;/code&gt;. Next, we need to specify what columns to use to lengthen the dataset. This argument recognizes &lt;em&gt;tidy-select&lt;/em&gt; notation, which can really simplify things. Here, I&amp;rsquo;m using &lt;code&gt;-park&lt;/code&gt;, which tells it to use all the column names except &lt;em&gt;park&lt;/em&gt;. Those column names will be transformed to values in a single new column, which needs a name. We&amp;rsquo;ll call it &lt;em&gt;day&lt;/em&gt;, so &lt;code&gt;names_to = &amp;quot;day&amp;quot;&lt;/code&gt;. Finally, the values in the current columns will be stacked in to a single column, and it too needs a name, so &lt;code&gt;values_to = &amp;quot;visitors&amp;quot;&lt;/code&gt;. This lengthens the dataset, taking it from 5 columns down to 3.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#view the data&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;visitors_longer&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 8 x 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   park       day   visitors&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;      &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; north_park Fri         65&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; north_park Sat        184&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; north_park Sun        135&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; north_park Mon         87&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; south_park Fri         80&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; south_park Sat        160&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;7&lt;/span&gt;&lt;span&gt; south_park Sun        140&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;8&lt;/span&gt;&lt;span&gt; south_park Mon         71&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;In this longer format, we&amp;rsquo;re able to apply the &lt;code&gt;group_by()&lt;/code&gt; and &lt;code&gt;summarize()&lt;/code&gt; functions&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;visitors_longer&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
    &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;day&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
    &lt;span class=&#39;nf&#39;&gt;summarise&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;mean&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;visitors&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 4 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   day    mean&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Fri    72.5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Mon    79  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Sat   172  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Sun   138.&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And we can go in the opposite direction with &lt;code&gt;pivot_wider()&lt;/code&gt;&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;visitors_longer&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;pivot_wider&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;names_from &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;day&lt;/span&gt;, 
              values_from &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;visitors&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 2 x 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   park         Fri   Sat   Sun   Mon&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;      &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; north_park    65   184   135    87&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; south_park    80   160   140    71&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The examples above represent the most basic uses of &lt;code&gt;pivot_longer()&lt;/code&gt; and &lt;code&gt;pivot_wider()&lt;/code&gt;. But each of these functions offer additional arguments that can help deal with more complicated situations. The next example is from the &lt;a href=&#34;https://tidyr.tidyverse.org/articles/pivot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;pivoting vignette&lt;/a&gt; I referenced above. It uses the billboard dataset that should already be available in your R session, and that stores weekly rankings of Billboard top 100 songs from the year 2000.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#preview billboard data&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;billboard&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 79&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   artist track date.entered   wk1   wk2   wk3   wk4   wk5   wk6   wk7   wk8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;date&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; 2 Pac  Baby… 2000-02-26      87    82    72    77    87    94    99    &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; 2Ge+h… The … 2000-09-02      91    87    92    &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; 3 Doo… Kryp… 2000-04-08      81    70    68    67    66    57    54    53&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; 3 Doo… Loser 2000-10-21      76    76    72    69    67    65    55    59&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; 504 B… Wobb… 2000-04-15      57    34    25    17    17    31    36    49&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; 98^0   Give… 2000-08-19      51    39    34    26    26    19     2     2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 68 more variables: wk9 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk10 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk11 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk12 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk13 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk14 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk15 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk16 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk17 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk18 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk19 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk20 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk21 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk22 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk23 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk24 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk25 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk26 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk27 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk28 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk29 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk30 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk31 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk32 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk33 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk34 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk35 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk36 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk37 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk38 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk39 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk40 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk41 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk42 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk43 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk44 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk45 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk46 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk47 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk48 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk49 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk50 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk51 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk52 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk53 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk54 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk55 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk56 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk57 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk58 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk59 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk60 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk61 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk62 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk63 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk64 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk65 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk66 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;lgl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk67 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;lgl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk68 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;lgl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk69 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;lgl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk70 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;lgl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk71 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;lgl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk72 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;lgl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   wk73 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;lgl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk74 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;lgl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk75 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;lgl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, wk76 &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;lgl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice there are columns named &amp;lsquo;wk1&amp;rsquo; through &amp;lsquo;wk73&amp;rsquo; that store the weekly ranking for each song. Week itself is a variable with values that could be represented in a single column. We could do something similar to our above use of &lt;code&gt;pivot_longer()&lt;/code&gt;&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;billboard&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;pivot_longer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;starts_with&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;wk&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
               names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;week&#34;&lt;/span&gt;,
               values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;rank&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   artist track                   date.entered week   rank&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;date&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk1      87&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk2      82&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk3      72&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk4      77&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk5      87&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   wk6      94&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This is a start - we&amp;rsquo;ve gone from 79 columns to just 6. But we can clean this up a bit more. Notice the values in the new &lt;em&gt;week&lt;/em&gt; column all include the &amp;lsquo;wk&amp;rsquo; prefix. Since we&amp;rsquo;ve labeled the column &amp;lsquo;week&amp;rsquo;, it&amp;rsquo;s kind of redundant and unnecessary to have &amp;lsquo;wk&amp;rsquo; at the beginning of each value. We can add the &amp;lsquo;names_prefix&amp;rsquo; argument, which accepts a regular expression (regex). Characters at the beginning of column names that match the regex get removed.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;billboard&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;pivot_longer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;starts_with&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;wk&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
              names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;week&#34;&lt;/span&gt;,
              values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;rank&#34;&lt;/span&gt;,
              names_prefix &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;wk&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   artist track                   date.entered week   rank&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;date&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   1        87&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   2        82&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   3        72&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   4        77&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   5        87&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; 2 Pac  Baby Don&#39;t Cry (Keep... 2000-02-26   6        94&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We haven&amp;rsquo;t dealt with regular expressions in Code Club yet - they&amp;rsquo;ll make a good topic for a future session, but if you&amp;rsquo;re interested in the meantime, I did a couple short videos introducing them as part of &lt;a href=&#34;https://youtube.com/playlist?list=PLxhIMi78eQeh-1fdS8ta7A29jCIHeZe9Q&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this set of videos on command line computing&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout Rooms&lt;/h2&gt;
&lt;p&gt;In the breakout rooms, we&amp;rsquo;ll use a pivot function to analyze a portion of the NHANES dataset. We&amp;rsquo;ll use the data to try to address whether successive blood pressure measurements from the same individual differ in a predictable way.&lt;/p&gt;
&lt;p&gt;If you haven&amp;rsquo;t already done it, you can install the NHANES dataset with&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;NHANES&#34;&lt;/span&gt;, repos &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;http://cran.us.r-project.org&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; The downloaded binary packages are in&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   /var/folders/s7/y_mgh3c54h9fjcyw9wqdkb8x4zs_jy/T//RtmpWxvWIv/downloaded_packages&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;First let&amp;rsquo;s load and preview the NHANES dataset.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;a href=&#34;https://rdrr.io/r/base/library.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library()&lt;/code&gt;&lt;/a&gt; to load the dataset. The functions &lt;a href=&#34;https://rdrr.io/r/utils/head.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;head()&lt;/code&gt;&lt;/a&gt; are &lt;code&gt;glimpse()&lt;/code&gt; are a couple good options for previewing the data. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 10,000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 76&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ ID               &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 51624, 51624, 51624, 51625, 51630, 51638, 51646, 516…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SurveyYr         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; 2009_10, 2009_10, 2009_10, 2009_10, 2009_10, 2009_10…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Gender           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; male, male, male, male, female, male, male, female, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Age              &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 34, 34, 34, 4, 49, 9, 8, 45, 45, 45, 66, 58, 54, 10,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AgeDecade        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  30-39,  30-39,  30-39,  0-9,  40-49,  0-9,  0-9,  4…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AgeMonths        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 409, 409, 409, 49, 596, 115, 101, 541, 541, 541, 795…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Race1            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; White, White, White, Other, White, White, White, Whi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Race3            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Education        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; High School, High School, High School, NA, Some Coll…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ MaritalStatus    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Married, Married, Married, NA, LivePartner, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HHIncome         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; 25000-34999, 25000-34999, 25000-34999, 20000-24999, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HHIncomeMid      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 30000, 30000, 30000, 22500, 40000, 87500, 60000, 875…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Poverty          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 1.36, 1.36, 1.36, 1.07, 1.91, 1.84, 2.33, 5.00, 5.00…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HomeRooms        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 6, 6, 6, 9, 5, 6, 7, 6, 6, 6, 5, 10, 6, 10, 10, 4, 3…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HomeOwn          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Own, Own, Own, Own, Rent, Rent, Own, Own, Own, Own, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Work             &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NotWorking, NotWorking, NotWorking, NA, NotWorking, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Weight           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 87.4, 87.4, 87.4, 17.0, 86.7, 29.8, 35.2, 75.7, 75.7…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Length           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HeadCirc         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Height           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 164.7, 164.7, 164.7, 105.4, 168.4, 133.1, 130.6, 166…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BMI              &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 32.22, 32.22, 32.22, 15.30, 30.57, 16.82, 20.64, 27.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BMICatUnder20yrs &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BMI_WHO          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; 30.0_plus, 30.0_plus, 30.0_plus, 12.0_18.5, 30.0_plu…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Pulse            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 70, 70, 70, NA, 86, 82, 72, 62, 62, 62, 60, 62, 76, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPSysAve         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 113, 113, 113, NA, 112, 86, 107, 118, 118, 118, 111,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPDiaAve         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 85, 85, 85, NA, 75, 47, 37, 64, 64, 64, 63, 74, 85, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPSys1           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 114, 114, 114, NA, 118, 84, 114, 106, 106, 106, 124,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPDia1           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 88, 88, 88, NA, 82, 50, 46, 62, 62, 62, 64, 76, 86, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPSys2           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 114, 114, 114, NA, 108, 84, 108, 118, 118, 118, 108,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPDia2           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 88, 88, 88, NA, 74, 50, 36, 68, 68, 68, 62, 72, 88, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPSys3           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 112, 112, 112, NA, 116, 88, 106, 118, 118, 118, 114,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPDia3           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 82, 82, 82, NA, 76, 44, 38, 60, 60, 60, 64, 76, 82, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Testosterone     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ DirectChol       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 1.29, 1.29, 1.29, NA, 1.16, 1.34, 1.55, 2.12, 2.12, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ TotChol          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 3.49, 3.49, 3.49, NA, 6.70, 4.86, 4.09, 5.82, 5.82, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ UrineVol1        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 352, 352, 352, NA, 77, 123, 238, 106, 106, 106, 113,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ UrineFlow1       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 0.094, 1.538, 1.322, 1.116, 1.116, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ UrineVol2        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ UrineFlow2       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Diabetes         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, No, No, No, No, No, No, No, No, No, No, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ DiabetesAge      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HealthGen        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Good, Good, Good, NA, Good, NA, NA, Vgood, Vgood, Vg…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ DaysPhysHlthBad  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 0, 0, 0, NA, 0, NA, NA, 0, 0, 0, 10, 0, 4, NA, NA, 0…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ DaysMentHlthBad  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 15, 15, 15, NA, 10, NA, NA, 3, 3, 3, 0, 0, 0, NA, NA…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ LittleInterest   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Most, Most, Most, NA, Several, NA, NA, None, None, N…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Depressed        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Several, Several, Several, NA, Several, NA, NA, None…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ nPregnancies     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 2, NA, NA, 1, 1, 1, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ nBabies          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 2, NA, NA, NA, NA, NA, NA, NA, NA, N…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Age1stBaby       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 27, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SleepHrsNight    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 4, 4, 4, NA, 8, NA, NA, 8, 8, 8, 7, 5, 4, NA, 5, 7, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SleepTrouble     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, No, No, No, No, No, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ PhysActive       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, NA, No, NA, NA, Yes, Yes, Yes, Yes, Yes,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ PhysActiveDays   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, 5, 5, 5, 7, 5, 1, NA, 2,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ TVHrsDay         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ CompHrsDay       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ TVHrsDayChild    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, 4, NA, 5, 1, NA, NA, NA, NA, NA, NA, 4, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ CompHrsDayChild  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, 1, NA, 0, 6, NA, NA, NA, NA, NA, NA, 3, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Alcohol12PlusYr  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, Yes, Yes, Yes, Yes, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AlcoholDay       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 2, NA, NA, 3, 3, 3, 1, 2, 6, NA, NA,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AlcoholYear      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 0, 0, 0, NA, 20, NA, NA, 52, 52, 52, 100, 104, 364, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SmokeNow         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, NA, Yes, NA, NA, NA, NA, NA, No, NA, NA,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Smoke100         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, No, No, No, Yes, No,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Smoke100n        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Smoker, Smoker, Smoker, NA, Smoker, NA, NA, Non-Smok…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SmokeAge         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 18, 18, 18, NA, 38, NA, NA, NA, NA, NA, 13, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Marijuana        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, Yes, Yes, Yes, NA, Y…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AgeFirstMarij    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 17, 17, 17, NA, 18, NA, NA, 13, 13, 13, NA, 19, 15, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ RegularMarij     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, NA, No, NA, NA, No, No, No, NA, Yes, Yes…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AgeRegMarij      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 20, 15, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HardDrugs        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, No, No, No, No, Yes,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexEver          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, Yes, Yes, Yes, Yes, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexAge           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 16, 16, 16, NA, 12, NA, NA, 13, 13, 13, 17, 22, 12, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexNumPartnLife  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 8, 8, 8, NA, 10, NA, NA, 20, 20, 20, 15, 7, 100, NA,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexNumPartYear   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 1, 1, 1, NA, 1, NA, NA, 0, 0, 0, NA, 1, 1, NA, NA, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SameSex          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, NA, Yes, NA, NA, Yes, Yes, Yes, No, No, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexOrientation   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Heterosexual, Heterosexual, Heterosexual, NA, Hetero…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ PregnantNow      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;As you might know, blood pressure consists of two values - systolic and diastolic. Each participant in the NHANES survey had their blood pressure measured three times in succession, giving us the columns: &lt;em&gt;BPSys1&lt;/em&gt;, &lt;em&gt;BPDia1&lt;/em&gt;, &lt;em&gt;BPSys2&lt;/em&gt;, &lt;em&gt;BPDia2&lt;/em&gt;, &lt;em&gt;BPSys3&lt;/em&gt;, &lt;em&gt;BPDia3&lt;/em&gt;. Let&amp;rsquo;s work first with just the three systolic values.&lt;/p&gt;
&lt;p&gt;Subset the dataset to get just the columns &lt;em&gt;BPSys1&lt;/em&gt;, &lt;em&gt;BPSys2&lt;/em&gt;, and &lt;em&gt;BPSys3&lt;/em&gt;. Name the new object &amp;lsquo;sys_values&amp;rsquo;, then get the dimensions of &lt;em&gt;sys_values&lt;/em&gt; and preview it.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;code&gt;select()&lt;/code&gt; from &lt;em&gt;dplyr&lt;/em&gt; to get the three columns we want. &lt;a href=&#34;https://rdrr.io/r/base/dim.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dim()&lt;/code&gt;&lt;/a&gt; and &lt;code&gt;glimpse()&lt;/code&gt; can be used to get the dimensions and preview the data, respectively. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;sys_values&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
    &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;matches&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;BPSys[123]$&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#I used the &#39;matches&#39; helper along with a regular expression &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#above, but there are a number of ways you could do this. &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#One equivalent would be...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# sys_values &amp;lt;- NHANES %&amp;gt;% select(BPSys1, BPSys2, BPSys3)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sys_values&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 10000     3&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sys_values&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   BPSys1 BPSys2 BPSys3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt;    114    114    112&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt;    114    114    112&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt;    114    114    112&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt;    118    108    116&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt;     84     84     88&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;We can see just from the preview in Exercise 2 that the dataset has some missing data - let&amp;rsquo;s remove rows that have NA&amp;rsquo;s. Call the new dataset &amp;lsquo;sys_noNA&amp;rsquo;. Then check the dimensions and preview again.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Try the &lt;code&gt;drop_na&lt;/code&gt; function from &lt;em&gt;tidyr&lt;/em&gt; to eliminate rows containing missing data. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;sys_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sys_values&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sys_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 7971    3&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sys_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   BPSys1 BPSys2 BPSys3&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt;    114    114    112&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt;    114    114    112&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt;    114    114    112&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt;    118    108    116&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt;     84     84     88&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt;    114    108    106&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;We&amp;rsquo;ll explore these data a bit to see if there&amp;rsquo;s any evidence of a trend in systolic blood pressure with respect to the sequence of measurements (differences among measurements 1, 2, and 3). First, lets reshape the data so we end up with just two columns named &amp;lsquo;measurement&amp;rsquo; and &amp;lsquo;sys_bp&amp;rsquo;. Save the new objects as &amp;lsquo;sys_long&amp;rsquo;. Then check the dimensions and preview again.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;code&gt;pivot_longer()&lt;/code&gt; to lengthen the dataset. You&amp;rsquo;ll need to include the arguments &amp;ldquo;cols&amp;rdquo;, &amp;ldquo;names_to&amp;rdquo;, and &amp;ldquo;values_to&amp;rdquo;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;sys_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sys_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;pivot_longer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;starts_with&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;BP&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
               names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;measurement&#34;&lt;/span&gt;,
               values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;sys_bp&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sys_long&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 23913     2&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sys_long&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   measurement sys_bp&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;        &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; BPSys1         114&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; BPSys2         114&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; BPSys3         112&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; BPSys1         114&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; BPSys2         114&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; BPSys3         112&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-5&#34;&gt;Exercise 5&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now let&amp;rsquo;s calculate and compare the mean values for each measurement.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use &lt;code&gt;group_by()&lt;/code&gt; and &lt;code&gt;summarize()&lt;/code&gt; to get a mean for each of the three measurements. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;sys_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;measurement&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;mean_sys&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sys_bp&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   measurement mean_sys&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; BPSys1          119.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; BPSys2          118.&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; BPSys3          118.&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-6&#34;&gt;Exercise 6&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;The &lt;code&gt;summarise()&lt;/code&gt; functions outputs a tibble. Tibbles are intended to be tidy, and as part of that, by default the values they display tend to be truncated/rounded to a greater degree than they would be otherwise in R. In this case, we might want to see a bit more precision in the values. Try adjusting (increasing) the number of significant figures that are displayed in the tibble that was output in Exercise 5.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; This can be done in a couple different ways. One is to convert the tibble to a data frame with &lt;a href=&#34;https://rdrr.io/r/base/as.data.frame.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;as.data.frame()&lt;/code&gt;&lt;/a&gt;, since data frames, by default, will likely show more significant digits. Alternatively, try setting options(pillar.sigfig) to a new value. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;sys_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;measurement&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;mean_sys&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sys_bp&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/as.data.frame.html&#39;&gt;as.data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   measurement mean_sys&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1      BPSys1 119.1682&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2      BPSys2 118.4333&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3      BPSys3 117.8479&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#OR&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/options.html&#39;&gt;options&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;pillar.sigfig &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;6&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;sys_long&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;measurement&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;mean_sys&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sys_bp&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   measurement mean_sys&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; BPSys1       119.168&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; BPSys2       118.433&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; BPSys3       117.848&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;br&gt;
&lt;h3 id=&#34;bonus-1&#34;&gt;Bonus 1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Are those differences statistically significant? A one-way anova might be a good option to test that. Check out the help page for the function &lt;a href=&#34;https://rdrr.io/r/stats/aov.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;aov()&lt;/code&gt;&lt;/a&gt; and try running an ANOVA.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hint 1 (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; R often uses the tilde (~) to indicate formula notation. So, for example, you can generate a scatterplot in base R by plotting y~x, assuming y and x are numeric vectors of equal lengths. The &lt;a href=&#34;https://rdrr.io/r/stats/aov.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;aov()&lt;/code&gt;&lt;/a&gt; function requires a formula with the pattern values~group. You can use the column names in the data frame to define these, but then you need to use the &amp;lsquo;data&amp;rsquo; argument to tell the function the name of the data frame where those columns exist. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Hint 2 (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Once you get the &lt;a href=&#34;https://rdrr.io/r/stats/aov.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;aov()&lt;/code&gt;&lt;/a&gt; function to work, you can get a p-value with the &lt;code&gt;summary&lt;/code&gt; function. See info under the &amp;ldquo;Value&amp;rdquo; heading on the help page for &lt;a href=&#34;https://rdrr.io/r/stats/aov.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;aov()&lt;/code&gt;&lt;/a&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/aov.html&#39;&gt;aov&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;sys_bp&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;~&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;measurement&lt;/span&gt;, data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sys_long&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/summary.html&#39;&gt;summary&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;                Df  Sum Sq Mean Sq F value   Pr(&amp;gt;F)    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; measurement     2    6977    3489   11.87 7.05e-06 ***&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Residuals   23910 7028228     294                     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ---&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Signif. codes:  0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-2&#34;&gt;Bonus 2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Repeat all of the above for diastolic blood pressure with a couple of modifications along the way. First, when you reshape/lengthen the data, make the values in the &amp;lsquo;measurement&amp;rsquo; column numeric. For example, in the &lt;em&gt;sys_long&lt;/em&gt; data frame we created above, the values in the measurement column were characters, and looked like &amp;ldquo;BPsys1&amp;rdquo;. This time, make them a factor with the levels &amp;ldquo;1&amp;rdquo;, &amp;ldquo;2&amp;rdquo;, and &amp;ldquo;3&amp;rdquo;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hint (click here)
&lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Use the &lt;code&gt;pivot_longer()&lt;/code&gt; arguments &amp;ldquo;names_prefix&amp;rdquo; and &amp;ldquo;names_transform&amp;rdquo;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;dia_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;matches&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;BPDia[123]$&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;pivot_longer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cols &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;starts_with&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;BP&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
               names_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;measurement&#34;&lt;/span&gt;,
               values_to &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;dia_bp&#34;&lt;/span&gt;,
               names_prefix &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;BPDia&#34;&lt;/span&gt;,
               names_transform &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.html&#39;&gt;list&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;measurement &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;as.factor&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dia_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   measurement dia_bp&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;        &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; 1               88&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; 2               88&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; 3               82&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; 1               88&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; 2               88&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; 3               82&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;dia_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;measurement&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;mean_dia&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dia_bp&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/as.data.frame.html&#39;&gt;as.data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   measurement mean_dia&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1           1 68.28830&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2           2 67.46280&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3           3 67.06762&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/aov.html&#39;&gt;aov&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dia_bp&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;~&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;measurement&lt;/span&gt;, data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;dia_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/summary.html&#39;&gt;summary&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;                Df  Sum Sq Mean Sq F value   Pr(&amp;gt;F)    &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; measurement     2    6185  3092.3   14.91 3.38e-07 ***&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Residuals   23910 4958916   207.4                     &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; ---&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Signif. codes:  0 &#39;***&#39; 0.001 &#39;**&#39; 0.01 &#39;*&#39; 0.05 &#39;.&#39; 0.1 &#39; &#39; 1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Session 7: R Markdown</title>
      <link>https://biodash.github.io/codeclub/07_rmarkdown/</link>
      <pubDate>Sun, 24 Jan 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/07_rmarkdown/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;p&gt;R Markdown consists of an amazing ecosystem of R packages to produce many types of technical content. Its signature capability is that is can &lt;strong&gt;run R code and print the code along with its results and nicely formatted prose.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;To understand R Markdown, we need to learn about three new things:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Markdown&lt;/strong&gt;, a very lightweight text formatting language.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Code chunks&lt;/strong&gt;, which allow us to incorporate R code that can be executed and whose results we can display in text, figures, and tables.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The YAML header&lt;/strong&gt;, which encodes metadata about the output, such as the desired output format and specific formatting features.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;We&amp;rsquo;ll focus on HTML page output, but will glimpse at the &lt;strong&gt;many possibilities for the output format&lt;/strong&gt;: with R Markdown, it is possible to create not just technical reports, but also slide decks, websites, books, scientific articles, and so on.&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;setup&#34;&gt;Setup&lt;/h4&gt;
&lt;p&gt;At the core of the R Markdown ecosystem is the &lt;em&gt;rmarkdown&lt;/em&gt; package. We need to install this but don&amp;rsquo;t need to load it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;rmarkdown&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Inside your directory for Code Club, create a directory for this week:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;S07&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h4 id=&#34;first-an-example&#34;&gt;First, an example&lt;/h4&gt;
&lt;p&gt;Before we go into details, let&amp;rsquo;s first see a quick demonstration of what we are talking about:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Go to &lt;code&gt;File&lt;/code&gt; =&amp;gt; &lt;code&gt;New File&lt;/code&gt; =&amp;gt; &lt;code&gt;R Markdown&lt;/code&gt;, change the &lt;em&gt;Title&lt;/em&gt; to &amp;ldquo;Markdown demo&amp;rdquo;, and click &lt;code&gt;OK&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Take a look at the R Markdown document, and notice that there seems to be some sort of header (=&amp;gt; &lt;em&gt;&lt;strong&gt;YAML&lt;/strong&gt;&lt;/em&gt;), followed by R code wrapped in strange constructs with backticks (=&amp;gt; &lt;em&gt;&lt;strong&gt;Code chunks&lt;/strong&gt;&lt;/em&gt;), and plain written text (=&amp;gt; &lt;em&gt;&lt;strong&gt;Markdown&lt;/strong&gt;&lt;/em&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Before we can create output, we need to save the document. Click the &lt;code&gt;Save&lt;/code&gt; button and save the files as &lt;code&gt;demo.Rmd&lt;/code&gt; inside your newly created directory.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Now click the &lt;strong&gt;Knit button&lt;/strong&gt; in one of the top bars, and a document should show up in a pop-up or the Viewer pane. This is the &lt;em&gt;rendered output&lt;/em&gt; from the R Markdown document.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Notice that the YAML header is not printed, at least not verbatim, while some of the code is printed, and we also see code output including a plot!&lt;/p&gt;
&lt;p&gt;This is what the raw and rendered output look side-by-side:&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/rmd-demo-both.png width=&#34;1000px&#34;&gt;
&lt;/p&gt;
&lt;p&gt;We&amp;rsquo;ll now talk about Markdown, code chunks, and the YAML header in turn.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;i-markdown&#34;&gt;I: Markdown&lt;/h2&gt;
&lt;p&gt;Markdown is a very lightweight language to format plain text files, which evolved from simple in-line formatting applied in emails before those started using HTML.&lt;/p&gt;
&lt;p&gt;Need to emphasize a word without being able to make it italic or bold? How about adding emphasis with asterisks *like so*?&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;an-overview-of-commonly-used-markdown-syntax&#34;&gt;An overview of commonly used Markdown syntax&lt;/h4&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Syntax&lt;/th&gt;
&lt;th&gt;Result&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;# My Title&lt;/td&gt;
&lt;td&gt;Header level 1 (largest)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;## My Section&lt;/td&gt;
&lt;td&gt;Header level 2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;### My Subsection&lt;/td&gt;
&lt;td&gt;Header level 3 &amp;ndash; and so forth&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;*italic* or _italic_&lt;/td&gt;
&lt;td&gt;&lt;em&gt;italic&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;**bold** or __bold__&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;bold&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;[Markdown Guide](markdownguide.org)&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://markdownguide.org&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Markdown Guide&lt;/a&gt; (Link with custom text)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;![](path/to/figure.png)&lt;/td&gt;
&lt;td&gt;Figure&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;- List item&lt;/td&gt;
&lt;td&gt;Unordered (bulleted) list&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;1. List item&lt;/td&gt;
&lt;td&gt;Ordered (numbered) list&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;`inline code`&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;inline code&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;```&lt;/code&gt; &lt;br&gt; &amp;hellip;code&amp;hellip; &lt;br&gt; &lt;code&gt;```&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Generic code block (for formatting only) &lt;br&gt; (&lt;em&gt;Alternative syntax: 4 leading spaces.&lt;/em&gt;)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;```r&lt;/code&gt; &lt;br&gt; &amp;hellip;code&amp;hellip; &lt;br&gt; &lt;code&gt;```&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;r&lt;/code&gt; code block (for formatting only)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;---&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;Horizontal rule (line)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;To see this formatting in action, see below an example of a raw Markdown file on the left, and its &lt;em&gt;rendered&lt;/em&gt; (formatted) output on the right:&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/md-demo.png width=&#34;2000px&#34;&gt;
&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;&amp;ldquo;Plain&amp;rdquo; Markdown files have the extension &lt;code&gt;.md&lt;/code&gt;, whereas R Markdown files have the extension &lt;code&gt;.Rmd&lt;/code&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;ii-integrating-r-code&#34;&gt;II: Integrating R code&lt;/h2&gt;
&lt;p&gt;As we saw above, plain Markdown has syntax for code &lt;em&gt;formatting&lt;/em&gt;, but the code is not actually being executed. &lt;strong&gt;In R Markdown, however, we are able run code!&lt;/strong&gt; The syntax to do so is only slightly modified from what we saw above:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For &lt;strong&gt;inline code&lt;/strong&gt;, we add &lt;code&gt;r&lt;/code&gt; and a space before the R code that is to be executed, for example:&lt;/p&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Raw&lt;/th&gt;
&lt;th&gt;Rendered&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;There are &lt;code&gt;`r 365*24`&lt;/code&gt; hours in a year&lt;/td&gt;
&lt;td&gt;There are 8760 hours in a year&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To generate &lt;em&gt;code blocks&lt;/em&gt;, which we call &lt;strong&gt;code chunks&lt;/strong&gt; in an R Markdown context,&lt;br&gt;
we add r &lt;em&gt;inside curly braces&lt;/em&gt;: &lt;code&gt;```{r}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;We can optionally add settings that we want to apply to that chunk and/or chunk labels:&lt;br&gt;
&lt;code&gt;```{r, option1=value, ...}&lt;/code&gt; or &lt;code&gt;```{r, unique-chunk-label, option1=value, ...}&lt;/code&gt;&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;RStudio keyboard shortcut to insert a code chunk: &lt;kbd&gt;Cmd/Ctrl&lt;/kbd&gt;+&lt;kbd&gt;Alt&lt;/kbd&gt;+&lt;kbd&gt;I&lt;/kbd&gt;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;h4 id=&#34;code-chunk-examples&#34;&gt;Code chunk examples&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;A code chunk with &lt;strong&gt;default options&lt;/strong&gt;&amp;hellip;&lt;/p&gt;
&lt;p align=&#34;left&#34;&gt;
&lt;img src=img/example-chunk-1.png width=&#34;100%&#34;&gt;
&lt;/p&gt;
&lt;p&gt;&amp;hellip;will be executed and shown followed by the output of the code:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 17.15117&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;As an example of using a &lt;strong&gt;code chunk option&lt;/strong&gt;, we will disable printing the code using &lt;code&gt;echo=FALSE&lt;/code&gt; (the code will still run and the output will still be shown):&lt;/p&gt;
&lt;p align=&#34;left&#34;&gt;
&lt;img src=img/example-chunk-2.png width=&#34;100%&#34;&gt;
&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 17.15117&lt;/span&gt;
 &lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Figures&lt;/strong&gt; can, of course, also be printed:&lt;/p&gt;
&lt;p align=&#34;left&#34;&gt;
&lt;img src=img/example-chunk-3.png width=&#34;100%&#34;&gt;
&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_depth_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_bw&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 2 rows containing missing values (geom_point).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;figure&#34; style=&#34;text-align: center&#34;&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-6-1.png&#34; alt=&#34;Fig. 1: Bill length and depth are correlated within species, &amp;lt;br&amp;gt; and differ subtly between species.&#34; width=&#34;700px&#34; /&gt;&lt;/p&gt;
&lt;p class=&#34;caption&#34;&gt;
Fig. 1: Bill length and depth are correlated within species, &lt;br&gt; and differ subtly between species.
&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Above, we added a &lt;strong&gt;caption&lt;/strong&gt; for the figure using the &lt;code&gt;fig.cap&lt;/code&gt; argument (with a little trick to force a line break, using the &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt; HTML syntax).&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;code-chunk-options&#34;&gt;Code chunk options&lt;/h4&gt;
&lt;p&gt;Here is an overview of some the most commonly made &lt;em&gt;changes to defaults&lt;/em&gt; for code chunk options. This quickly gets confusing, but you&amp;rsquo;ll get the hang of it after experimenting a bit.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;echo=FALSE&lt;/code&gt; &amp;ndash; Don&amp;rsquo;t print the code in the output file.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;eval=FALSE&lt;/code&gt; &amp;ndash; Don&amp;rsquo;t run (&lt;strong&gt;eval&lt;/strong&gt;uate) the code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;include=FALSE&lt;/code&gt; &amp;ndash; Run but don&amp;rsquo;t print the code, nor any of its results.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;results=&amp;quot;hide&amp;quot;&lt;/code&gt; &amp;ndash; Don&amp;rsquo;t print the &lt;em&gt;text output&lt;/em&gt; of the code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fig.show=&amp;quot;hide&amp;quot;&lt;/code&gt; &amp;ndash; Don&amp;rsquo;t print &lt;em&gt;figures&lt;/em&gt; produced by the code.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Furthermore, you can use &lt;code&gt;message=FALSE&lt;/code&gt; and &lt;code&gt;warning=FALSE&lt;/code&gt; to suppress any &lt;em&gt;messages&lt;/em&gt; (like the output when loading packages) and &lt;em&gt;warnings&lt;/em&gt; (like the warning for the penguin figure above), respectively, that R might produce.&lt;/p&gt;
&lt;p&gt;For figures, the following options are especially useful:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;fig.cap=&amp;quot;My caption&amp;quot;&lt;/code&gt; &amp;ndash; Include a caption.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fig.asp=0.6&lt;/code&gt; &amp;ndash; Aspect ratio.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fig.width=6&lt;/code&gt; &amp;ndash; Width of in inches: same as sizing in regular R code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;fig.height=9.6&lt;/code&gt; &amp;ndash; Height in inches: same as sizing in regular R code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;out.width=&amp;quot;70%&amp;quot;&lt;/code&gt; &amp;ndash; Figure width as &lt;em&gt;printed in the document&lt;/em&gt; (in &lt;code&gt;%&lt;/code&gt; or pixels, &lt;code&gt;px&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;out.height=&amp;quot;500px&amp;quot;&lt;/code&gt; &amp;ndash; Figure height as &lt;em&gt;printed in the document&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Finally, if your document takes a long time to knit, use &lt;code&gt;cache=TRUE&lt;/code&gt; to enable caching of results.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;default-chunk-options&#34;&gt;Default chunk options&lt;/h4&gt;
&lt;p&gt;It is often practical to set default chunk options for the entire document, and you can do so with the &lt;code&gt;opts_chunk$set()&lt;/code&gt; function as shown below:&lt;/p&gt;
&lt;p align=&#34;left&#34;&gt;
&lt;img src=img/global-chunk.png width=&#34;100%&#34;&gt;
&lt;/p&gt;
&lt;p&gt;This is usually done in separate &lt;em&gt;&amp;ldquo;global setup chunk&amp;rdquo;&lt;/em&gt; at the start of the document.&lt;br&gt;
Whenever necessary, you can then override these defaults for specific chunks.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;iii-the-yaml-header&#34;&gt;III: The YAML header&lt;/h2&gt;
&lt;p&gt;YAML (&lt;em&gt;&amp;ldquo;YAML Ain&amp;rsquo;t Markup Language&amp;rdquo;&lt;/em&gt;) is a simple format commonly used for &lt;em&gt;configuration files&lt;/em&gt;, which allows you to provide key-value pairs such as &lt;code&gt;author: John Doe&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In R Markdown files, it is used as a &lt;strong&gt;header&lt;/strong&gt; which configures certain aspects of the output, especially the formatting. Put another way, the YAML header &lt;em&gt;contains the metadata&lt;/em&gt; for the output.&lt;/p&gt;
&lt;h4 id=&#34;a-basic-yaml-header&#34;&gt;A basic YAML header&lt;/h4&gt;
&lt;p&gt;Here is an example of a very basic YAML header:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;---
author: My name
title: The document&#39;s title
output: html_document
---
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note the lines which just contain &lt;strong&gt;three dashes&lt;/strong&gt;, which mark the beginning and the end of the YAML header.&lt;/p&gt;
&lt;h4 id=&#34;adding-options&#34;&gt;Adding options&lt;/h4&gt;
&lt;p&gt;Often, a value (like &lt;code&gt;html_document&lt;/code&gt;) can itself be given key-value pairs to specify additional options &amp;ndash; see the example below where we include a Table of Contents (&lt;code&gt;toc&lt;/code&gt;) and also set it to &amp;ldquo;float&amp;rdquo;:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;---
output:
  html_document:
    toc: true
    toc_float: true
---
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Note the syntax changes (newlines and added indentation) between the above two examples, this is perhaps a little awkward and often leads to mistakes.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Indentation in YAML is using two or four spaces (no tabs!) per indentation level, and it is &lt;em&gt;sensitive to indentation errors&lt;/em&gt;. (Fortunately, RStudio inserts spaces for tabs by default &amp;ndash; check/set in &lt;code&gt;Tools&lt;/code&gt; =&amp;gt; &lt;code&gt;Global Options&lt;/code&gt; =&amp;gt; &lt;code&gt;Code&lt;/code&gt; =&amp;gt; &lt;code&gt;Editing&lt;/code&gt;.)&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;some-options-for-html_document-output&#34;&gt;Some options for &lt;code&gt;html_document&lt;/code&gt; output&lt;/h4&gt;
&lt;p&gt;&lt;code&gt;html_document&lt;/code&gt; is the most commonly used output format for R Markdown documents, and here are few particularly useful options to customize the output:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;code_download: true&lt;/code&gt; &amp;ndash; Include a button to download the code.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;code_folding: hide&lt;/code&gt; &amp;ndash; Using &lt;code&gt;hide&lt;/code&gt; or &lt;code&gt;show&lt;/code&gt; will enable the folding of code chunks, with &lt;code&gt;hide&lt;/code&gt; hiding them by default.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;toc: true&lt;/code&gt; &amp;ndash; Include a table of contents (Also: &lt;code&gt;toc_depth: 3&lt;/code&gt; sets depth to 3, &lt;code&gt;toc_float: true&lt;/code&gt; lets the TOC &amp;ldquo;float&amp;rdquo; as you scroll down the document).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;number_sections: true&lt;/code&gt; &amp;ndash; Number the section headings.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;df_print: paged&lt;/code&gt; &amp;ndash; Get nicely formatted and paged data frame printing (also try: &lt;code&gt;df_print: kable&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;&lt;code&gt;theme: cerulean&lt;/code&gt; &amp;ndash; Use a pre-built theme, controlling the overall look and feel of the document. See &lt;a href=&#34;https://www.datadreaming.org/post/r-markdown-theme-gallery/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt; for a visual overview.&lt;/li&gt;
&lt;/ul&gt;
&lt;figure&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/rmd-3themes.png width=&#34;100%&#34;&gt;
&lt;figcaption&gt;
Three HTML document &lt;code&gt;theme&lt;/code&gt; options: &lt;code&gt;darkly&lt;/code&gt;, &lt;code&gt;flatly&lt;/code&gt;, and &lt;code&gt;cerulean&lt;/code&gt;.
&lt;/figcaption&gt;
&lt;/p&gt;
&lt;/figure&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;iv-r-markdown-and-rstudio&#34;&gt;IV: R Markdown and RStudio&lt;/h2&gt;
&lt;p&gt;The RMarkdown ecosystem of packages is being developed by RStudio, so it should come as no surprise that the RStudio IDE has some nice RMarkdown functionality.&lt;/p&gt;
&lt;h4 id=&#34;knitting-and-previewing-your-document&#34;&gt;Knitting and previewing your document&lt;/h4&gt;
&lt;p&gt;The process of rendering an R Markdown file into another format, as specified by the YAML header, is called &lt;strong&gt;knitting&lt;/strong&gt;. We already saw the button to knit the current document (keyboard shortcut: &lt;kbd&gt;Cmd/Ctrl&lt;/kbd&gt;+&lt;kbd&gt;Shift&lt;/kbd&gt;+&lt;kbd&gt;K&lt;/kbd&gt;).&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;If you get preview pop-up windows in RStudio, click the cog wheel icon next to the Knit button, and then select &amp;ldquo;&lt;em&gt;Preview in Viewer Pane&lt;/em&gt;&amp;rdquo;.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;Instead of knitting the entire document, you can also &lt;strong&gt;run individual code chunks&lt;/strong&gt; using the green &amp;ldquo;play button&amp;rdquo; (or &lt;kbd&gt;Cmd/Ctrl&lt;/kbd&gt;+&lt;kbd&gt;Shift&lt;/kbd&gt;+&lt;kbd&gt;Enter&lt;/kbd&gt;), or all code chunks up until the current one (button to the left of the play button).&lt;/p&gt;
&lt;p&gt;For a &lt;strong&gt;live preview (!)&lt;/strong&gt; of R Markdown output for your active document,&lt;br&gt;
use the &lt;em&gt;infinite moon reader&lt;/em&gt; from the &lt;em&gt;xaringan&lt;/em&gt; package:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;xaringan&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Simply running the function without arguments will start the preview:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;xaringan&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/xaringan/man/inf_mr.html&#39;&gt;inf_mr&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# To shut down the preview server, if needed, run `servr::daemon_stop()`&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h4 id=&#34;visual-markdown-editor&#34;&gt;Visual Markdown Editor&lt;/h4&gt;
&lt;p&gt;If your RStudio version is at least 1.4 (Click &lt;code&gt;Help&lt;/code&gt; =&amp;gt; &lt;code&gt;About RStudio&lt;/code&gt;), which was released last fall, you can also use the &lt;em&gt;Visual Markdown Editor&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;This makes writing in R Markdown almost like using a word processor, and also includes many other features such as better citation support with Zotero integration. Read more about the visual editor &lt;a href=&#34;https://rstudio.github.io/visual-markdown-editing&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;To switch between the visual editor and regular (&amp;ldquo;source&amp;rdquo;) editing mode, click the A-shaped ruler button in the top-right corner or press &lt;kbd&gt;Cmd/Ctrl&lt;/kbd&gt;+&lt;kbd&gt;Shift&lt;/kbd&gt;+&lt;kbd&gt;F4&lt;/kbd&gt;.&lt;/p&gt;
&lt;p&gt;This is what our document looks like in the visual editor &amp;ndash; kind of intermediate between the raw R Markdown and the rendered output:&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/visual-editor.png width=&#34;70%&#34;&gt;
&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;v-a-single-source-doc-many-output-formats&#34;&gt;V: A single source doc, many output formats!&lt;/h2&gt;
&lt;p&gt;One of the greatest features of R Markdown is that you can output to many formats. So from one source document, or very similar variants, you can create completely different output depending on what you need.&lt;/p&gt;
&lt;h4 id=&#34;built-in-output-formats&#34;&gt;Built-in output formats&lt;/h4&gt;
&lt;p&gt;The &lt;a href=&#34;https://rmarkdown.rstudio.com/docs/reference/index.html#section-output-formats&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;built-in output formats&lt;/a&gt;, which can be used with just the &lt;em&gt;rmarkdown&lt;/em&gt; package, are listed below. These include HTML, PDF, Word, PowerPoint, and different HTML slide show formats!&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=img/rmarkdown-output-formats.png width=&#34;80%&#34;&gt;
&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;extension-output-formats&#34;&gt;Extension output formats&lt;/h4&gt;
&lt;p&gt;It&amp;rsquo;s worth highlighting a few of the output formats that can be used with the following packages in the R Markdown ecosystem:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://rstudio.github.io/distill/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;distill&lt;/em&gt;&lt;/a&gt; &amp;ndash; An output format geared towards technical content, e.g. with extended support for equations, citations, and footnotes. Can also create websites.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://github.com/rstudio/rticles&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;rticles&lt;/em&gt;&lt;/a&gt; &amp;ndash; R Markdown templates to format output for specific scientific journals.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://rmarkdown.rstudio.com/flexdashboard/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;flexdashboard&lt;/em&gt;&lt;/a&gt; &amp;ndash; Create interactive &amp;ldquo;dashboards&amp;rdquo; to present data.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://bookdown.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;bookdown&lt;/em&gt;&lt;/a&gt; &amp;ndash; A book format, the &lt;a href=&#34;https://bookdown.org/yihui/rmarkdown/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R Markdown book&lt;/a&gt; is an example.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://bookdown.org/yihui/rmarkdown/xaringan.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;xaringan&lt;/em&gt;&lt;/a&gt; &amp;ndash; Create fancier presentation slides thanks to a JavaScript library.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Starting to use these and other output formats is often as simple as changing the YAML header:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span class=&#34;nn&#34;&gt;---&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;output&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;l&#34;&gt;distill::distill_article&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;nn&#34;&gt;---&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout rooms!&lt;/h2&gt;
&lt;p&gt;In the exercises, we will work with an &lt;code&gt;.Rmd&lt;/code&gt; file that you can download as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# dir.create(&#34;S07&#34;)     # You should have already done this&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Save the URL for the Rmd file:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;todays_rmd&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/07_rmarkdown/penguins.Rmd&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Download the Rmd file:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;todays_rmd&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;S07/penguins.Rmd&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Next, open the document in RStudio, and fire up the &lt;em&gt;infinite moon reader&lt;/em&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;xaringan&#34;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;xaringan&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/xaringan/man/inf_mr.html&#39;&gt;inf_mr&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This way, you will be able to nearly instantaneously see the effect of your changes: save the document whenever you want the server to update.&lt;/p&gt;
&lt;p&gt;You can use either the &amp;ldquo;visual editor&amp;rdquo; or the regular (&amp;ldquo;source&amp;rdquo;) editor &amp;ndash; and you could also start by compating the two.&lt;/p&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-1-output-formatting-with-yaml&#34;&gt;Exercise 1: Output formatting with YAML&lt;/h3&gt;
&lt;p&gt;In this exercise, you will fiddle with the YAML header to modify aspects of the &lt;code&gt;html_document&lt;/code&gt; output format:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Add a &lt;code&gt;theme&lt;/code&gt; key to &lt;code&gt;html_output&lt;/code&gt;, and try a few of the available value options (&amp;quot;&lt;em&gt;default&lt;/em&gt;&amp;quot;, &amp;ldquo;&lt;em&gt;cerulean&lt;/em&gt;&amp;rdquo;, &amp;ldquo;&lt;em&gt;journal&lt;/em&gt;&amp;rdquo;, &amp;ldquo;&lt;em&gt;flatly&lt;/em&gt;&amp;rdquo;, &amp;ldquo;&lt;em&gt;darkly&lt;/em&gt;&amp;rdquo;, &amp;ldquo;&lt;em&gt;readable&lt;/em&gt;&amp;rdquo;, &amp;ldquo;&lt;em&gt;spacelab&lt;/em&gt;&amp;rdquo;, &amp;ldquo;&lt;em&gt;united&lt;/em&gt;&amp;rdquo;, &amp;ldquo;&lt;em&gt;cosmo&lt;/em&gt;&amp;rdquo;, &amp;ldquo;&lt;em&gt;lumen&lt;/em&gt;&amp;rdquo;, &amp;ldquo;&lt;em&gt;paper&lt;/em&gt;&amp;rdquo;, &amp;ldquo;&lt;em&gt;sandstone&lt;/em&gt;&amp;rdquo;, &amp;ldquo;&lt;em&gt;simplex&lt;/em&gt;&amp;rdquo;, &amp;ldquo;&lt;em&gt;yeti&lt;/em&gt;&amp;quot;).&lt;/p&gt;
&lt;p&gt;Determine, once and for all, what the best theme is.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Try some of the other options mentioned above (&lt;code&gt;code_download&lt;/code&gt;, &lt;code&gt;code_folding&lt;/code&gt;, &lt;code&gt;toc&lt;/code&gt;, &lt;code&gt;toc_float&lt;/code&gt;, &lt;code&gt;toc_depth&lt;/code&gt;, &lt;code&gt;df_print&lt;/code&gt;), and look at the effects on the rendered output.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To add options to &lt;code&gt;html_document&lt;/code&gt; in the YAML header, you&amp;rsquo;ll need to go from &lt;code&gt;output: html_document&lt;/code&gt; on a single line, to a multi-line format with indentation, and with a colon added after &lt;code&gt;html_document&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span class=&#34;nt&#34;&gt;output&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;html_document&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;l&#34;&gt;&amp;lt;option&amp;gt;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt; &lt;br&gt;
&lt;ul&gt;
&lt;li&gt;An example YAML header with several options added:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-yaml&#34; data-lang=&#34;yaml&#34;&gt;&lt;span class=&#34;nn&#34;&gt;---&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;title&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Penguins, demystified.&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;author&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;Jelmer Poelstra&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;date&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;1/29/2021&amp;#34;&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;output&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;  &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;html_document&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;theme&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;l&#34;&gt;flatly&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;toc&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;true&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;toc_float&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;true&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;toc_depth&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;m&#34;&gt;5&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;number_sections&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;true&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;code_download&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;kc&#34;&gt;true&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;code_folding&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;l&#34;&gt;hide&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;    &lt;/span&gt;&lt;span class=&#34;nt&#34;&gt;df_print&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;:&lt;/span&gt;&lt;span class=&#34;w&#34;&gt; &lt;/span&gt;&lt;span class=&#34;l&#34;&gt;kable&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;&lt;/span&gt;&lt;span class=&#34;nn&#34;&gt;---&lt;/span&gt;&lt;span class=&#34;w&#34;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;exercise-2-code-chunks&#34;&gt;Exercise 2: Code chunks&lt;/h3&gt;
&lt;p&gt;Our output document looks nice, but there is plenty of room for improvement. In this exercise, we&amp;rsquo;ll refine the output using code chunk options.&lt;/p&gt;
&lt;p&gt;Before you start, take another look at the box &lt;a href=&#34;#code-chunk-options&#34;&gt;Code chunk options&lt;/a&gt; above.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Did you notice those messages (when the &lt;em&gt;tidyverse&lt;/em&gt; is loaded) and warnings (for the two plots) in the output? Let&amp;rsquo;s get rid of those all at once: suppress R &lt;em&gt;messages&lt;/em&gt; and &lt;em&gt;warnings&lt;/em&gt; for all chunks by adding arguments to the &lt;code&gt;knitr::opts_chunk$set()&lt;/code&gt; function in the first code chunk.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Currently, the code line in the &lt;code&gt;install-package&lt;/code&gt; code chunk is commented out to avoid the code from running, while still printing it. Try to accomplish this using a code chunk option instead, so you can uncomment the line.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;We do want to print the code in some cases, but not in others. For the chunk labeled &lt;code&gt;print-tibble&lt;/code&gt;, which prints &lt;code&gt;penguins&lt;/code&gt;, alter the settings such that the code is no longer printed.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Our first figure is kind of squished, and the point and font sizes are perhaps too large. Compare this with the second figure, which has a different setting &lt;em&gt;only&lt;/em&gt; for &lt;code&gt;out.width&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Play around with the values for the three options that are already in the code chunks (&lt;code&gt;fig.width&lt;/code&gt;, &lt;code&gt;out.width&lt;/code&gt;, and &lt;code&gt;fig.asp&lt;/code&gt;), for one or both figures, see what the effects are, and try to make some improvements.&lt;/p&gt;
&lt;p&gt;Do you understand the difference between the two methods to indicate the figure size (&lt;code&gt;fig.width&lt;/code&gt; and &lt;code&gt;out.width&lt;/code&gt;)?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Insert a new code chunk that prints the &lt;code&gt;penguins_raw&lt;/code&gt; tibble in some way (this is available in your environment).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To suppress messages and warnings throughout:&lt;br&gt;
Add &lt;code&gt;message=FALSE&lt;/code&gt; and &lt;code&gt;warnings=FALSE&lt;/code&gt; inside &lt;code&gt;knitr::opts_chunk$set()&lt;/code&gt; in the &lt;code&gt;setup&lt;/code&gt; chunk.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To avoid running the code:&lt;br&gt;
Use &lt;code&gt;eval=FALSE&lt;/code&gt; in the header of the &lt;code&gt;install-package&lt;/code&gt; code chunk.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To avoid printing the code:&lt;br&gt;
Use the &lt;code&gt;echo&lt;/code&gt; option in the header of the &lt;code&gt;print-tibble&lt;/code&gt; code chunk.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Figure sizing:&lt;br&gt;
There are two types of sizes that you can set: the size at which R creates figures (&lt;code&gt;fig.width&lt;/code&gt; and &lt;code&gt;fig.height&lt;/code&gt;), and the size at which the figures are inserted in the document (&lt;code&gt;out.width&lt;/code&gt; and &lt;code&gt;out.height&lt;/code&gt;). The former will effectively only control relative font and point sizes, whereas the latter controls the &amp;ldquo;actual&amp;rdquo; / final size. For more details and advice, see &lt;a href=&#34;https://r4ds.had.co.nz/graphics-for-communication.html#figure-sizing&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this section&lt;/a&gt; in R for Data Science.&lt;/p&gt;
&lt;p&gt;The aspect ratio (&lt;code&gt;fig.asp&lt;/code&gt;) is height/width, so a value smaller than one creates a wide figure and a value larger than one creates a narrow figure.&lt;/p&gt;
&lt;p&gt;Here, we&amp;rsquo;ve been setting width only &amp;ndash; you can also set &lt;code&gt;fig.height&lt;/code&gt; and &lt;code&gt;out.height&lt;/code&gt;, but these options become redundant when you set the width &lt;em&gt;and&lt;/em&gt; the aspect ratio.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt; &lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To suppress messages and warnings throughout:&lt;br&gt;
&lt;code&gt;knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE)&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To avoid running the code: &lt;code&gt;{r install-package, eval=FALSE}&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To avoid printing the code:&lt;br&gt;
&lt;code&gt;{r print-tibble, echo=FALSE}&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Figure sizing:&lt;br&gt;
Example settings for better-sized figures &amp;ndash;&lt;br&gt;
&lt;code&gt;{r plot-bills, out.width=&amp;quot;80%&amp;quot;, fig.width=6, fig.asp=0.7}&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A code chunk to print the &lt;code&gt;penguins_raw&lt;/code&gt; tibble (replace single quotes by backticks):&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;!-- --&gt;
&lt;pre&gt;&lt;code&gt;&#39;&#39;&#39;{r}
penguins_raw
&#39;&#39;&#39;
&lt;/code&gt;&lt;/pre&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;bonus-1-markdown-and-inline-code&#34;&gt;Bonus 1: Markdown and inline code&lt;/h3&gt;
&lt;p&gt;The formatting for the prose in our document could also be improved. For instance:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Use inline code &lt;em&gt;formatting&lt;/em&gt; in a couple of cases where this is appropriate.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Instead of simply saying &amp;ldquo;8 variables (n = 344 penguins)&amp;rdquo; (under the &lt;em&gt;Summary of the dataset&lt;/em&gt;&amp;quot; heading), use &lt;em&gt;inline R code&lt;/em&gt; that makes these calculations and print the results.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Try a couple of other things: heading levels (one of them is currently not right!), &lt;em&gt;italic&lt;/em&gt; text, &lt;strong&gt;bold&lt;/strong&gt; text, and/or ordered (numbered) and unordered (bulleted) lists.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Simply put backticks around the inline text you want have formatted as code. You can do this, for instance, for mentions of &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/reference/penguins.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;palmerpenguins::penguins&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For inline code that runs, use &lt;code&gt;`r my-code`&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The number of variables and penguins in the penguin dataset are the number of columns and rows, respectively, in the &lt;code&gt;penguin&lt;/code&gt; tibble.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt; &lt;br&gt;
&lt;p&gt;Inline calculation of the number of variables and penguins:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;[...] that contains `r ncol(penguins)` variables
(n = `r nrow(penguins)` penguins).
&lt;/code&gt;&lt;/pre&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;bonus-2-other-output-formats&#34;&gt;Bonus 2: Other output formats&lt;/h3&gt;
&lt;p&gt;Try one or more output formats other than &lt;code&gt;html_document&lt;/code&gt;, see &lt;a href=&#34;https://rmarkdown.rstudio.com/docs/reference/index.html#section-output-formats&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this website&lt;/a&gt; for the list of available options. If you want to try presentations, note that three dashes &lt;code&gt;---&lt;/code&gt; are used to separate slides.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;It might be confusing that on the website linked to above (see also the screenshot in section V), the output formats are listed &lt;em&gt;functions&lt;/em&gt; (&lt;code&gt;html_document()&lt;/code&gt; rather than &lt;code&gt;html_document&lt;/code&gt;) &amp;ndash; but this is simply because under the hood, these functions are called via the YAML header.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;go-further&#34;&gt;Go further&lt;/h2&gt;
&lt;h4 id=&#34;pitfalls--tips&#34;&gt;Pitfalls / Tips&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;The working directory&lt;/strong&gt;&lt;br&gt;
By default, the working directory for an R Markdown document is the directory in which the file resides.&lt;/p&gt;
&lt;p&gt;This can be a bit annoying if you&amp;rsquo;re used to using your project&amp;rsquo;s root directory as your working directory (which you should be) and the R Markdown file is not in the project&amp;rsquo;s root directory (which it probably shouldn&amp;rsquo;t be). Nevertheless, simply using &lt;code&gt;../&lt;/code&gt; notation to move one or two directories up should generally work.&lt;/p&gt;
&lt;p&gt;If you really need to set a different working directory, you should be aware that surprisingly, setting the working directory with &lt;code&gt;setwd()&lt;/code&gt; in a code chunk is &lt;strong&gt;not persistent&lt;/strong&gt; across code chunks. To set a different working directory for the entire document, use &lt;code&gt;knitr::opts_knit$set(root.dir = &#39;/my/working/dir&#39;)&lt;/code&gt; in a setup chunk.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Chunk labels&lt;/strong&gt;&lt;br&gt;
Chunk labels are optional but if you do give them, note that they have to be &lt;em&gt;unique&lt;/em&gt;: the document will fail to render if have two chunks with the same label. Also, &lt;em&gt;avoid using spaces and underscores in the labels&lt;/em&gt; (&lt;code&gt;good-chunk-label&lt;/code&gt;, &lt;code&gt;bad chunk label&lt;/code&gt;, &lt;code&gt;bad_chunk_label&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;h4 id=&#34;tables&#34;&gt;Tables&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Tables produced by Markdown text&lt;/strong&gt;&lt;br&gt;
The syntax for basic Markdown tables is as follows:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;| Time          | Session | Topic    |
|:--------------|:-------:|---------:|
| _left_        | _center_| _right_  |
| Wed 5 pm      | 1       | Getting started  |
| Fri 3 pm      |         |          |
| Wed 5 pm      | 2       | *dplyr*  |
| Fri 3 pm      |         | *Break*  |
&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&#34;text-align:left&#34;&gt;Time&lt;/th&gt;
&lt;th style=&#34;text-align:center&#34;&gt;Session&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;Topic&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;&lt;em&gt;left&lt;/em&gt;&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;&lt;em&gt;center&lt;/em&gt;&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;&lt;em&gt;right&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Wed 5 pm&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;1&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;Getting started&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Fri 3 pm&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Wed 5 pm&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;2&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;&lt;em&gt;dplyr&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Fri 3 pm&lt;/td&gt;
&lt;td style=&#34;text-align:center&#34;&gt;&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;&lt;em&gt;Break&lt;/em&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;In the Visual Markdown editor in RStudio, you can simply insert a table with a little dialogue box after clicking &lt;code&gt;Table&lt;/code&gt; =&amp;gt; &lt;code&gt;Insert Table&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Tables (dataframes) produced by R code&lt;/strong&gt;&lt;br&gt;
Using &lt;code&gt;kable(my_df)&lt;/code&gt; in a code chunk will create nicer output for individual dataframes (recall the &lt;code&gt;df_print: kable&lt;/code&gt; YAML option for document-wide &amp;ldquo;kable&amp;rdquo; printing).&lt;/p&gt;
&lt;p&gt;There are many packages available for more advanced options, such as &lt;a href=&#34;https://gt.rstudio.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;GT&lt;/em&gt;&lt;/a&gt;, &lt;a href=&#34;https://rstudio.github.io/DT/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;DT&lt;/em&gt;&lt;/a&gt;, and &lt;a href=&#34;https://glin.github.io/reactable/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;reactable&lt;/em&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;h4 id=&#34;websites&#34;&gt;Websites&lt;/h4&gt;
&lt;p&gt;Note that &lt;code&gt;rmarkdown::render_site()&lt;/code&gt; can create simple websites that connects multiple pages with a navigation bar. All you need is a simple YAML file called &lt;code&gt;_site.yml&lt;/code&gt; with some settings, and a file for the front page which needs to be called &lt;code&gt;index.Rmd&lt;/code&gt;. See &lt;a href=&#34;https://bookdown.org/yihui/rmarkdown/rmarkdown-site.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here in the R Markdown book&lt;/a&gt; for more details.&lt;/p&gt;
&lt;p&gt;Options with more features, like a blog, are &lt;a href=&#34;https://rstudio.github.io/distill/website.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;distill websites&lt;/em&gt;&lt;/a&gt;, and the &lt;a href=&#34;https://bookdown.org/yihui/blogdown/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;em&gt;blogdown&lt;/em&gt; package&lt;/a&gt; for Hugo sites.&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;further-resources&#34;&gt;Further resources&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;Free online books by the primary creator of R Markdown and other authors:
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://bookdown.org/yihui/rmarkdown/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R Markdown &amp;ndash; The Definitive Guide&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://bookdown.org/yihui/rmarkdown-cookbook/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R Markdown Cookbook&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rstudio.com/wp-content/uploads/2015/03/rmarkdown-reference.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;RStudio&amp;rsquo;s 5-page R Markdown Reference PDF&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://github.com/rstudio/cheatsheets/raw/master/rmarkdown-2.0.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;RStudio&amp;rsquo;s R Markdown Cheatsheet&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://rmarkdown.rstudio.com/lesson-1.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;RStudio R Markdown lessons&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://commonmark.org/help/tutorial/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Markdown tutorial&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</description>
    </item>
    
    <item>
      <title>Session 6: Factors</title>
      <link>https://biodash.github.io/codeclub/06_factors/</link>
      <pubDate>Mon, 18 Jan 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/06_factors/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;p&gt;Factors form the basis for many powerful operations in R, including many performed on tabular data. The motivation for factors comes from the notion of categorical variables. These variables are non-numeric in nature corresponding to categories such as male and female, or Democrat, Republican and Independent.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;A factor might be viewed simply as a vector with a bit of more information added.&lt;/strong&gt; The extra information consists of a record of distinct values in that vector, which are called: &lt;em&gt;&lt;strong&gt;levels&lt;/strong&gt;&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Let us look at some examples of factors. We will make use of the package &lt;em&gt;forcats&lt;/em&gt;, which is one of the 8 core &lt;em&gt;tidyverse&lt;/em&gt; packages. Therefore, we start by loading the &lt;em&gt;tidyverse&lt;/em&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching packages&lt;/span&gt;&lt;span&gt; ─────────────────────────────────────── tidyverse 1.3.0 ──&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2&lt;/span&gt;&lt;span&gt; 3.3.3     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;purrr  &lt;/span&gt;&lt;span&gt; 0.3.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;tibble &lt;/span&gt;&lt;span&gt; 3.0.4     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr  &lt;/span&gt;&lt;span&gt; 1.0.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr  &lt;/span&gt;&lt;span&gt; 1.1.2     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stringr&lt;/span&gt;&lt;span&gt; 1.4.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;readr  &lt;/span&gt;&lt;span&gt; 1.4.0     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;forcats&lt;/span&gt;&lt;span&gt; 0.5.0&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt;&lt;span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt;&lt;span&gt; masks &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;&lt;span&gt;::filter()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;&lt;span&gt;    masks &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;&lt;span&gt;::lag()&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;## Check whether &#34;forcats&#34; is listed among the loaded packages.&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;## Alternatively, you could load &#34;forcats&#34; (and &#34;ggplot2&#34;) separately:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;forcats&#34;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# library(forcats)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# library(ggplot2)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;example-1-from-a-numeric-vector-to-a-factor&#34;&gt;Example 1: From a numeric vector to a factor&lt;/h2&gt;
&lt;p&gt;Let us create a factor &lt;code&gt;xf&lt;/code&gt; from a vector &lt;code&gt;x&lt;/code&gt; with the numbers &lt;code&gt;5&lt;/code&gt;, &lt;code&gt;12&lt;/code&gt;, &lt;code&gt;13&lt;/code&gt;, and &lt;code&gt;12&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;12&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;13&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;12&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1]  5 12 13 12&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# Convert the vector to a factor:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;xf&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/factor.html&#39;&gt;factor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;x&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;xf&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 5  12 13 12&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Levels: 5 12 13&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The &lt;em&gt;distinct values&lt;/em&gt; in &lt;code&gt;xf&lt;/code&gt; are &lt;code&gt;5&lt;/code&gt;, &lt;code&gt;12&lt;/code&gt; and &lt;code&gt;13&lt;/code&gt;, and are listed as &lt;em&gt;levels&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;Let us look in a bit more details at our factor using the R functions &lt;code&gt;str&lt;/code&gt; and &lt;code&gt;unclass&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;xf&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  Factor w/ 3 levels &#34;5&#34;,&#34;12&#34;,&#34;13&#34;: 1 2 3 2&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;unclass&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;xf&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 2 3 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; attr(,&#34;levels&#34;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;5&#34;  &#34;12&#34; &#34;13&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Notice that the values in the factor are not stored as &lt;code&gt;(5, 12, 13, 12)&lt;/code&gt;, but rather as &lt;code&gt;(1, 2, 3, 2)&lt;/code&gt;!&lt;/p&gt;
&lt;p&gt;This means that our data consists first of a level-1 value, then level-2 and level 3 values, and finally another level-2 value. So, the data has been recorded by level.&lt;/p&gt;
&lt;p&gt;The values attached to each level are recorded too, but as &lt;em&gt;characters&lt;/em&gt; such as &lt;code&gt;&amp;quot;5&amp;quot;&lt;/code&gt; rather than as numbers such as &lt;code&gt;5&lt;/code&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;example-2-from-a-character-vector-to-a-factor&#34;&gt;Example 2: From a character vector to a factor&lt;/h2&gt;
&lt;p&gt;We will use the levels Democrat (&lt;code&gt;D&lt;/code&gt;), Republican (&lt;code&gt;R&lt;/code&gt;), and Independent (&lt;code&gt;I&lt;/code&gt;). First, we save a &lt;em&gt;vector&lt;/em&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;D&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;R&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;R&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;I&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;R&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;I&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;D&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;I&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;D&#34; &#34;R&#34; &#34;R&#34; &#34;I&#34; &#34;R&#34; &#34;I&#34; &#34;D&#34; &#34;I&#34;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  chr [1:8] &#34;D&#34; &#34;R&#34; &#34;R&#34; &#34;I&#34; &#34;R&#34; &#34;I&#34; &#34;D&#34; &#34;I&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then, we again convert the &lt;em&gt;vector&lt;/em&gt; to a &lt;em&gt;factor&lt;/em&gt;, and look at the levels:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;fy&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/factor.html&#39;&gt;factor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;fy&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] D R R I R I D I&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Levels: D I R&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/class.html&#39;&gt;unclass&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;fy&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 1 3 3 2 3 2 1 2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; attr(,&#34;levels&#34;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;D&#34; &#34;I&#34; &#34;R&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;example-3-ordering-factor-levels&#34;&gt;Example 3: Ordering factor levels&lt;/h2&gt;
&lt;p&gt;Some variables can be challenging to sort automatically, because the desired sorting order is not alphabetical or numeric.&lt;/p&gt;
&lt;p&gt;For instance, months that are listed using characters:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;months_vector&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Dec&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Apr&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Jan&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Mar&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Try to sort using the `sort` function&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/sort.html&#39;&gt;sort&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;months_vector&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;Apr&#34; &#34;Dec&#34; &#34;Jan&#34; &#34;Mar&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;That didn&amp;rsquo;t sort in a useful way. &lt;strong&gt;But, the problem can be fixed by using a factor.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;First, we create a list of the valid levels, which are all 12 months in a year:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;month_levels&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Jan&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Feb&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Mar&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Apr&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;May&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Jun&#34;&lt;/span&gt;,
                  &lt;span class=&#39;s&#39;&gt;&#34;Jul&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Aug&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Sep&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Oct&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Nov&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Dec&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then we convert the vector into a factor, like before, but now we additionally specify the desired levels of the factor, &lt;strong&gt;in order&lt;/strong&gt;, using the &lt;code&gt;levels&lt;/code&gt; argument:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;months_factor&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/factor.html&#39;&gt;factor&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;months_vector&lt;/span&gt;, levels &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;month_levels&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now it sorts the way we want to!&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/sort.html&#39;&gt;sort&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;months_factor&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] Jan Mar Apr Dec&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Levels: Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;example-4-use-of-factors-in-plots-with-forcats&#34;&gt;Example 4: Use of factors in plots with &lt;em&gt;forcats&lt;/em&gt;&lt;/h2&gt;
&lt;h3 id=&#34;4a-plot-after-reordering-manually-with-fct_relevel&#34;&gt;4A: Plot after reordering manually with &lt;code&gt;fct_relevel()&lt;/code&gt;&lt;/h3&gt;
&lt;p&gt;We will use the &lt;em&gt;mtcars&lt;/em&gt; data, which was extracted from the 1974 Motor Trend US magazine, and comprises fuel consumption and 10 aspects of automobile design and performance for 32 automobiles (1973&amp;ndash;74 models) &amp;ndash; a data frame with 32 observations for 11 (numeric) variables,&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/data.html&#39;&gt;data&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/names.html&#39;&gt;names&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;  [1] &#34;mpg&#34;  &#34;cyl&#34;  &#34;disp&#34; &#34;hp&#34;   &#34;drat&#34; &#34;wt&#34;   &#34;qsec&#34; &#34;vs&#34;   &#34;am&#34;   &#34;gear&#34;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; [11] &#34;carb&#34;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 32 11&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &#39;data.frame&#39;:  32 obs. of  11 variables:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ mpg : num  21 21 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ cyl : num  6 6 4 6 8 6 8 4 4 6 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ disp: num  160 160 108 258 360 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ hp  : num  110 110 93 110 175 105 245 62 95 123 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ drat: num  3.9 3.9 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ wt  : num  2.62 2.88 2.32 3.21 3.44 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ qsec: num  16.5 17 18.6 19.4 17 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ vs  : num  0 0 1 1 0 1 0 1 1 1 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ am  : num  1 1 1 0 0 0 0 0 0 0 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ gear: num  4 4 4 3 3 3 3 4 4 4 ...&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;  $ carb: num  4 4 1 1 2 1 4 2 2 4 ...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;we will select six variables (&lt;code&gt;mpg&lt;/code&gt;, &lt;code&gt;cyl&lt;/code&gt;, &lt;code&gt;disp&lt;/code&gt;, &lt;code&gt;hp&lt;/code&gt;, and &lt;code&gt;wt&lt;/code&gt;) to create a dataset &lt;code&gt;Data&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;mpg&lt;/code&gt;: Miles per (US) gallon,&lt;/li&gt;
&lt;li&gt;&lt;code&gt;cyl&lt;/code&gt;: Number of cylinders&lt;/li&gt;
&lt;li&gt;&lt;code&gt;disp&lt;/code&gt;: Displacement (cu.in.)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;hp&lt;/code&gt;: Horse power&lt;/li&gt;
&lt;li&gt;&lt;code&gt;wt&lt;/code&gt;: Weight (in 1000 lbs)&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;Data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;mpg&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;cyl&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;disp&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;hp&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;wt&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now, we&amp;rsquo;ll add a new column &lt;code&gt;cyl_chr&lt;/code&gt; by converting &lt;code&gt;cyl&lt;/code&gt; from &lt;em&gt;numeric&lt;/em&gt; to &lt;em&gt;character&lt;/em&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;Data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cyl_chr &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;recode&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;cyl&lt;/span&gt;,`4` &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Four&#34;&lt;/span&gt;, `6` &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Six&#34;&lt;/span&gt;, `8` &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Eight&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;    mpg cyl disp  hp    wt cyl_chr&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 21.0   6  160 110 2.620     Six&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 21.0   6  160 110 2.875     Six&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3 22.8   4  108  93 2.320    Four&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4 21.4   6  258 110 3.215     Six&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5 18.7   8  360 175 3.440   Eight&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6 18.1   6  225 105 3.460     Six&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We plot a bar chart for &lt;code&gt;cyl_chr&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;Data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cyl_chr&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_bar&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;In the plot, the levels of the factor were arranged in alphabetical order (&lt;code&gt;Eight&lt;/code&gt;, &lt;code&gt;Four&lt;/code&gt;, and &lt;code&gt;Six&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;Instead, we want the bar graph arranged in the order &lt;code&gt;Four&lt;/code&gt;, &lt;code&gt;Six&lt;/code&gt;, and &lt;code&gt;Eight&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;An alternative to using &lt;a href=&#34;https://rdrr.io/r/base/factor.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;factor(levels = ...)&lt;/code&gt;&lt;/a&gt; like we did above, is to use the &lt;code&gt;fct_relevel()&lt;/code&gt; function from the &lt;em&gt;forcats&lt;/em&gt; package:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;Data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;cyl_chr &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;fct_relevel&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;cyl_chr&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Four&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Six&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Eight&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;cyl_chr&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_bar&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Cylinder&#34;&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Number of cars&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;h3 id=&#34;4b-plot-after-reordering-by-the-value-of-another-column-fct_reorder&#34;&gt;4B: Plot after reordering by the value of another column (&lt;code&gt;fct_reorder&lt;/code&gt;)&lt;/h3&gt;
&lt;p&gt;Create a dataset called &lt;code&gt;Data_a&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;Data_a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/data.frame.html&#39;&gt;data.frame&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;name &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;North&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;South&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;East&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;West&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                     var &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/sample.html&#39;&gt;sample&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/seq.html&#39;&gt;seq&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;10&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;m&#39;&gt;4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Plot a bar chart of &lt;code&gt;Data_a&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;Data_a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;name&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;var&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_bar&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;stat &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;identity&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;#f68034&#34;&lt;/span&gt;, alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.6&lt;/span&gt;, width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-16-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Reorder following the value of another column using the &lt;code&gt;fct_reorder()&lt;/code&gt; function, and flip the plot:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;Data_a&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;name &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;fct_reorder&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;name&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;var&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;name&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;var&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_bar&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;stat &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;identity&#34;&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;#f68034&#34;&lt;/span&gt;, alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.6&lt;/span&gt;, width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.4&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;coord_flip&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-17-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;There are several more convenient reordering functions in the &lt;em&gt;forcats&lt;/em&gt; package, including:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;fact_infreq()&lt;/code&gt; to reorder by occurrence frequencies of each level (see the picture at the top of the post).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;fct_inorder()&lt;/code&gt; to reorder by order of appearance in the dataframe. This can be useful, for example, if your dataframe has already been sorted properly, and you just need to prevent automatic alphabetic reordering when plotting.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout rooms!&lt;/h2&gt;
&lt;p&gt;For the Breakout room exercises, we will use datasets from &lt;em&gt;mtcars&lt;/em&gt; and the &lt;code&gt;gss_cat&lt;/code&gt; dataset from the &lt;em&gt;forcats&lt;/em&gt; package.&lt;/p&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Convert the variable &lt;code&gt;gear&lt;/code&gt; from &lt;em&gt;mtcars&lt;/em&gt; to a character vector with words for each number (link in example 4A), and plot a bar chart.&lt;/p&gt;
&lt;p&gt;Then, use a factor to reorder the bars to appear in the regular &amp;ldquo;numeric&amp;rdquo; order: &amp;ldquo;Three&amp;rdquo; then &amp;ldquo;Four&amp;rdquo; then &amp;ldquo;Five&amp;rdquo;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, create a dataframe with a column that codes the gears as words, using the &lt;code&gt;mutate()&lt;/code&gt; and &lt;code&gt;recode()&lt;/code&gt; functions.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Then, create a factor from this modified gear column, and order it manually using the &lt;code&gt;fct_relevel()&lt;/code&gt; function.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt; &lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Start by loading the dataset:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/data.html&#39;&gt;data&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;mtcars&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Now, create a new dataset &lt;code&gt;Gear&lt;/code&gt; from &lt;em&gt;mtcars&lt;/em&gt;, adding a column &lt;code&gt;gear_chr&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;gear_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mtcars&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;gear_chr &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;recode&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;gear&lt;/span&gt;,
                         `3`&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Three&#34;&lt;/span&gt;,
                         `4` &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Four&#34;&lt;/span&gt;,
                         `5`&lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Five&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;gear_df&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;    mpg cyl disp  hp drat    wt  qsec vs am gear carb gear_chr&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 21.0   6  160 110 3.90 2.620 16.46  0  1    4    4     Four&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 21.0   6  160 110 3.90 2.875 17.02  0  1    4    4     Four&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3 22.8   4  108  93 3.85 2.320 18.61  1  1    4    1     Four&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4 21.4   6  258 110 3.08 3.215 19.44  1  0    3    1    Three&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2    Three&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6 18.1   6  225 105 2.76 3.460 20.22  1  0    3    1    Three&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;ul&gt;
&lt;li&gt;Finally, use the &lt;em&gt;forcats&lt;/em&gt; function &lt;code&gt;fct_relevel()&lt;/code&gt; to rearrange &lt;code&gt;gear_chr&lt;/code&gt; in nonalphabetical order, and plot the barchart using &lt;code&gt;geom_bar()&lt;/code&gt;:&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;gear_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;gear_fct &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;fct_relevel&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;gear_chr&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Three&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Four&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Five&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gear_fct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_bar&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Gear&#34;&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Number of cars&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-20-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Using the &lt;code&gt;gss_cat&lt;/code&gt; dataset from the &lt;em&gt;forcats&lt;/em&gt; package (available as &lt;code&gt;gsscat&lt;/code&gt; in your environment), create a plot that compares the average number of hours spent watching TV per day across religions, and where &lt;em&gt;religions are ordered by the average number of hours&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;(Despite what we&amp;rsquo;ve learned last week, start by merely plotting the mean, and no distributions, using a barplot or with &lt;code&gt;geom_point()&lt;/code&gt;.)&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Source: (R for Data Science)&lt;/em&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt; &lt;br&gt; In order to be able to order the factor by the average number of hours spent watching TV, first compute this average per religion, and save the results in a dataframe (use `mutate()` and `summarize()`).
&lt;p&gt;Then, use &lt;code&gt;fct_recorder()&lt;/code&gt; to reorder the factor.&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt; &lt;br&gt;
&lt;p&gt;First, have a look at the dataset:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;forcats&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://forcats.tidyverse.org/reference/gss_cat.html&#39;&gt;gss_cat&lt;/a&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 21,483 x 9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     year marital     age race  rincome    partyid     relig     denom    tvhours&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;      &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;      &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;000 Never ma…    26 White $8000 to … Ind,near r… Protesta… Souther…      12&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;000 Divorced     48 White $8000 to … Not str re… Protesta… Baptist…      &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;000 Widowed      67 White Not appli… Independent Protesta… No deno…       2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;000 Never ma…    39 White Not appli… Ind,near r… Orthodox… Not app…       4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;000 Divorced     25 White Not appli… Not str de… None      Not app…       1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;000 Married      25 White $20000 - … Strong dem… Protesta… Souther…      &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;000 Never ma…    36 White $25000 or… Not str re… Christian Not app…       3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;000 Divorced     44 White $7000 to … Ind,near d… Protesta… Luthera…      &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;000 Married      44 White $25000 or… Not str de… Protesta… Other          0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;000 Married      47 White $25000 or… Strong rep… Protesta… Souther…       3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 21,473 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then, calculate the mean number of tv-hours and create a plot:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;relig&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gss_cat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;relig&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;tvhours &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tvhours&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;relig&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tvhours&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;relig&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-22-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;It is difficult to interpret this plot because there is no overall pattern.&lt;/p&gt;
&lt;p&gt;We can improve the plot by reordering the level of religion using &lt;code&gt;fct_reorder()&lt;/code&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;relig&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;gss_cat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;relig&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;tvhours &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tvhours&lt;/span&gt;, na.rm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;relig&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;relig &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;fct_reorder&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;relig&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;tvhours&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;tvhours&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;relig&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-23-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Reordering religion makes it much easier to see that people in the &amp;ldquo;Don&amp;rsquo;t know&amp;rdquo; category watch much more TV.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-exercise-3&#34;&gt;Bonus: Exercise 3&lt;/h3&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;In exercise 2, we saw large differences in the &lt;em&gt;average&lt;/em&gt; time spent watching TV across religions, but we should perhaps have a closer look at the data by plotting distributions.&lt;/p&gt;
&lt;p&gt;Go back to the &lt;a href=&#34;https://biodash.github.io/codeclub/05_ggplot-round-2/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;previous Code Club session&lt;/a&gt; and decide which type of plot could be ideal with so many categories.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt; &lt;br&gt; [`geom_density_ridges()`](https://wilkelab.org/ggridges/reference/geom_density_ridges.html) from the *ggridges* package is very well suited for a plot with so many categories.
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt; &lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/&#39;&gt;ggridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;gss_cat&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;tvhours&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;relig&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;relig&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#39;&gt;geom_density_ridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.8&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Number of hours spent watching TV&#39;&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;Religion&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;guides&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_minimal&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Picking joint bandwidth of 0.586&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 10146 rows containing non-finite values (stat_density_ridges).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-24-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
</description>
    </item>
    
    <item>
      <title>Session 5: ggplot2, round 2</title>
      <link>https://biodash.github.io/codeclub/05_ggplot-round-2/</link>
      <pubDate>Fri, 15 Jan 2021 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/05_ggplot-round-2/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;prep-homework&#34;&gt;Prep homework&lt;/h2&gt;
&lt;h3 id=&#34;basic-computer-setup&#34;&gt;Basic computer setup&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/04_ggplot2/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;new-to-ggplot&#34;&gt;New to ggplot?&lt;/h3&gt;
&lt;p&gt;Check out the last Code Club &lt;a href=&#34;https://biodash.github.io/codeclub/&#34;&gt;Session 4&lt;/a&gt; on Visualizing Data.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;ve never used &lt;code&gt;ggplot2&lt;/code&gt; before (or even if you have), you may find &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this cheat sheet&lt;/a&gt; useful.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;getting-started&#34;&gt;Getting Started&lt;/h2&gt;
&lt;h3 id=&#34;script-for-todays-session&#34;&gt;Script for today&amp;rsquo;s session&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# directory for Code Club Session 2:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S05&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# directory for our script&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# (&#34;recursive&#34; to create two levels at once.)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S05/scripts/&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# save the url location for today&#39;s script&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;todays_R_script&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/05_ggplot-round-2/Session5_ggplot2.R&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# indicate the name of the new script file&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;Session5_script&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;S05/scripts/Session5_script.R&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# go get that file! &lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;todays_R_script&lt;/span&gt;,
              destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Session5_script&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---why-visualize-our-data&#34;&gt;1 - Why visualize our data?&lt;/h2&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=ggplot2_exploratory.png width=&#34;95%&#34; alt=&#34;ggplot2 exploratory cartoon&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Artwork by &lt;a href=&#34;https://github.com/allisonhorst/stats-illustrations&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;We make data visualizations for two main reasons:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;To explore our data&lt;/li&gt;
&lt;li&gt;To share our data with others&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Often, we think about figure generation as the last part of the scientic process, something you do as you prepare a manuscript for publication. I hope to convince you that exploring your data, and making exploratory plots is a critical part of the data analysis and interpretation process.&lt;/p&gt;
&lt;p&gt;Today we will be using &lt;a href=&#34;https://ggplot2.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggplot2&lt;/code&gt;&lt;/a&gt; to make a series of plots that help us better understand the underlying structure in our dataset.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;When summary statistics don&amp;rsquo;t cut it&lt;/strong&gt;&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=DinoSequentialSmaller.gif width=&#34;95%&#34;&gt;
&lt;/p&gt;
&lt;p&gt;This &lt;a href=&#34;https://www.autodesk.com/research/publications/same-stats-different-graphs&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&amp;ldquo;Datasaurus Dozen&amp;rdquo;&lt;/a&gt; shows the value of looking at your data beyond means and standard deviations. In the gif above, created by &lt;a href=&#34;http://albertocairo.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Alberto Cairo&lt;/a&gt;, each of these 13 datasets have identical means, standard eviations, and correlations to two decimal places. And one of the datasets is a dinosaur!&lt;/p&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;&lt;strong&gt;What will we go over today&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;These geoms will help you to get better acquainted with your data.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_bar.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_col()&lt;/code&gt;&lt;/a&gt; - makes bar plots. I will show you how to do this and then recommend that you don&amp;rsquo;t.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_boxplot.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_boxplot()&lt;/code&gt;&lt;/a&gt; - makes infinitely useful boxplots.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_violin.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_violin()&lt;/code&gt;&lt;/a&gt; - makes violin plots, a hybrid between a boxplot and a density plot. Very musical.&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://mran.microsoft.com/snapshot/2017-12-11/web/packages/ggridges/vignettes/introduction.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_density_ridges()&lt;/code&gt;&lt;/a&gt; - a density plot giving you the impression of a side view of a mountain range. Requires the package &lt;a href=&#34;https://cran.r-project.org/web/packages/ggridges/index.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;ggridges&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_jitter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_jitter()&lt;/code&gt;&lt;/a&gt; - adds all datapoints to your plot, and jitters them to handle overplotting.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I will also go over a few tricks along the way, including &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/coord_flip.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;coord_flip()&lt;/code&gt;&lt;/a&gt;, adding labels using &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/labs.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;labs()&lt;/code&gt;&lt;/a&gt;, and changing the overall look of the plot with &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/theme.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;theme()&lt;/code&gt;&lt;/a&gt;, or pre-set themes like &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/ggtheme.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;theme_classic()&lt;/code&gt;&lt;/a&gt; which is my go-to.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2---accessing-our-data&#34;&gt;2 - Accessing our data&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Let&amp;rsquo;s get set up and grab some data so that we can learn more about penguins (and ggplot2)&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You can do this locally, or at OSC. You can find instructions if you are having trouble &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;First load your libraries.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then let&amp;rsquo;s access the wintry &lt;a href=&#34;https://allisonhorst.github.io/palmerpenguins/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;palmerpenguins&lt;/a&gt; dataset. We will then look at &lt;code&gt;penguins&lt;/code&gt;, the dataset we will be using for the first part of today&amp;rsquo;s Code Club. This data is collected on penguins from the &lt;a href=&#34;https://pal.lternet.edu/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Palmer Station Antarctica Long-Term Ecological Research&lt;/a&gt; study area.&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=penguins.png width=&#34;95%&#34; alt=&#34;cartoon of the palmer penguins&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Artwork by &lt;a href=&#34;https://github.com/allisonhorst/palmerpenguins&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;palmerpenguins&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://allisonhorst.github.io/palmerpenguins/&#39;&gt;palmerpenguins&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s look at the data in &lt;code&gt;penguins&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# look at the first 6 rows, all columns&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species island bill_length_mm bill_depth_mm flipper_length_… body_mass_g sex  &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;           &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.1          18.7              181        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;750 male &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.5          17.4              186        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;800 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Adelie  Torge…           40.3          18                195        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;250 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Adelie  Torge…           &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Adelie  Torge…           36.7          19.3              193        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;450 fema…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Adelie  Torge…           39.3          20.6              190        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;3&lt;/span&gt;&lt;span&gt;650 male &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 1 more variable: year &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# check the structure&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# this tell us what is contained within our df&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 344&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 8&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Adelie, Adelie, Adelie, Adelie, Adelie, Adelie, Ade…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ island            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Torgersen, Torgersen, Torgersen, Torgersen, Torgers…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_length_mm    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 39.1, 39.5, 40.3, NA, 36.7, 39.3, 38.9, 39.2, 34.1,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ bill_depth_mm     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 18.7, 17.4, 18.0, NA, 19.3, 20.6, 17.8, 19.6, 18.1,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ flipper_length_mm &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 181, 186, 195, NA, 193, 190, 181, 195, 193, 190, 18…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ body_mass_g       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 3750, 3800, 3250, NA, 3450, 3650, 3625, 4675, 3475,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ sex               &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; male, female, female, NA, female, male, female, mal…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ year              &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 200…&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This dataset contains the following measurements about penguins at Palmer Station in Antarctica:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;species&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;island&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bill_length_mm&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;bill_depth_mm&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;flipper_length_mm&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;body_mass_g&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;sex&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;year&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;We are going to be plotting to get an understanding of &lt;code&gt;bill_length_mm&lt;/code&gt; which is the length of the bill from the penguins face, protruding outwards (and more easily understood in the image below).&lt;/p&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=culmen_depth.png width=&#34;95%&#34; alt=&#34;depiction of bill length protruding from the penguins face, and bill depth, the height of the bill parallel to the ground&#34;&gt;
&lt;/p&gt;
&lt;p&gt;Artwork by &lt;a href=&#34;https://github.com/allisonhorst/palmerpenguins&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Allison Horst&lt;/a&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3---removing-nas&#34;&gt;3 - Removing NAs&lt;/h2&gt;
&lt;p&gt;Sometimes you will have NAs (or missing data). That might be informative to you, but here we are going to remove missing data using &lt;a href=&#34;https://tidyr.tidyverse.org/reference/drop_na.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;drop_na()&lt;/code&gt;&lt;/a&gt;, and assign it to a new dataframe called &lt;code&gt;penguins_noNA&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# check dimensions of penguins&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 344   8&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# remove NAs&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;penguins&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# we have removed 11 observations&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 333   8&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Note - by removing NAs, we have gotten rid of 11 observations&lt;/strong&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4---bar-charts-with-geom_col-and-stat_summary&#34;&gt;4 - Bar charts with &lt;code&gt;geom_col()&lt;/code&gt; and &lt;code&gt;stat_summary()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Often, people use bar charts, representing the height or the length of the bar as proportional to the average value that it represents. These charts are sometimes called dynamite plots because they resemble (when they have an error bar with whisker) those cartoon style dynamite sticks. Pow!&lt;/p&gt;
&lt;p&gt;However, these bar charts, even if you add a standard deviation/error, really can hide the true distribution of your data, and for this reason, I and &lt;a href=&#34;https://simplystatistics.org/2019/02/21/dynamite-plots-must-die/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;others&lt;/a&gt; hope you don&amp;rsquo;t select to make them.&lt;/p&gt;
&lt;p&gt;I hope after today, you see that there is always a better chart type to make than a bar chart. But I will show you how to make them anyway.&lt;/p&gt;
&lt;p&gt;Before we plot, let&amp;rsquo;s calculate some summary statistics so we know what we should expect.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# calculating mean bill_length_mm by species&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_bill_length &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species   mean_bill_length&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;                &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Adelie                38.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Chinstrap             48.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Gentoo                47.6&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Just calling &lt;code&gt;geom_col()&lt;/code&gt; does not give us what we want. Look at the y-axis scale and how out of line this is with our summary statistics.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# bar plot with geom_col()&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# this is wrong!&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_col&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-8-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Using &lt;code&gt;geom_col()&lt;/code&gt; the right way.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# bar plot, the right way with geom_col()&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean_bill_length &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;mean_bill_length&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_col&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-9-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# or you could do this in a less bulky way with stat_summary()&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;stat_summary&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fun &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;mean&#34;&lt;/span&gt;, geom &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;bar&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-9-2.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;5---boxplots-with-geom_boxplot&#34;&gt;5 - Boxplots with &lt;code&gt;geom_boxplot()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;A boxplot has the benefit of showing you more than the median and the standard deviation, so you can better see the true distribution of your data. In &lt;code&gt;geom_boxplot()&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;lower whisker = smallest observation greater than or equal to lower hinge - 1.5 * IQR&lt;/li&gt;
&lt;li&gt;lower hinge/bottom line of box part of boxplot = 25% quantile&lt;/li&gt;
&lt;li&gt;middle = median, 50% quantile&lt;/li&gt;
&lt;li&gt;upper hinge/top line of box part of boxplot = 75% quantile&lt;/li&gt;
&lt;li&gt;upper whisker = largest observation less than or equal to upper hinge + 1.5 * IQR&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# vertical boxplot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-10-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Adding &lt;code&gt;coord_flip()&lt;/code&gt; makes your vertical boxplot horizontal. You could do the same thing by flipping the variables on the &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; mappings.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# horizontal boxplot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;coord_flip&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-11-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Look at how much more information we have here than in our bar plots!&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;5---violin-plots-with-geom_violin&#34;&gt;5 - Violin plots with &lt;code&gt;geom_violin()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;A violin plot is boxplot-esque, but shows a mirrored density distribution. This type of plot is useful when you are trying to particularly show data distribution.&lt;/p&gt;
&lt;p&gt;Note here I have also mapped &lt;code&gt;species&lt;/code&gt; to &lt;code&gt;color&lt;/code&gt;, within the &lt;code&gt;aes&lt;/code&gt; statement so it will apply globally to this plot.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# violin plot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_violin&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Adding &lt;code&gt;geom_point()&lt;/code&gt; lets you add another layer of all the actual data points, on top of your violin plot. Remember that this is inherent in the design of ggplot2, that you can layer your plots, of different types, on top of each other.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# violin plot with data points overlaid&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_violin&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Note, I am now mapping &lt;code&gt;species&lt;/code&gt; to &lt;code&gt;fill&lt;/code&gt; instead of &lt;code&gt;color&lt;/code&gt;. See the difference?&lt;/p&gt;
&lt;p&gt;This doesn&amp;rsquo;t look too good because of overplotting, i.e., the smear of datapoints that doesn&amp;rsquo;t give you much information about distribution.&lt;/p&gt;
&lt;p&gt;We can add &lt;code&gt;geom_jitter()&lt;/code&gt; to introduce some small amount of randomness to our points to make us able to see them better. Seeing all your data points also lets the reader easily get a sense of your sample size.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# violin plot with data points jittered&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_violin&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;geom_jitter()&lt;/code&gt; is a specialized version of &lt;code&gt;geom_point()&lt;/code&gt;, but you could replace the &lt;code&gt;geom_jitter()&lt;/code&gt; call with &lt;code&gt;geom_point(position = &amp;quot;jitter)&lt;/code&gt; and get the same result. You can also use &lt;code&gt;geom_point(position = position_jitterdodge())&lt;/code&gt; if you only want jitter in the x, and don&amp;rsquo;t want any jitter in the y.&lt;/p&gt;
&lt;p&gt;Wow, we now have so much more information about our data!&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;6---dot-plots-with-geom_dotplot&#34;&gt;6 - Dot plots with &lt;code&gt;geom_dotplot()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;A dot plot plots each individual datapoint, and can stack how you like. These look a lot like the SigmaPlot plots to me.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;binaxis&lt;/code&gt; can be set to &amp;ldquo;x&amp;rdquo; or &amp;ldquo;y&amp;rdquo;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;stackdir&lt;/code&gt; indicates how to stack the dots: &amp;ldquo;up&amp;rdquo; (default), &amp;ldquo;down&amp;rdquo;, &amp;ldquo;center&amp;rdquo;, &amp;ldquo;centerwhole&amp;rdquo; (centered, but with dots aligned)&lt;/li&gt;
&lt;li&gt;&lt;code&gt;dotsize&lt;/code&gt; indicates the size of the dots, with 1 as default&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# dotplot&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_dotplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;binaxis &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;y&#34;&lt;/span&gt;, stackdir &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;center&#34;&lt;/span&gt;, dotsize &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `stat_bindot()` using `bins = 30`. Pick better value with `binwidth`.&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-15-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;7---density-ridge-plots-with-geom_density_ridgeshttpswilkelaborgggridgesreferencegeom_density_ridgeshtml&#34;&gt;7 - Density ridge plots with &lt;a href=&#34;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_density_ridges()&lt;/code&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p&gt;A density ridge plots with &lt;a href=&#34;https://www.rdocumentation.org/packages/ggridges/versions/0.5.2/topics/geom_density_ridges&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_density_ridges()&lt;/code&gt;&lt;/a&gt; requires the packages &lt;code&gt;ggridges&lt;/code&gt;, and make multiple density plots in a staggered orientation.&lt;/p&gt;
&lt;p&gt;You can adjust &lt;code&gt;scale&lt;/code&gt; within &lt;a href=&#34;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_density_ridges()&lt;/code&gt;&lt;/a&gt; to adjust the size of each density plot, though I have left it on the default. Adding &lt;code&gt;alpha&lt;/code&gt; sets transparency.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;ggridges&#34;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/&#39;&gt;ggridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#39;&gt;geom_density_ridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.8&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Picking joint bandwidth of 1.08&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-16-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;8---ggplot-is-made-for-layering&#34;&gt;8 - ggplot is made for layering!&lt;/h2&gt;
&lt;p&gt;I have shown you a bunch of different plot types, and you can combine many of them together. Here is an example of combining &lt;code&gt;geom_violin()&lt;/code&gt; and &lt;code&gt;geom_jitter()&lt;/code&gt;, while mapping new variables to aesthetics.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, 
             color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;, 
             shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;, 
             group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_violin&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;position_jitterdodge&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;jitter.width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-17-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;9---increase-clarity-and-visual-appeal&#34;&gt;9 - Increase clarity and visual appeal&lt;/h2&gt;
&lt;p&gt;We can quickly make our plot:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;prettier by setting a &lt;code&gt;theme&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;more clear by setting plot labels (eg., axes, titles, legend) with &lt;code&gt;labs&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;penguins_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;bill_length_mm&lt;/span&gt;, 
             color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;sex&lt;/span&gt;, 
             shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;island&lt;/span&gt;, 
             group &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_violin&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;position &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;position_jitterdodge&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;jitter.width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
              alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.7&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme_classic&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Bill Length by Species, Sex and Location&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Collected at Palmer Station, Antarctica&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Penguin Species&#34;&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# x axis label&lt;/span&gt;
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bill length (mm)&#34;&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;#  y axis label&lt;/span&gt;
       color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Sex&#34;&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# legend title&lt;/span&gt;
       shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Island&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# legend title&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-18-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;10---breakout-rooms&#34;&gt;10 - Breakout rooms!&lt;/h2&gt;
&lt;h3 id=&#34;main-exercises&#34;&gt;Main exercises&lt;/h3&gt;
&lt;h4 id=&#34;get-data&#34;&gt;Get data&lt;/h4&gt;
&lt;p&gt;We are going to use the NHANES dataset we used in &lt;a href=&#34;https://biodash.github.io/codeclub/s03_joining-datasets/&#34;&gt;Session 3&lt;/a&gt; on joining. What was that data about again? Let&amp;rsquo;s refresh our memory.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;knitr&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;::&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/knitr/man/kable.html&#39;&gt;kable&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;/code&gt;&lt;/pre&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th style=&#34;text-align:right&#34;&gt;ID&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;SurveyYr&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;Gender&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;Age&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;AgeDecade&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;AgeMonths&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;Race1&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;Race3&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;Education&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;MaritalStatus&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;HHIncome&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;HHIncomeMid&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;Poverty&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;HomeRooms&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;HomeOwn&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;Work&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;Weight&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;Length&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;HeadCirc&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;Height&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;BMI&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;BMICatUnder20yrs&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;BMI_WHO&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;Pulse&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;BPSysAve&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;BPDiaAve&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;BPSys1&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;BPDia1&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;BPSys2&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;BPDia2&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;BPSys3&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;BPDia3&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;Testosterone&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;DirectChol&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;TotChol&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;UrineVol1&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;UrineFlow1&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;UrineVol2&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;UrineFlow2&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;Diabetes&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;DiabetesAge&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;HealthGen&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;DaysPhysHlthBad&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;DaysMentHlthBad&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;LittleInterest&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;Depressed&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;nPregnancies&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;nBabies&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;Age1stBaby&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;SleepHrsNight&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;SleepTrouble&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;PhysActive&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;PhysActiveDays&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;TVHrsDay&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;CompHrsDay&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;TVHrsDayChild&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;CompHrsDayChild&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;Alcohol12PlusYr&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;AlcoholDay&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;AlcoholYear&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;SmokeNow&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;Smoke100&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;Smoke100n&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;SmokeAge&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;Marijuana&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;AgeFirstMarij&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;RegularMarij&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;AgeRegMarij&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;HardDrugs&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;SexEver&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;SexAge&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;SexNumPartnLife&lt;/th&gt;
&lt;th style=&#34;text-align:right&#34;&gt;SexNumPartYear&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;SameSex&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;SexOrientation&lt;/th&gt;
&lt;th style=&#34;text-align:left&#34;&gt;PregnantNow&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:right&#34;&gt;51624&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;2009_10&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;male&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;34&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;30-39&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;409&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;White&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;High School&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Married&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;25000-34999&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;30000&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1.36&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;6&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Own&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NotWorking&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;87.4&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;164.7&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;32.22&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;30.0_plus&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;70&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;113&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;85&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;114&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;88&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;114&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;88&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;112&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;82&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1.29&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;3.49&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;352&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Good&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;15&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Most&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Several&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;4&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Smoker&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;18&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;17&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;16&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;8&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Heterosexual&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:right&#34;&gt;51624&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;2009_10&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;male&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;34&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;30-39&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;409&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;White&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;High School&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Married&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;25000-34999&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;30000&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1.36&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;6&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Own&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NotWorking&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;87.4&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;164.7&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;32.22&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;30.0_plus&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;70&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;113&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;85&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;114&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;88&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;114&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;88&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;112&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;82&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1.29&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;3.49&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;352&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Good&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;15&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Most&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Several&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;4&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Smoker&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;18&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;17&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;16&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;8&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Heterosexual&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:right&#34;&gt;51624&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;2009_10&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;male&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;34&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;30-39&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;409&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;White&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;High School&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Married&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;25000-34999&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;30000&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1.36&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;6&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Own&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NotWorking&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;87.4&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;164.7&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;32.22&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;30.0_plus&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;70&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;113&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;85&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;114&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;88&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;114&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;88&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;112&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;82&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1.29&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;3.49&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;352&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Good&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;15&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Most&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Several&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;4&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Smoker&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;18&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;17&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;16&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;8&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Heterosexual&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:right&#34;&gt;51625&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;2009_10&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;male&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;4&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;0-9&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;49&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Other&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;20000-24999&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;22500&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1.07&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;9&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Own&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;17.0&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;105.4&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;15.30&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;12.0_18.5&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;4&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:right&#34;&gt;51630&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;2009_10&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;female&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;49&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;40-49&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;596&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;White&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Some College&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;LivePartner&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;35000-44999&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;40000&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1.91&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;5&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Rent&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NotWorking&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;86.7&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;168.4&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;30.57&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;30.0_plus&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;86&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;112&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;75&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;118&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;82&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;108&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;74&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;116&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;76&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1.16&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;6.70&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;77&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0.094&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Good&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;10&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Several&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Several&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;2&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;2&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;27&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;8&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;2&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;20&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Smoker&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;38&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;18&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;12&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;10&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Yes&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Heterosexual&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td style=&#34;text-align:right&#34;&gt;51638&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;2009_10&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;male&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;9&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;0-9&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;115&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;White&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;75000-99999&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;87500&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1.84&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;6&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;Rent&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;29.8&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;133.1&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;16.82&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;12.0_18.5&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;82&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;86&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;47&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;84&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;50&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;84&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;50&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;88&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;44&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1.34&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;4.86&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;123&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;1.538&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;No&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;5&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;0&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:right&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;td style=&#34;text-align:left&#34;&gt;NA&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# kable just formats as a scrollable table for this website&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# you can just use head(NHANES) or glimpse(NHANES)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Create a new data frame includes the NHANES data only from individuals that are 20 years of age or older, and removes observations where there are NAs for either age subdivided by decade (&lt;code&gt;AgeDecade&lt;/code&gt;) or total cholesterol (&lt;code&gt;TotChol&lt;/code&gt;).&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Try using a series of &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; statements. Remember, you can tell filter what you want, or what you don&amp;rsquo;t want. You can filter for if specific variables have NAs by using &lt;a href=&#34;https://rdrr.io/r/base/NA.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;is.na()&lt;/code&gt;&lt;/a&gt; on your variable of interest. Also remember that &lt;a href=&#34;https://rdrr.io/r/base/Logic.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;!&lt;/code&gt;&lt;/a&gt; means &amp;ldquo;not.&amp;rdquo; You will notice that if you want to use &lt;code&gt;drop_NA()&lt;/code&gt; you need to specific which specific variables you want to use, or you will inadvertably drop a lot of observations which have missing data for variables other than those we are plotting.. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# here are a few ways to do this&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;NHANES_over20_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Age&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;drop_na&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;TotChol&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NHANES_over20_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 6408   76&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;NHANES_over20_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Age&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;20&lt;/span&gt;,
         &lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
         &lt;span class=&#39;o&#39;&gt;!&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/NA.html&#39;&gt;is.na&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;TotChol&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NHANES_over20_noNA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 6408   76&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Create a boxplot to show the relationship between total cholesterol (&lt;code&gt;TotChol&lt;/code&gt;) and age (&lt;code&gt;AgeDecade&lt;/code&gt;).&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Try &lt;code&gt;geom_boxplot()&lt;/code&gt;. Map your variables of interest to the &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; aesthetics. Which you variable you put on &lt;code&gt;x&lt;/code&gt; and &lt;code&gt;y&lt;/code&gt; will determine if your boxplot is vertical or horizontal. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;NHANES_over20_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;TotChol&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-22-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Take your plot from Exercise 2 and make it a violin plot instead of a boxplot. Then color by age.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;The geom for a violin plot is &lt;code&gt;geom_violin()&lt;/code&gt;. You can change color by mapping to &lt;code&gt;color&lt;/code&gt; or to &lt;code&gt;fill&lt;/code&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;p&gt;Note the difference between mapping to &lt;code&gt;color&lt;/code&gt; vs. &lt;code&gt;fill&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;NHANES_over20_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;TotChol&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_violin&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-23-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;NHANES_over20_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;TotChol&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_violin&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-24-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Make add a boxplot to your violin plot from Exercise 3. Adjust the parameters so you the plot looks good to you.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;In &lt;code&gt;geom_boxplot()&lt;/code&gt;, you can adjust the width of the boxplot by setting &lt;code&gt;width = X&lt;/code&gt;. A width of 1 is the default. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;NHANES_over20_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;TotChol&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_violin&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-25-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;exercise-5&#34;&gt;Exercise 5&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Add all of the data points on top of your boxplot from Exercise 2 of total cholesterol by age. Adjust the parameters so you the plot looks good to you. While you are at it, clean up your plot labels and give your plot a title.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Remember that ggplot layers your plots, so layers that are further down in your code, will be applied on top of those that come earlier. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;p&gt;&lt;code&gt;geom_boxplot(outlier.shape = NA)&lt;/code&gt; removes the outliers from &lt;code&gt;geom_boxplot()&lt;/code&gt;, since we are plotting all of the points, we do not want the outliers appearing twice.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;NHANES_over20_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;TotChol&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_boxplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;outlier.shape &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;NA&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;geom_jitter&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.3&lt;/span&gt;, alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Total Cholesterol by Age&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data from the National Health and Nutrition Examination Survey (NHANES)&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Age, by Decade&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Total Cholesterol, mmol/L&#34;&lt;/span&gt;,
       color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Age (years)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-26-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-exercises&#34;&gt;Bonus exercises&lt;/h3&gt;
&lt;h4 id=&#34;bonus-1&#34;&gt;Bonus 1&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Make a density ridge plot for age by total cholesterol.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Try &lt;a href=&#34;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_density_ridges()&lt;/code&gt;&lt;/a&gt;, and remember, this is not a part of &lt;code&gt;ggplot2&lt;/code&gt;, so be sure to call &lt;a href=&#34;https://wilkelab.org/ggridges/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library(ggridges)&lt;/code&gt;&lt;/a&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;ggridges&#34;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/&#39;&gt;ggridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;NHANES_over20_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;TotChol&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#39;&gt;geom_density_ridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.7&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Picking joint bandwidth of 0.224&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-27-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;bonus-2&#34;&gt;Bonus 2&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Take your density ridge plot from Bonus 1, and try applying a theme from &lt;code&gt;hrbrthemes&lt;/code&gt; to it.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;&lt;code&gt;hrbrthemes&lt;/code&gt; is not part of &lt;code&gt;ggplot2&lt;/code&gt; so remember to install the package, and then call &lt;a href=&#34;http://github.com/hrbrmstr/hrbrthemes&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library(hrbrthemes)&lt;/code&gt;&lt;/a&gt;. You can google the package to see what all your theme options are. I like &lt;a href=&#34;https://rdrr.io/pkg/hrbrthemes/man/theme_ipsum_rc.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;theme_ipsum_rc()&lt;/code&gt;&lt;/a&gt;, try that one if you like! &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;hrbrthemes&#34;)&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://github.com/hrbrmstr/hrbrthemes&#39;&gt;hrbrthemes&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; NOTE: Either Arial Narrow or Roboto Condensed fonts are required to use these themes.&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;       Please use hrbrthemes::import_roboto_condensed() to install Roboto Condensed and&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;       if Arial Narrow is not on your system, please see https://bit.ly/arialnarrow&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;NHANES_over20_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;TotChol&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#39;&gt;geom_density_ridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.7&lt;/span&gt;, scale &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.9&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/hrbrthemes/man/theme_ipsum_rc.html&#39;&gt;theme_ipsum_rc&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Picking joint bandwidth of 0.224&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-28-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;bonus-3&#34;&gt;Bonus 3&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Tidy up your plot from Bonus 2 by giving it a title, axis labels, and try adding the median total cholesterol to each density ridge plot.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Using &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/stat_summary.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;stat_summary()&lt;/code&gt;&lt;/a&gt; will help you add the median.&lt;br&gt;
&lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;theme(axis.title.x = element_text(hjust = 0.5))&lt;/code&gt; makes the x-axis title center justified.&lt;/li&gt;
&lt;li&gt;you can change &lt;code&gt;shape&lt;/code&gt; within &lt;code&gt;stat_summary()&lt;/code&gt; to be anything you like, either an R shape, a specific keyboard key, or even a pasted emoji. The default is a point.&lt;/li&gt;
&lt;li&gt;when you set a &lt;code&gt;theme()&lt;/code&gt;, anything that comes below will override what code comes previous, so for this reason, if you are going to amend a pre-made theme, first call the pre-made theme, and then make any changes you like below.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;NHANES_over20_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;TotChol&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#39;&gt;geom_density_ridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.7&lt;/span&gt;, scale &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.9&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;stat_summary&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fun &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;median&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/hrbrthemes/man/theme_ipsum_rc.html&#39;&gt;theme_ipsum_rc&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;axis.title.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
        axis.title.y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Total Cholesterol by Age&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data from the National Health and Nutrition Examination Survey (NHANES)&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Total Cholesterol, mmol/L&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Age, by Decade&#34;&lt;/span&gt;,
       fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Age (years)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Picking joint bandwidth of 0.224&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 6 rows containing missing values (geom_segment).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-29-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h4 id=&#34;bonus-4&#34;&gt;Bonus 4&lt;/h4&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Commonly used cutoffs for cholesterol are: &amp;lt; 5.2 mmol/L is normal, 5.2-6.2 mmol/L is borderline high and &amp;gt; 6.2 mmol is high. Add a vertical cutoff line showing the level below which cholesterol would be considered normal.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Using &lt;a href=&#34;https://ggplot2.tidyverse.org/reference/geom_abline.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;geom_vline()&lt;/code&gt;&lt;/a&gt; will let you add a vertical line with an &lt;code&gt;xintercept&lt;/code&gt; that is appropriate. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;NHANES_over20_noNA&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;TotChol&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;AgeDecade&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://wilkelab.org/ggridges/reference/geom_density_ridges.html&#39;&gt;geom_density_ridges&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.7&lt;/span&gt;, scale &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.9&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;stat_summary&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;fun &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;median&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_vline&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;xintercept &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5.2&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/pkg/hrbrthemes/man/theme_ipsum_rc.html&#39;&gt;theme_ipsum_rc&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;theme&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;axis.title.x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
        axis.title.y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;element_text&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;hjust &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;labs&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;title &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Total Cholesterol by Age&#34;&lt;/span&gt;,
       subtitle &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Data from the National Health and Nutrition Examination Survey (NHANES)&#34;&lt;/span&gt;,
       caption &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Vertical line indicates upper limit of normal cholesterol&#34;&lt;/span&gt;,
       x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Total Cholesterol, mmol/L&#34;&lt;/span&gt;,
       y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Age, by Decade&#34;&lt;/span&gt;,
       fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Age (years)&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Picking joint bandwidth of 0.224&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 6 rows containing missing values (geom_segment).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-30-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Session 4: Visualizing Data</title>
      <link>https://biodash.github.io/codeclub/04_ggplot2/</link>
      <pubDate>Thu, 10 Dec 2020 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/04_ggplot2/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New To Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has some pointers that might be helpful if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Please open RStudio before Code Club to test things out &amp;ndash; if you run into issues, join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Learn the philosophy of &lt;strong&gt;coding&lt;/strong&gt; a graphic.&lt;/li&gt;
&lt;li&gt;Learn the basic &lt;strong&gt;template&lt;/strong&gt; of a &lt;strong&gt;ggplot2&lt;/strong&gt; graphic, so you can reuse it for multiple chart types.&lt;/li&gt;
&lt;li&gt;Learn how you can quickly add visual information to a graphic using &lt;strong&gt;aesthetics&lt;/strong&gt; and &lt;strong&gt;layers&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;intro-the-ggplot2-philosophy&#34;&gt;Intro: The ggplot2 philosophy&lt;/h2&gt;
&lt;p&gt;We have already seen that in R, instead of manually manipulating data frames as you might do when editing Excel sheets, we &lt;strong&gt;code&lt;/strong&gt; the operations we want to perform using &lt;strong&gt;dplyr&lt;/strong&gt; verbs like &lt;code&gt;select()&lt;/code&gt;, &lt;code&gt;mutate()&lt;/code&gt;, &lt;code&gt;inner_join()&lt;/code&gt;, and so on.&lt;/p&gt;
&lt;p&gt;In a similar way when performing visualization, instead of clicking on a chart type in Excel, we &lt;strong&gt;code the chart&lt;/strong&gt; in R.&lt;/p&gt;
&lt;p&gt;And just as &lt;strong&gt;dplyr&lt;/strong&gt; gives us efficient ways to manipulate data frames, &lt;strong&gt;ggplot2&lt;/strong&gt; (which is also part of the tidyverse) gives us efficient ways to manipulate charts/plots/graphics (we use these terms interchangeably).&lt;/p&gt;
&lt;p&gt;The &lt;strong&gt;gg&lt;/strong&gt; in &lt;strong&gt;ggplot2&lt;/strong&gt; stands for &lt;em&gt;grammar of graphics&lt;/em&gt;, a systematic approach for designing statistical plots developed by Leland Wilkinson. The idea behind this was to think about &amp;lsquo;pulling apart&amp;rsquo; various plots into their shared component pieces, then provide code that could put them together again. We can then create new plots like we create new sentences (once we understand this grammar).&lt;/p&gt;
&lt;p&gt;There are two parts to this. First, the &amp;lsquo;nouns and verbs&amp;rsquo; we need to work with plots are very different than those we need to work with data frames. &lt;strong&gt;ggplot2&lt;/strong&gt; is like a mini-language of its own, with its own verbs and syntax.&lt;/p&gt;
&lt;p&gt;Second, this notion of pulling apart a graphic leads to the idea of &lt;em&gt;layers&lt;/em&gt;. You can build up a plot of any complexity by &lt;em&gt;overlaying&lt;/em&gt; different views of the same data.&lt;/p&gt;
&lt;p&gt;There&amp;rsquo;s a learning curve here for sure, but there are a couple of things that help us.&lt;/p&gt;
&lt;p&gt;First, every graphic shares a &lt;em&gt;common template&lt;/em&gt;. This is like thinking about the sentence &amp;ldquo;The cat sat on the mat&amp;rdquo; grammatically as the template &lt;code&gt;NP V PP&lt;/code&gt; (&lt;code&gt;N&lt;/code&gt;oun &lt;code&gt;P&lt;/code&gt;hrase &amp;ldquo;The cat&amp;rdquo;, &lt;code&gt;V&lt;/code&gt;erb &amp;ldquo;sat&amp;rdquo;, &lt;code&gt;P&lt;/code&gt;repositional &lt;code&gt;P&lt;/code&gt;hrase &amp;ldquo;on the mat&amp;rdquo;). Once you understand this structure you can &amp;ldquo;say&amp;rdquo; a &lt;em&gt;lot&lt;/em&gt; of different things.&lt;/p&gt;
&lt;p&gt;(And I mean a &lt;em&gt;lot&lt;/em&gt;. The &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;ggplot cheat sheet&lt;/a&gt; lists over 40 plot-types, but because this is a language, users can create their own &lt;a href=&#34;https://exts.ggplot2.tidyverse.org/gallery/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;extensions&lt;/a&gt; that you can also utilize, adding over 80 more.)&lt;/p&gt;
&lt;p&gt;Second, the way we put layers together is identical to the way we use pipes. You can read &lt;code&gt;%&amp;gt;%&lt;/code&gt; as &amp;ldquo;and then&amp;rdquo;: &lt;code&gt;select()&lt;/code&gt; &lt;em&gt;and then&lt;/em&gt; &lt;code&gt;mutate()&lt;/code&gt; &lt;em&gt;and then&lt;/em&gt; &lt;code&gt;summarize()&lt;/code&gt;. In graphics, we can say &amp;ldquo;show this layer, and then &lt;em&gt;overlay&lt;/em&gt; this layer, and then &lt;em&gt;overlay&lt;/em&gt; this layer&amp;rdquo;, etc., using a very similar syntax.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;So how does this work in practice? We&amp;rsquo;ll work through visualizing the &lt;strong&gt;iris&lt;/strong&gt; dataset that you&amp;rsquo;ve seen before. This is an extremely famous &lt;a href=&#34;https://en.m.wikipedia.org/wiki/Iris_flower_data_set&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;dataset&lt;/a&gt; that was first analyzed by R. A. Fisher in 1936: &lt;em&gt;The use of multiple measurements in taxonomic problems&lt;/em&gt;. He was attempting to use petal and sepal measurements to discriminate one species from another.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;ggplot2&lt;/strong&gt; is part of the tidyverse package so we need to load that first:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# this assumes you&#39;ve already installed tidyverse&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching packages&lt;/span&gt;&lt;span&gt; ─────────────────────────────────────── tidyverse 1.3.0 ──&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2&lt;/span&gt;&lt;span&gt; 3.3.2     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;purrr  &lt;/span&gt;&lt;span&gt; 0.3.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;tibble &lt;/span&gt;&lt;span&gt; 3.0.4     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr  &lt;/span&gt;&lt;span&gt; 0.8.5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr  &lt;/span&gt;&lt;span&gt; 1.0.3     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stringr&lt;/span&gt;&lt;span&gt; 1.4.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;readr  &lt;/span&gt;&lt;span&gt; 1.3.1     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;forcats&lt;/span&gt;&lt;span&gt; 0.5.0&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt;&lt;span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt;&lt;span&gt; masks &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;&lt;span&gt;::filter()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;&lt;span&gt;    masks &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;&lt;span&gt;::lag()&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;And recall that the &lt;strong&gt;iris&lt;/strong&gt; dataset (3 species, 50 observations per species) is automatically available to us:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Sepal.Length Sepal.Width Petal.Length Petal.Width Species&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1          5.1         3.5          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2          4.9         3.0          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3          4.7         3.2          1.3         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4          4.6         3.1          1.5         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5          5.0         3.6          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6          5.4         3.9          1.7         0.4  setosa&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What is the correlation between petal length and width in these species? Are longer petals also wider? We can visualize this with a scatterplot. But first let&amp;rsquo;s look a the ggplot template. (Note the package is &lt;strong&gt;ggplot2&lt;/strong&gt;, the command is &lt;code&gt;ggplot&lt;/code&gt;.)&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;ggplot(data = &amp;lt;DATA&amp;gt;) + 
  &amp;lt;GEOM_FUNCTION&amp;gt;(mapping = aes(&amp;lt;MAPPINGS&amp;gt;))
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;These are the obligatory parts of any plot. The first argument to &lt;code&gt;ggplot()&lt;/code&gt; is the data frame:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-3-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;This is not very interesting! but it&amp;rsquo;s notable that it is &lt;em&gt;something&lt;/em&gt;. &lt;code&gt;ggplot()&lt;/code&gt; has created a base coordinate system (a base layer) that we can add visual layers to. The &lt;em&gt;add a layer&lt;/em&gt; operator is &amp;ldquo;&lt;strong&gt;+&lt;/strong&gt;&amp;rdquo;, which is the ggplot equivalent of the pipe symbol, and &lt;strong&gt;it must occur at the end of the line&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The next argument specifies the kind plot we want: scatterplot, bar chart, fitted line, boxplot, pie chart, etc. &lt;strong&gt;ggplot2&lt;/strong&gt; refers to these as &lt;strong&gt;geoms&lt;/strong&gt;: the geometrical object that a plot uses to represent data. You can see an overview of many of these geoms in the &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-visualization-2.1.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;cheat sheet&lt;/a&gt;. The geom for a scatterplot is &lt;code&gt;geom_point()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;But we also require a &lt;code&gt;mapping&lt;/code&gt; argument, which maps the &lt;em&gt;variables&lt;/em&gt; in the dataset we want to focus on to their &lt;em&gt;visual representation&lt;/em&gt; in the plot.&lt;/p&gt;
&lt;p&gt;And finally we need to specify an &lt;strong&gt;aesthetic&lt;/strong&gt; for the geometric objects in the plot, which will control things like shape, color, transparency, etc. Perhaps surprisingly, for a scatterplot, the x and y coordinates are aesthetics, since these control, not the shape or color, but the relative position of the points in the coordinate system.&lt;/p&gt;
&lt;p&gt;Here is our complete plot:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-4-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;There is clearly a positive correlation between length and width. And we can make this even more apparent by visually fitting a line to the data, by &lt;em&gt;overlaying&lt;/em&gt; another geom in the same plot.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using method = &#39;loess&#39; and formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-5-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;There is clearly some code redundancy here, and we really don&amp;rsquo;t want the x, y mapping of these two layers to be independent. We can extract the common mapping information and move it to the top level:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mapping&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_smooth&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `geom_smooth()` using method = &#39;loess&#39; and formula &#39;y ~ x&#39;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-6-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;So we have the possibility of &lt;em&gt;local&lt;/em&gt; layer specifications, and &lt;em&gt;global&lt;/em&gt; specifications. Global specifications are &lt;em&gt;inherited&lt;/em&gt; by all the local layers.&lt;/p&gt;
&lt;h3 id=&#34;the-power-of-aesthetics&#34;&gt;The power of aesthetics&lt;/h3&gt;
&lt;p&gt;The aim of Fisher&amp;rsquo;s paper was to try to discriminate different species based on their morphological measurements. It looks from this plot that there are two distinct clusters. Do these clusters correspond to different species? There are two clusters, but three species. How can we explore this further?&lt;/p&gt;
&lt;p&gt;Our current plot uses two numeric variables: &lt;code&gt;Petal.Length&lt;/code&gt; and &lt;code&gt;Petal.width&lt;/code&gt;. We can add a third categorical variable, like &lt;code&gt;Species&lt;/code&gt;, to a two dimensional scatterplot by mapping it to a different visual aesthetic. We&amp;rsquo;ve mapped length and width to x,y coordinates. Now we&amp;rsquo;ll simultaneously map species to &lt;code&gt;color&lt;/code&gt; by expanding our list of aesthetics:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mapping&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-7-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;The R help for a specific geoms will list, among other things, all the aesthetics that geom supports.&lt;/p&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout Rooms&lt;/h2&gt;
&lt;p&gt;In the exercises we&amp;rsquo;ll be looking a little more at the &lt;strong&gt;iris&lt;/strong&gt; data, and in addition, the NHANES data we used last week, and the left-joined bird dataset we built last week in &lt;strong&gt;Excercise 7&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;If you haven&amp;rsquo;t installed the NHANES dataset do:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;NHANES&#34;&lt;/span&gt;, repos &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;http://cran.us.r-project.org&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; The downloaded binary packages are in&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   /var/folders/d4/h4yjqs1560zbsgvrrwbmbp5r0000gn/T//RtmpPvm8W9/downloaded_packages&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Once installed, load it with:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;A prebuilt joined data set has been loaded on github.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# create a data directory for the new file if you haven&#39;t done so yet:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;data/birds&#39;&lt;/span&gt;, recursive &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning in dir.create(&#34;data/birds&#34;, recursive = TRUE): &#39;data/birds&#39; already exists&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# set the url&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;joined_data_url&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/04_ggplot2/joined_data.tsv&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# set the path for the downloaded file&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;joined_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;data/birds/joined_data.tsv&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#download to file&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;joined_data_url&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;joined_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# read file&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;joined_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Parsed with column specification:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; cols(&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   locality = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   stateProvince = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   eventDate = &lt;span style=&#39;color: #0000BB;&#39;&gt;col_datetime(format = &#34;&#34;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species_en = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   adult_body_mass_g = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   adult_svl_cm = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   longevity_y = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   litter_or_clutch_size_n = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; )&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h2 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Revisit the &lt;strong&gt;iris&lt;/strong&gt; data set, and plot sepal width (y) against sepal length (x) colored by species. Which morphological character, petals or sepals, provides the greatest discrimination between species?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;Simply reuse the code we used for petals. You can often leverage code from an old plot for a new one. &lt;br&gt; &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mapping&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Sepal.Length&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Sepal.Width&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-11-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Note this solution shows yet another way to position global mapping information: as its own layer. This can help readability and avoid too many nested parentheses.&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Use the NHANES data set to plot body mass index (y) against height (x). Color by gender. Which gender has the highest BMI?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;&lt;code&gt;glimpse()&lt;/code&gt; the dataset to identify the variable names. &lt;br&gt; &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Height&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;BMI&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Gender&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 366 rows containing missing values (geom_point).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-12-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Use the same plot but now color by physical activity. How active are those people with the highest BMI?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;Again, &lt;code&gt;glimpse()&lt;/code&gt; the dataset to identify the variable names. &lt;br&gt; &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Height&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;BMI&lt;/span&gt;, color &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;PhysActive&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 366 rows containing missing values (geom_point).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-13-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Often plotting the data allows us to identify outliers, which may be data-entry errors, or genuinely extreme data. Using the &lt;code&gt;joined_data&lt;/code&gt; set, plot adult body mass (y) against longevity (x). Identify extreme data points at the high end of body mass. How can we identify what these points represent?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt; Examine the plot to find an appropriate threshold value, and filter the data using that value. How many data points are there passing that threshold? What species are represented by these data points? How many weights are reported? Why is the plot misleading here? &lt;br&gt; &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_point&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mapping &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Warning: Removed 24089 rows containing missing values (geom_point).&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-14-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 228 x 9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species locality stateProvince eventDate           species_en&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;&lt;span&gt;              &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Cygnus… Findlay  Ohio          2008-02-17 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt;&lt;span&gt; Mute Swan &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Cygnus… Dundee   Ohio          2004-02-16 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt;&lt;span&gt; Mute Swan &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Cygnus… 44805 A… Ohio          2006-02-18 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt;&lt;span&gt; Mute Swan &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Cygnus… 45011 H… Ohio          2005-02-19 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt;&lt;span&gt; Mute Swan &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Cygnus… 45042 M… Ohio          2009-02-13 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt;&lt;span&gt; Trumpeter…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Cygnus… 44813 B… Ohio          2007-02-19 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt;&lt;span&gt; Mute Swan &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Cygnus… Spencer  Ohio          2008-02-16 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt;&lt;span&gt; Mute Swan &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Cygnus… 44903 M… Ohio          2009-02-16 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt;&lt;span&gt; Mute Swan &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Cygnus… 44601 A… Ohio          2002-02-16 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt;&lt;span&gt; Mute Swan &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Cygnus… Avon La… Ohio          2007-02-17 &lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;00:00:00&lt;/span&gt;&lt;span&gt; Mute Swan &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 218 more rows, and 4 more variables: adult_body_mass_g &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   adult_svl_cm &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, longevity_y &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, litter_or_clutch_size_n &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 2 x 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species          &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;            &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Cygnus olor      &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Cygnus buccinator&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;10000&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 2 x 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   adult_body_mass_g&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;               &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt;             &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;&lt;span&gt;230&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt;             &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;10&lt;/span&gt;&lt;span&gt;300&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;h2 id=&#34;bonus-a-new-geom&#34;&gt;Bonus, a new geom!&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;p&gt;Revisit the &lt;strong&gt;iris&lt;/strong&gt; data and generate a density histogram for sepal length, categorized by species.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;br&gt;Use &lt;code&gt;geom_density()&lt;/code&gt;. Check the help to see what aesthetics it supports. Note that while you &#39;color&#39; a point, you &#39;fill&#39; an area. &lt;br&gt; &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;ggplot&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;data &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;mapping&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;aes&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Sepal.Length&lt;/span&gt;, fill &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;+&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;geom_density&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;alpha &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;0.5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;img src=&#34;figs/unnamed-chunk-18-1.png&#34; width=&#34;700px&#34; style=&#34;display: block; margin: auto;&#34; /&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Note, what does the &lt;strong&gt;alpha&lt;/strong&gt; aesthetic control? &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Session 3: Joining Datasets</title>
      <link>https://biodash.github.io/codeclub/03_joining-datasets/</link>
      <pubDate>Fri, 04 Dec 2020 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/03_joining-datasets/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New To Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has some pointers that might be helpful if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Please open RStudio before Code Club to test things out &amp;ndash; if you run into issues, join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Differentiate between different types of joins&amp;hellip;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;inner_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;full_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;left_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;right_join()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use a join function to add new variables to the birds dataset&lt;/li&gt;
&lt;li&gt;Keep practicing with dplyr core verbs from last week, esp&amp;hellip;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Answer the question &amp;ldquo;What Ohio bird species have the longest and shortest average lifespans?&amp;rdquo;.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;intro-mergingjoining-datasets&#34;&gt;Intro: Merging/Joining Datasets&lt;/h2&gt;
&lt;p&gt;Sometimes you don&amp;rsquo;t have all your data in the same place. For example, maybe you have multiple Excel sheets for a project - each storing a different type of data for the same set of samples. Or maybe you&amp;rsquo;re interested in analyzing various metrics for US states and are getting the data from different places online - economic data from one database, climate data from another, and so on. As part of the process of data wrangling, it&amp;rsquo;s often useful to merge the separate datasets together according to a variable they share, possibly &amp;ldquo;SampleID&amp;rdquo; or &amp;ldquo;State Name&amp;rdquo; for the two above examples, respectively. R offers several ways to do this, but we&amp;rsquo;ll focus here on the set of &lt;code&gt;*_join()&lt;/code&gt; functions available in &lt;em&gt;dplyr&lt;/em&gt;. They include&amp;hellip;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;inner_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;full_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;left_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;right_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;semi_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;anti_join()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Check out the &amp;lsquo;Combine Data Sets&amp;rsquo; section of this &lt;a href=&#34;https://rstudio.com/wp-content/uploads/2015/02/data-wrangling-cheatsheet.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;cheat sheet&lt;/a&gt; for a brief look at these functions.&lt;/p&gt;
&lt;p&gt;You can also get more details &lt;a href=&#34;https://dplyr.tidyverse.org/reference/join.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;, or, as with any R function, by accessing the function&amp;rsquo;s documentation inside R with the &amp;lsquo;?&amp;rsquo;. For example, type &lt;code&gt;?inner_join&lt;/code&gt; at your R prompt and hit Enter. (Make sure the package the function comes from is loaded first! In this case, you need &lt;em&gt;dplyr&lt;/em&gt;, which is loaded as part of &lt;em&gt;tidyverse&lt;/em&gt;.)&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;Below we&amp;rsquo;ll go through a few examples of joins. You&amp;rsquo;re welcome to follow along and run this code on your own, &lt;strong&gt;but it&amp;rsquo;s not necessary&lt;/strong&gt; - the exercises in the breakout rooms are independent of these examples and will give you a chance to try these things out on your own.&lt;/p&gt;
&lt;p&gt;If you want to follow along, you can find the code &lt;a href=&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/scripts/birds/S03_Examples_Code.R&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;p&gt;Since the &lt;code&gt;*_join()&lt;/code&gt; functions come from the &lt;em&gt;dplyr&lt;/em&gt; package, which is part of &lt;em&gt;tidyverse&lt;/em&gt;, I&amp;rsquo;ll load that first&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#this assumes you&#39;ve already installed tidyverse&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The National Health and Nutrition Examination Survey &lt;a href=&#34;https://www.rdocumentation.org/packages/NHANES/versions/2.1.0/topics/NHANES&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;(NHANES) dataset&lt;/a&gt; contains survey data obtained annually from ~5,000 individuals on a variety of health and lifestyle-related metrics. A subset of the data are available as an R package - install and load it&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;NHANES&#34;&lt;/span&gt;, repos &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;http://cran.us.r-project.org&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; The downloaded binary packages are in&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   /var/folders/s7/y_mgh3c54h9fjcyw9wqdkb8x4zs_jy/T//RtmpdHHxzY/downloaded_packages&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now preview the dataset&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 10,000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 76&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ ID               &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 51624, 51624, 51624, 51625, 51630, 51638, 51646, 516…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SurveyYr         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; 2009_10, 2009_10, 2009_10, 2009_10, 2009_10, 2009_10…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Gender           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; male, male, male, male, female, male, male, female, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Age              &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 34, 34, 34, 4, 49, 9, 8, 45, 45, 45, 66, 58, 54, 10,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AgeDecade        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  30-39,  30-39,  30-39,  0-9,  40-49,  0-9,  0-9,  4…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AgeMonths        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 409, 409, 409, 49, 596, 115, 101, 541, 541, 541, 795…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Race1            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; White, White, White, Other, White, White, White, Whi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Race3            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Education        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; High School, High School, High School, NA, Some Coll…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ MaritalStatus    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Married, Married, Married, NA, LivePartner, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HHIncome         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; 25000-34999, 25000-34999, 25000-34999, 20000-24999, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HHIncomeMid      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 30000, 30000, 30000, 22500, 40000, 87500, 60000, 875…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Poverty          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 1.36, 1.36, 1.36, 1.07, 1.91, 1.84, 2.33, 5.00, 5.00…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HomeRooms        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 6, 6, 6, 9, 5, 6, 7, 6, 6, 6, 5, 10, 6, 10, 10, 4, 3…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HomeOwn          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Own, Own, Own, Own, Rent, Rent, Own, Own, Own, Own, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Work             &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NotWorking, NotWorking, NotWorking, NA, NotWorking, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Weight           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 87.4, 87.4, 87.4, 17.0, 86.7, 29.8, 35.2, 75.7, 75.7…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Length           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HeadCirc         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Height           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 164.7, 164.7, 164.7, 105.4, 168.4, 133.1, 130.6, 166…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BMI              &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 32.22, 32.22, 32.22, 15.30, 30.57, 16.82, 20.64, 27.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BMICatUnder20yrs &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BMI_WHO          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; 30.0_plus, 30.0_plus, 30.0_plus, 12.0_18.5, 30.0_plu…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Pulse            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 70, 70, 70, NA, 86, 82, 72, 62, 62, 62, 60, 62, 76, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPSysAve         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 113, 113, 113, NA, 112, 86, 107, 118, 118, 118, 111,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPDiaAve         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 85, 85, 85, NA, 75, 47, 37, 64, 64, 64, 63, 74, 85, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPSys1           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 114, 114, 114, NA, 118, 84, 114, 106, 106, 106, 124,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPDia1           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 88, 88, 88, NA, 82, 50, 46, 62, 62, 62, 64, 76, 86, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPSys2           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 114, 114, 114, NA, 108, 84, 108, 118, 118, 118, 108,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPDia2           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 88, 88, 88, NA, 74, 50, 36, 68, 68, 68, 62, 72, 88, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPSys3           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 112, 112, 112, NA, 116, 88, 106, 118, 118, 118, 114,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPDia3           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 82, 82, 82, NA, 76, 44, 38, 60, 60, 60, 64, 76, 82, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Testosterone     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ DirectChol       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 1.29, 1.29, 1.29, NA, 1.16, 1.34, 1.55, 2.12, 2.12, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ TotChol          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 3.49, 3.49, 3.49, NA, 6.70, 4.86, 4.09, 5.82, 5.82, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ UrineVol1        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 352, 352, 352, NA, 77, 123, 238, 106, 106, 106, 113,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ UrineFlow1       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 0.094, 1.538, 1.322, 1.116, 1.116, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ UrineVol2        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ UrineFlow2       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Diabetes         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, No, No, No, No, No, No, No, No, No, No, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ DiabetesAge      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HealthGen        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Good, Good, Good, NA, Good, NA, NA, Vgood, Vgood, Vg…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ DaysPhysHlthBad  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 0, 0, 0, NA, 0, NA, NA, 0, 0, 0, 10, 0, 4, NA, NA, 0…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ DaysMentHlthBad  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 15, 15, 15, NA, 10, NA, NA, 3, 3, 3, 0, 0, 0, NA, NA…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ LittleInterest   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Most, Most, Most, NA, Several, NA, NA, None, None, N…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Depressed        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Several, Several, Several, NA, Several, NA, NA, None…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ nPregnancies     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 2, NA, NA, 1, 1, 1, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ nBabies          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 2, NA, NA, NA, NA, NA, NA, NA, NA, N…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Age1stBaby       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 27, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SleepHrsNight    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 4, 4, 4, NA, 8, NA, NA, 8, 8, 8, 7, 5, 4, NA, 5, 7, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SleepTrouble     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, No, No, No, No, No, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ PhysActive       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, NA, No, NA, NA, Yes, Yes, Yes, Yes, Yes,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ PhysActiveDays   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, 5, 5, 5, 7, 5, 1, NA, 2,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ TVHrsDay         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ CompHrsDay       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ TVHrsDayChild    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, 4, NA, 5, 1, NA, NA, NA, NA, NA, NA, 4, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ CompHrsDayChild  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, 1, NA, 0, 6, NA, NA, NA, NA, NA, NA, 3, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Alcohol12PlusYr  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, Yes, Yes, Yes, Yes, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AlcoholDay       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 2, NA, NA, 3, 3, 3, 1, 2, 6, NA, NA,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AlcoholYear      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 0, 0, 0, NA, 20, NA, NA, 52, 52, 52, 100, 104, 364, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SmokeNow         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, NA, Yes, NA, NA, NA, NA, NA, No, NA, NA,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Smoke100         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, No, No, No, Yes, No,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Smoke100n        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Smoker, Smoker, Smoker, NA, Smoker, NA, NA, Non-Smok…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SmokeAge         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 18, 18, 18, NA, 38, NA, NA, NA, NA, NA, 13, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Marijuana        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, Yes, Yes, Yes, NA, Y…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AgeFirstMarij    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 17, 17, 17, NA, 18, NA, NA, 13, 13, 13, NA, 19, 15, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ RegularMarij     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, NA, No, NA, NA, No, No, No, NA, Yes, Yes…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AgeRegMarij      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 20, 15, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HardDrugs        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, No, No, No, No, Yes,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexEver          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, Yes, Yes, Yes, Yes, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexAge           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 16, 16, 16, NA, 12, NA, NA, 13, 13, 13, 17, 22, 12, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexNumPartnLife  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 8, 8, 8, NA, 10, NA, NA, 20, 20, 20, 15, 7, 100, NA,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexNumPartYear   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 1, 1, 1, NA, 1, NA, NA, 0, 0, 0, NA, 1, 1, NA, NA, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SameSex          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, NA, Yes, NA, NA, Yes, Yes, Yes, No, No, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexOrientation   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Heterosexual, Heterosexual, Heterosexual, NA, Hetero…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ PregnantNow      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To try out merging/joining, we&amp;rsquo;ll create two separate data frames by pulling out some variables from this NHANES dataset. One will contain demographic variables, and the other with have some physical measurements. Then we&amp;rsquo;ll join them back together. Let&amp;rsquo;s create the two sub-datasets first&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#Filter out rows with data from 2009-2010 and Age &amp;gt; 5, &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#select a subset (4) of the variables, then get rid of &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#all duplicate rows. Assign the output to object &#39;dem_data&#39;.&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
            &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;SurveyYr&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;2009_10&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
            &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Age&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
            &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ID&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Gender&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Age&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Education&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
            &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#similar as above, but with a different filter and &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#selecting different variables. Save as &#39;phys_data&#39;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
             &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;SurveyYr&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;2009_10&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
             &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Height&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;180&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
             &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ID&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Height&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;BMI&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Pulse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
             &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now explore them a bit&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#view the first 6 rows of each - note the shared ID column&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      ID Gender   Age Education   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;624 male      34 High School &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;630 female    49 Some College&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;638 male       9 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;646 male       8 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;647 female    45 College Grad&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;654 male      66 Some College&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      ID Height   BMI Pulse&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;624   165.  32.2    70&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;625   105.  15.3    &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;630   168.  30.6    86&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;638   133.  16.8    82&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;646   131.  20.6    72&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;647   167.  27.2    62&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#preview in another way - note the different numbers of observations (rows)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 3,217&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ ID        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 51624, 51630, 51638, 51646, 51647, 51654, 51656, 51657, 516…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Gender    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; male, female, male, male, female, male, male, male, female,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Age       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 34, 49, 9, 8, 45, 66, 58, 54, 10, 58, 50, 9, 33, 60, 16, 56…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Education &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; High School, Some College, NA, NA, College Grad, Some Colle…&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 3,021&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ ID     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 51624, 51625, 51630, 51638, 51646, 51647, 51654, 51657, 51659,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Height &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 164.7, 105.4, 168.4, 133.1, 130.6, 166.7, 169.5, 169.4, 141.8,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BMI    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 32.22, 15.30, 30.57, 16.82, 20.64, 27.24, 23.67, 26.03, 19.20,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Pulse  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 70, NA, 86, 82, 72, 62, 60, 76, 80, 94, 74, 92, 84, 76, 64, 70…&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s use the shared ID column to join the two datasets together. We&amp;rsquo;ll do this in 4 different ways to compare different types of joins: &lt;code&gt;inner_join()&lt;/code&gt;, &lt;code&gt;left_join()&lt;/code&gt;, &lt;code&gt;right_join()&lt;/code&gt;, and &lt;code&gt;full_join()&lt;/code&gt;. &lt;strong&gt;Pay attention to the number of rows in the joined dataset each time and how it relates to the number of rows in each of the two individual datasets&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The basic structure of the dplyr &lt;code&gt;*_join()&lt;/code&gt; functions is&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;*_join(dataframe &#39;x&#39;, dataframe &#39;y&#39;, by = shared column name)&lt;/code&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;1---inner_join&#34;&gt;1 - &lt;code&gt;inner_join()&lt;/code&gt;&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#perform an inner join&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;join_inner&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;inner_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ID&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#preview the new object&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_inner&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      ID Gender   Age Education    Height   BMI Pulse&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;624 male      34 High School    165.  32.2    70&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;630 female    49 Some College   168.  30.6    86&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;638 male       9 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             133.  16.8    82&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;646 male       8 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             131.  20.6    72&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;647 female    45 College Grad   167.  27.2    62&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;654 male      66 Some College   170.  23.7    60&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#get dimensions&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_inner&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2806    7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;2---left_join&#34;&gt;2 - &lt;code&gt;left_join()&lt;/code&gt;&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#perform an left join&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;join_left&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;left_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ID&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#preview the new object&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_left&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      ID Gender   Age Education    Height   BMI Pulse&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;624 male      34 High School    165.  32.2    70&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;630 female    49 Some College   168.  30.6    86&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;638 male       9 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             133.  16.8    82&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;646 male       8 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             131.  20.6    72&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;647 female    45 College Grad   167.  27.2    62&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;654 male      66 Some College   170.  23.7    60&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#get dimensions&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_left&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3217    7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;3---right_join&#34;&gt;3 - &lt;code&gt;right_join()&lt;/code&gt;&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#perform an right join&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;join_right&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;right_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ID&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#preview the new object&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_right&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      ID Gender   Age Education    Height   BMI Pulse&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;624 male      34 High School    165.  32.2    70&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;630 female    49 Some College   168.  30.6    86&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;638 male       9 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             133.  16.8    82&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;646 male       8 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             131.  20.6    72&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;647 female    45 College Grad   167.  27.2    62&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;654 male      66 Some College   170.  23.7    60&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#get dimensions&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_right&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3021    7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;4---full_join&#34;&gt;4 - &lt;code&gt;full_join()&lt;/code&gt;&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#perform an full join&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;join_full&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;full_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ID&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#preview the new object&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_full&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      ID Gender   Age Education    Height   BMI Pulse&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;624 male      34 High School    165.  32.2    70&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;630 female    49 Some College   168.  30.6    86&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;638 male       9 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             133.  16.8    82&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;646 male       8 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             131.  20.6    72&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;647 female    45 College Grad   167.  27.2    62&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;654 male      66 Some College   170.  23.7    60&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#get dimensions&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_full&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3432    7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout rooms&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;re going to add to our backyard birds dataset. I found a dataset that has life history data for a large number of species (birds and others). We&amp;rsquo;ll use species names to merge some of these life history variables in to the occurrence data we already have.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re new and haven&amp;rsquo;t yet gotten the backyard bird dataset, get it first by running the code below. Otherwise, you can skip this step&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# create a directory called data that contains a subdirectory called birds&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;data/birds/&#39;&lt;/span&gt;, recursive &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# set the location of the file&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_file_url&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt;
&lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# set the path for the downloaded file&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#download&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file_url&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now &lt;strong&gt;(everybody)&lt;/strong&gt;, read in the bird data for this session&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Parsed with column specification:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; cols(&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   order = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   family = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   genus = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   locality = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   stateProvince = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLatitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLongitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   eventDate = &lt;span style=&#39;color: #0000BB;&#39;&gt;col_datetime(format = &#34;&#34;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species_en = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   range = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; )&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Reduce the backyard bird dataset and keep just the following columns: &lt;strong&gt;species, locality, stateProvince, eventDate, species_en&lt;/strong&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Use &lt;code&gt;select()&lt;/code&gt; to pull out the columns you want. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;pre&gt;&lt;code&gt;birds &amp;lt;- birds %&amp;gt;% select(species, locality, stateProvince, eventDate, species_en)
&lt;/code&gt;&lt;/pre&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Check to make sure things look right - how many columns does the birds dataset now have?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Use the &lt;code&gt;dim()&lt;/code&gt; function. Or the &lt;code&gt;ncol()&lt;/code&gt; function. Or &lt;code&gt;glimpse()&lt;/code&gt;. Or &lt;code&gt;head()&lt;/code&gt;. Or &lt;code&gt;str()&lt;/code&gt;. Or even &lt;code&gt;summary()&lt;/code&gt;. There&amp;rsquo;s lots of ways to do this. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 311441     5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now download and read in the new life history dataset (tab separated) available at &lt;a href=&#34;https://github.com/biodash/biodash.github.io/raw/master/assets/data/birds/esa_life_history_data_cc.tsv&#34;&gt;https://github.com/biodash/biodash.github.io/raw/master/assets/data/birds/esa_life_history_data_cc.tsv&lt;/a&gt;. Then explore it a bit - how many rows and columns are there?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Use the &lt;code&gt;download.file()&lt;/code&gt; function like we did previously for the bird dataset. You&amp;rsquo;ll need to define the arguments &amp;lsquo;url&amp;rsquo; and &amp;lsquo;destfile&amp;rsquo; inside the parentheses. You can put the file anywhere you want, but I&amp;rsquo;d suggest in the same directory as the bird file we got, so, for example, the destination file could be &amp;ldquo;data/birds/life_history_data.tsv&amp;rdquo;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#download the file from online and save it as a &#39;.tsv&#39; file (since it&#39;s tab delimited)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://github.com/biodash/biodash.github.io/raw/master/assets/data/birds/esa_life_history_data_cc.tsv&#34;&lt;/span&gt;,
destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;data/birds/life_history_data.tsv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#read the data in to R as an object named &#39;life_hist&#39;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;life_hist&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;file &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;data/birds/life_history_data.tsv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Parsed with column specification:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; cols(&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   order = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   family = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   genus = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   common_name = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   female_maturity_d = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   litter_or_clutch_size_n = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   litters_or_clutches_per_y = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   adult_body_mass_g = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   maximum_longevity_y = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   egg_mass_g = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   incubation_d = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   fledging_age_d = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   longevity_y = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   adult_svl_cm = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; )&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#preview the data&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;life_hist&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 21,322&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 16&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ class                     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Av…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ order                     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Accipitriformes&#34;, &#34;Accipitriformes&#34;, &#34;Acci…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ family                    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Accipitridae&#34;, &#34;Accipitridae&#34;, &#34;Accipitrid…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ genus                     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Accipiter&#34;, &#34;Accipiter&#34;, &#34;Accipiter&#34;, &#34;Acc…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species                   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Accipiter albogularis&#34;, &#34;Accipiter badius&#34;…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ common_name               &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Pied Goshawk&#34;, &#34;Shikra&#34;, &#34;Bicolored Hawk&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ female_maturity_d         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 363.468, NA, NA, 363.468, NA, NA, 547.8…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ litter_or_clutch_size_n   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 3.250, 2.700, NA, 4.000, NA, 2.700, 4.2…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ litters_or_clutches_per_y &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 1, NA, NA, 1, NA, NA, 1, NA, 1, NA, 1, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_body_mass_g         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 251.500, 140.000, 345.000, 142.000, 203.500…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ maximum_longevity_y       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, 19.90000, NA, 2…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ egg_mass_g                &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 21.00, 32.00, NA, 21.85, NA, 32.00, 19.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ incubation_d              &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 30.00, NA, NA, 32.50, NA, NA, 33.00, NA…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ fledging_age_d            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 32.00, NA, NA, 42.50, NA, NA, 24.25, NA…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ longevity_y               &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, 12.58333, NA, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_svl_cm              &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 30.00, 39.50, NA, 33.50, NA, 39.50, 29.…&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;This new dataset contains life history data for more than just birds. What Classes of organisms are represented in the &amp;lsquo;Class&amp;rsquo; variable?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Try using a combination of the &lt;code&gt;select()&lt;/code&gt; and &lt;code&gt;distinct()&lt;/code&gt; functions to pull out the column you&amp;rsquo;re interested in, and then to get the distinct values, respectively. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;life_hist&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;class&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 x 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Aves    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Mammalia&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Reptilia&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-5&#34;&gt;Exercise 5&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Reduce the life history dataset down to keep just the rows for Class &lt;strong&gt;Aves&lt;/strong&gt; and the columns &lt;strong&gt;species, adult_body_mass_g, adult_svl_cm, longevity_y, litter_or_clutch_size_n&lt;/strong&gt;. What are the dimensions now?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Use &lt;code&gt;filter()&lt;/code&gt; along with an appropriate logical expression to keep the rows we want. Use &lt;code&gt;select()&lt;/code&gt; to get the desired columns. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# pull out target rows and columns&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;life_hist&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;class&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Aves&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;adult_svl_cm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;litter_or_clutch_size_n&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 9802    5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-6&#34;&gt;Exercise 6&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Preview each dataset again, just to make sure you&amp;rsquo;re clear about what&amp;rsquo;s in each one. Are there any columns that are shared between the two?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Consider &lt;code&gt;glimpse()&lt;/code&gt; or &lt;code&gt;head()&lt;/code&gt; to preview the datasets (tibbles/data frames). If you want to use a function to find shared columns, try a combination of &lt;code&gt;intersect()&lt;/code&gt; and &lt;code&gt;names().&lt;/code&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 311,441&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 12&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ class            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Ave…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ order            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Passeriformes&#34;, &#34;Passeriformes&#34;, &#34;Passeriformes&#34;, &#34;…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ family           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Corvidae&#34;, &#34;Corvidae&#34;, &#34;Corvidae&#34;, &#34;Corvidae&#34;, &#34;Cor…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ genus            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Cyanocitta&#34;, &#34;Cyanocitta&#34;, &#34;Cyanocitta&#34;, &#34;Cyanocitt…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Cyanocitta cristata&#34;, &#34;Cyanocitta cristata&#34;, &#34;Cyano…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ locality         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;44805 Ashland&#34;, &#34;45244 Cincinnati&#34;, &#34;44132 Euclid&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ stateProvince    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ decimalLatitude  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 40.86166, 39.10666, 41.60768, 39.24236, 39.28207, 41…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ decimalLongitude &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; -82.31558, -84.32972, -81.50085, -84.35545, -84.4688…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ eventDate        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;&lt;span&gt; 2007-02-16, 2007-02-17, 2007-02-17, 2007-02-19, 200…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species_en       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blu…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ range            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 9,802&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species                 &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Accipiter albogularis&#34;, &#34;Accipiter badius&#34;, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_body_mass_g       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 251.500, 140.000, 345.000, 142.000, 203.500, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_svl_cm            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 30.00, 39.50, NA, 33.50, NA, 39.50, 29.00…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ longevity_y             &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, 12.58333, NA, 12.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ litter_or_clutch_size_n &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 3.250, 2.700, NA, 4.000, NA, 2.700, 4.250…&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/sets.html&#39;&gt;intersect&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/names.html&#39;&gt;names&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/names.html&#39;&gt;names&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;species&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-7&#34;&gt;Exercise 7&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now lets join them together based on their shared variable. Not all species in the backyard bird (Ohio) dataset are included in the life history dataset. Likewise, there are life history data for many species that aren&amp;rsquo;t in the Ohio dataset. We want to keep all the Ohio observations, and merge in life history data for species where it&amp;rsquo;s availble, but we also don&amp;rsquo;t want to add in life history data for species that aren&amp;rsquo;t in the Ohio dataset. Choose an appropriate join function with those things in mind.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Try a &lt;code&gt;left_join()&lt;/code&gt;, defining the Ohio backyard bird dataset as the &amp;lsquo;x&amp;rsquo; dataset in the join and the life history data as the &amp;lsquo;y&amp;rsquo; dataset. Get details on that function with &lt;code&gt;?left_join&lt;/code&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;left_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-8&#34;&gt;Exercise 8&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;What are the longest- and shortest-living bird species in Ohio based on the data in the longevity_y column?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Try using &lt;code&gt;select()&lt;/code&gt; to pull out just the columns species and longevity_y, then use &lt;code&gt;distinct()&lt;/code&gt; to get the unique rows, then &lt;code&gt;arrange()&lt;/code&gt; based on the longevity_y column. You might also find the dplyr function &lt;code&gt;desc()&lt;/code&gt; helpful.&lt;/p&gt;
&lt;p&gt;Alternatively, you could try grouping by species, then use &lt;code&gt;summarise()&lt;/code&gt; to get either the max, min, or mean value for longevity_y for each species (there&amp;rsquo;s just one value for each species, so all of those statistics give the same value in this case). Then sort (arrange) the resulting summarized data frame on the longevity value.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#option 1 - shortest-lived birds&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 171 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species              longevity_y&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                      &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Loxia leucoptera            4   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Spiza americana             4   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Certhia americana           4.6 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Acanthis hornemanni         4.6 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Tringa flavipes             4.75&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Podiceps grisegena          4.8 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Calcarius lapponicus        5   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Anthus rubescens            5.1 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Perdix perdix               5.17&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Regulus satrapa             5.32&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 161 more rows&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#option 1 - longest-lived birds&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;desc&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 171 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species                  longevity_y&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                          &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Larus argentatus                33.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Larus glaucoides                33  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Larus thayeri                   33  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Haliaeetus leucocephalus        33.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Larus fuscus                    32.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Aquila chrysaetos               32  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Anas platyrhynchos              29  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Larus delawarensis              28.6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Asio otus                       27.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Cygnus olor                     27.7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 161 more rows&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#option 2 - shortest-lived birds&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;summarise&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;longevity &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;longevity&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 171 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species              longevity&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                    &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Loxia leucoptera          4   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Spiza americana           4   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Acanthis hornemanni       4.6 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Certhia americana         4.6 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Tringa flavipes           4.75&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Podiceps grisegena        4.8 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Calcarius lapponicus      5   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Anthus rubescens          5.1 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Perdix perdix             5.17&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Regulus satrapa           5.32&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 161 more rows&lt;/span&gt;&lt;/span&gt;

    
&lt;span class=&#39;c&#39;&gt;#option 2 - longest-lived birds&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;summarise&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;longevity &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;desc&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;longevity&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 171 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species                  longevity&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                        &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Larus argentatus              33.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Larus glaucoides              33  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Larus thayeri                 33  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Haliaeetus leucocephalus      33.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Larus fuscus                  32.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Aquila chrysaetos             32  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Anas platyrhynchos            29  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Larus delawarensis            28.6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Asio otus                     27.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Cygnus olor                   27.7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 161 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;bonus-time&#34;&gt;Bonus time!&lt;/h2&gt;
&lt;h3 id=&#34;bonus-1&#34;&gt;Bonus 1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;What species in Ohio has the largest ratio of adult body mass to length (measured as snout vent length, or &amp;lsquo;adult_svl_cm&amp;rsquo;)?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Use &lt;code&gt;mutate()&lt;/code&gt; to create a new variable containing the body mass divided by svl, then arrange the dataset using that new variable to get the species with the highest value.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;ratio &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;/&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;adult_svl_cm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;ratio&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;desc&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ratio&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 170 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species_en     ratio&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Mute Swan       71.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Wild Turkey     68.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Trumpeter Swan  64.9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Bald Eagle      59.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Golden Eagle    56.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Canada Goose    48.3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Tundra Swan     47.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Cackling Goose  44.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Snow Goose      35.1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Snowy Owl       32.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 160 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-2&#34;&gt;Bonus 2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;There are 2 additional joins we haven&amp;rsquo;t talked about - semi_join() and anti_join(). Take a look at the documentation to see what these do. Use one of them to find what species in the backyard birds dataset are not in the life history dataset.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Use &lt;code&gt;anti_join()&lt;/code&gt; and &lt;code&gt;distinct()&lt;/code&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;anti_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
                                                     &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species                       species_en           &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Dendrocopos pubescens         Downy Woodpecker     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Spizelloides arborea          American Tree Sparrow&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Otus asio                     Eastern Screech Owl  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Larus minutus                 Little Gull          &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Anas rubripes x platyrhynchos &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                            &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-3&#34;&gt;Bonus 3&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;The life history dataset we downloaded above is actually a modified version of the original file, which is located at &amp;lsquo;&lt;a href=&#34;http://www.esapubs.org/archive/ecol/E096/269/Data_Files/Amniote_Database_Aug_2015.csv&#34;&gt;http://www.esapubs.org/archive/ecol/E096/269/Data_Files/Amniote_Database_Aug_2015.csv&lt;/a&gt;&amp;rsquo;&lt;/p&gt;
&lt;p&gt;Try starting with the original file and repeating what we did above - merging the variables &lt;strong&gt;species, adult_body_mass_g, adult_svl_cm, longevity_y, litter_or_clutch_size_n&lt;/strong&gt; in to the original birds dataset. First, make sure to get it read in correctly. Then pay attention to the species column in the life history dataset - what needs to be done before a join/merge can be performed?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Pay attention to how missing data are coded in this dataset (it&amp;rsquo;s -999). Also, data are very sparse for some of the variables - in other words, they have lots of missing data. This seems to cause a problem with the &lt;code&gt;read_csv()&lt;/code&gt; function, as it only considers the first 1000 rows for the purpose of defining the class of each column. This can be a problem if all of the first 1000 rows are missing. Finally, it appears that even though this is a comma separated file (commas define the column breaks), there are a few instances where commas are used within a field. This happens in the &amp;lsquo;common name&amp;rsquo; column in a few cases where multiple common names are listed for a specific observation. This is one example of something that can become quite frustrating when trying to get data loaded in, and is worth keeping an eye out for. Fortunately, in our case, it only seems to happen for non-bird species in this dataset, which we filter out anyway, so it can be dealt with. However, if it had impacted any of the bird observations, I think fixing this might require a solution outside of R - possibly a command line approach.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#download&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;http://www.esapubs.org/archive/ecol/E096/269/Data_Files/Amniote_Database_Aug_2015.csv&#34;&lt;/span&gt;, 
destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;data/birds/orig_life_history.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#read the data in to R as an object named &#39;full_life_hist&#39;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;full_life_hist&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_csv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;data/birds/orig_life_history.csv&#34;&lt;/span&gt;, 
                  na &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;-999&#34;&lt;/span&gt;, 
                  col_types &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;cols&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;birth_or_hatching_svl_cm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                  weaning_d &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,gestation_d &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
                  weaning_weight_g &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
                  male_svl_cm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
                  female_svl_cm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                  no_sex_svl_cm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
                  female_body_mass_at_maturity_g &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                  female_svl_at_maturity_cm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#get the original version of the birds dataset&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Parsed with column specification:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; cols(&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   order = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   family = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   genus = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   locality = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   stateProvince = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLatitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLongitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   eventDate = &lt;span style=&#39;color: #0000BB;&#39;&gt;col_datetime(format = &#34;&#34;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species_en = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   range = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; )&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#subset each for the columns and rows we want&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;full_life_hist&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;class&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Aves&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;adult_svl_cm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;litter_or_clutch_size_n&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;locality&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;stateProvince&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;eventDate&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 311,441&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Cyanocitta cristata&#34;, &#34;Cyanocitta cristata&#34;, &#34;Cyanocit…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ locality      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;44805 Ashland&#34;, &#34;45244 Cincinnati&#34;, &#34;44132 Euclid&#34;, &#34;4…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ stateProvince &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ eventDate     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;&lt;span&gt; 2007-02-16, 2007-02-17, 2007-02-17, 2007-02-19, 2007-0…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species_en    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue J…&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 9,802&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species                 &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;albogularis&#34;, &#34;badius&#34;, &#34;bicolor&#34;, &#34;brachyur…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_body_mass_g       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 251.500, 140.000, 345.000, 142.000, 203.500, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_svl_cm            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 30.00, 39.50, NA, 33.50, NA, 39.50, 29.00…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ longevity_y             &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, 12.58333, NA, 12.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ litter_or_clutch_size_n &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 3.250, 2.700, NA, 4.000, NA, 2.700, 4.250…&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#notice the species column in the life history data doesn&#39;t include the genus name. Since the names don&#39;t match in the species column from each dataset, a join won&#39;t work. Add the genus variable in from the original life history data...&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;full_life_hist&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;class&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Aves&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;genus&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;adult_svl_cm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;litter_or_clutch_size_n&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#now use mutate to replace the species column so it includes both the genus and species...&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;species &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/paste.html&#39;&gt;paste0&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;genus&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34; &#34;&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;genus&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#preview again&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 311,441&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Cyanocitta cristata&#34;, &#34;Cyanocitta cristata&#34;, &#34;Cyanocit…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ locality      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;44805 Ashland&#34;, &#34;45244 Cincinnati&#34;, &#34;44132 Euclid&#34;, &#34;4…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ stateProvince &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ eventDate     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;&lt;span&gt; 2007-02-16, 2007-02-17, 2007-02-17, 2007-02-19, 2007-0…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species_en    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue J…&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 9,802&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species                 &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Accipiter albogularis&#34;, &#34;Accipiter badius&#34;, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_body_mass_g       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 251.500, 140.000, 345.000, 142.000, 203.500, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_svl_cm            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 30.00, 39.50, NA, 33.50, NA, 39.50, 29.00…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ longevity_y             &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, 12.58333, NA, 12.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ litter_or_clutch_size_n &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 3.250, 2.700, NA, 4.000, NA, 2.700, 4.250…&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#now we can join&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;left_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Session 3: Joining Datasets</title>
      <link>https://biodash.github.io/codeclub/s03_joining-datasets/</link>
      <pubDate>Fri, 04 Dec 2020 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/s03_joining-datasets/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;new-to-code-club&#34;&gt;New To Code Club?&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;First, check out the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has some pointers that might be helpful if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Please open RStudio before Code Club to test things out &amp;ndash; if you run into issues, join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;session-goals&#34;&gt;Session Goals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Differentiate between different types of joins&amp;hellip;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;inner_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;full_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;left_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;right_join()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Use a join function to add new variables to the birds dataset&lt;/li&gt;
&lt;li&gt;Keep practicing with dplyr core verbs from last week, esp&amp;hellip;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;Answer the question &amp;ldquo;What Ohio bird species have the longest and shortest average lifespans?&amp;rdquo;.&lt;/li&gt;
&lt;/ul&gt;
&lt;hr&gt;
&lt;h2 id=&#34;intro-mergingjoining-datasets&#34;&gt;Intro: Merging/Joining Datasets&lt;/h2&gt;
&lt;p&gt;Sometimes you don&amp;rsquo;t have all your data in the same place. For example, maybe you have multiple Excel sheets for a project - each storing a different type of data for the same set of samples. Or maybe you&amp;rsquo;re interested in analyzing various metrics for US states and are getting the data from different places online - economic data from one database, climate data from another, and so on. As part of the process of data wrangling, it&amp;rsquo;s often useful to merge the separate datasets together according to a variable they share, possibly &amp;ldquo;SampleID&amp;rdquo; or &amp;ldquo;State Name&amp;rdquo; for the two above examples, respectively. R offers several ways to do this, but we&amp;rsquo;ll focus here on the set of &lt;code&gt;*_join()&lt;/code&gt; functions available in &lt;em&gt;dplyr&lt;/em&gt;. They include&amp;hellip;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;inner_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;full_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;left_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;right_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;semi_join()&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;anti_join()&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Check out the &amp;lsquo;Combine Data Sets&amp;rsquo; section of this &lt;a href=&#34;https://rstudio.com/wp-content/uploads/2015/02/data-wrangling-cheatsheet.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;cheat sheet&lt;/a&gt; for a brief look at these functions.&lt;/p&gt;
&lt;p&gt;You can also get more details &lt;a href=&#34;https://dplyr.tidyverse.org/reference/join.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;, or, as with any R function, by accessing the function&amp;rsquo;s documentation inside R with the &amp;lsquo;?&amp;rsquo;. For example, type &lt;code&gt;?inner_join&lt;/code&gt; at your R prompt and hit Enter. (Make sure the package the function comes from is loaded first! In this case, you need &lt;em&gt;dplyr&lt;/em&gt;, which is loaded as part of &lt;em&gt;tidyverse&lt;/em&gt;.)&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;Below we&amp;rsquo;ll go through a few examples of joins. You&amp;rsquo;re welcome to follow along and run this code on your own, &lt;strong&gt;but it&amp;rsquo;s not necessary&lt;/strong&gt; - the exercises in the breakout rooms are independent of these examples and will give you a chance to try these things out on your own.&lt;/p&gt;
&lt;p&gt;If you want to follow along, you can find the code &lt;a href=&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/scripts/birds/S03_Examples_Code.R&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;p&gt;Since the &lt;code&gt;*_join()&lt;/code&gt; functions come from the &lt;em&gt;dplyr&lt;/em&gt; package, which is part of &lt;em&gt;tidyverse&lt;/em&gt;, I&amp;rsquo;ll load that first&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#this assumes you&#39;ve already installed tidyverse&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;The National Health and Nutrition Examination Survey &lt;a href=&#34;https://www.rdocumentation.org/packages/NHANES/versions/2.1.0/topics/NHANES&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;(NHANES) dataset&lt;/a&gt; contains survey data obtained annually from ~5,000 individuals on a variety of health and lifestyle-related metrics. A subset of the data are available as an R package - install and load it&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/install.packages.html&#39;&gt;install.packages&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;NHANES&#34;&lt;/span&gt;, repos &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;http://cran.us.r-project.org&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; The downloaded binary packages are in&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   /var/folders/s7/y_mgh3c54h9fjcyw9wqdkb8x4zs_jy/T//RtmpdHHxzY/downloaded_packages&lt;/span&gt;

&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now preview the dataset&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 10,000&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 76&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ ID               &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 51624, 51624, 51624, 51625, 51630, 51638, 51646, 516…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SurveyYr         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; 2009_10, 2009_10, 2009_10, 2009_10, 2009_10, 2009_10…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Gender           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; male, male, male, male, female, male, male, female, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Age              &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 34, 34, 34, 4, 49, 9, 8, 45, 45, 45, 66, 58, 54, 10,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AgeDecade        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  30-39,  30-39,  30-39,  0-9,  40-49,  0-9,  0-9,  4…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AgeMonths        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 409, 409, 409, 49, 596, 115, 101, 541, 541, 541, 795…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Race1            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; White, White, White, Other, White, White, White, Whi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Race3            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Education        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; High School, High School, High School, NA, Some Coll…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ MaritalStatus    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Married, Married, Married, NA, LivePartner, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HHIncome         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; 25000-34999, 25000-34999, 25000-34999, 20000-24999, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HHIncomeMid      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 30000, 30000, 30000, 22500, 40000, 87500, 60000, 875…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Poverty          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 1.36, 1.36, 1.36, 1.07, 1.91, 1.84, 2.33, 5.00, 5.00…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HomeRooms        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 6, 6, 6, 9, 5, 6, 7, 6, 6, 6, 5, 10, 6, 10, 10, 4, 3…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HomeOwn          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Own, Own, Own, Own, Rent, Rent, Own, Own, Own, Own, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Work             &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NotWorking, NotWorking, NotWorking, NA, NotWorking, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Weight           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 87.4, 87.4, 87.4, 17.0, 86.7, 29.8, 35.2, 75.7, 75.7…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Length           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HeadCirc         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Height           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 164.7, 164.7, 164.7, 105.4, 168.4, 133.1, 130.6, 166…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BMI              &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 32.22, 32.22, 32.22, 15.30, 30.57, 16.82, 20.64, 27.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BMICatUnder20yrs &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BMI_WHO          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; 30.0_plus, 30.0_plus, 30.0_plus, 12.0_18.5, 30.0_plu…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Pulse            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 70, 70, 70, NA, 86, 82, 72, 62, 62, 62, 60, 62, 76, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPSysAve         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 113, 113, 113, NA, 112, 86, 107, 118, 118, 118, 111,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPDiaAve         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 85, 85, 85, NA, 75, 47, 37, 64, 64, 64, 63, 74, 85, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPSys1           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 114, 114, 114, NA, 118, 84, 114, 106, 106, 106, 124,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPDia1           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 88, 88, 88, NA, 82, 50, 46, 62, 62, 62, 64, 76, 86, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPSys2           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 114, 114, 114, NA, 108, 84, 108, 118, 118, 118, 108,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPDia2           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 88, 88, 88, NA, 74, 50, 36, 68, 68, 68, 62, 72, 88, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPSys3           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 112, 112, 112, NA, 116, 88, 106, 118, 118, 118, 114,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BPDia3           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 82, 82, 82, NA, 76, 44, 38, 60, 60, 60, 64, 76, 82, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Testosterone     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ DirectChol       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 1.29, 1.29, 1.29, NA, 1.16, 1.34, 1.55, 2.12, 2.12, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ TotChol          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 3.49, 3.49, 3.49, NA, 6.70, 4.86, 4.09, 5.82, 5.82, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ UrineVol1        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 352, 352, 352, NA, 77, 123, 238, 106, 106, 106, 113,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ UrineFlow1       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 0.094, 1.538, 1.322, 1.116, 1.116, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ UrineVol2        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ UrineFlow2       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Diabetes         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, No, No, No, No, No, No, No, No, No, No, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ DiabetesAge      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HealthGen        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Good, Good, Good, NA, Good, NA, NA, Vgood, Vgood, Vg…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ DaysPhysHlthBad  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 0, 0, 0, NA, 0, NA, NA, 0, 0, 0, 10, 0, 4, NA, NA, 0…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ DaysMentHlthBad  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 15, 15, 15, NA, 10, NA, NA, 3, 3, 3, 0, 0, 0, NA, NA…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ LittleInterest   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Most, Most, Most, NA, Several, NA, NA, None, None, N…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Depressed        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Several, Several, Several, NA, Several, NA, NA, None…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ nPregnancies     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 2, NA, NA, 1, 1, 1, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ nBabies          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 2, NA, NA, NA, NA, NA, NA, NA, NA, N…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Age1stBaby       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 27, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SleepHrsNight    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 4, 4, 4, NA, 8, NA, NA, 8, 8, 8, 7, 5, 4, NA, 5, 7, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SleepTrouble     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, No, No, No, No, No, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ PhysActive       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, NA, No, NA, NA, Yes, Yes, Yes, Yes, Yes,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ PhysActiveDays   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, 5, 5, 5, 7, 5, 1, NA, 2,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ TVHrsDay         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ CompHrsDay       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ TVHrsDayChild    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, 4, NA, 5, 1, NA, NA, NA, NA, NA, NA, 4, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ CompHrsDayChild  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, 1, NA, 0, 6, NA, NA, NA, NA, NA, NA, 3, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Alcohol12PlusYr  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, Yes, Yes, Yes, Yes, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AlcoholDay       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, 2, NA, NA, 3, 3, 3, 1, 2, 6, NA, NA,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AlcoholYear      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 0, 0, 0, NA, 20, NA, NA, 52, 52, 52, 100, 104, 364, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SmokeNow         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, NA, Yes, NA, NA, NA, NA, NA, No, NA, NA,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Smoke100         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, No, No, No, Yes, No,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Smoke100n        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Smoker, Smoker, Smoker, NA, Smoker, NA, NA, Non-Smok…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SmokeAge         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 18, 18, 18, NA, 38, NA, NA, NA, NA, NA, 13, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Marijuana        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, Yes, Yes, Yes, NA, Y…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AgeFirstMarij    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 17, 17, 17, NA, 18, NA, NA, 13, 13, 13, NA, 19, 15, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ RegularMarij     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, NA, No, NA, NA, No, No, No, NA, Yes, Yes…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ AgeRegMarij      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, 20, 15, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ HardDrugs        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, No, No, No, No, Yes,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexEver          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Yes, Yes, Yes, NA, Yes, NA, NA, Yes, Yes, Yes, Yes, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexAge           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 16, 16, 16, NA, 12, NA, NA, 13, 13, 13, 17, 22, 12, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexNumPartnLife  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 8, 8, 8, NA, 10, NA, NA, 20, 20, 20, 15, 7, 100, NA,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexNumPartYear   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 1, 1, 1, NA, 1, NA, NA, 0, 0, 0, NA, 1, 1, NA, NA, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SameSex          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; No, No, No, NA, Yes, NA, NA, Yes, Yes, Yes, No, No, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ SexOrientation   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; Heterosexual, Heterosexual, Heterosexual, NA, Hetero…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ PregnantNow      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;To try out merging/joining, we&amp;rsquo;ll create two separate data frames by pulling out some variables from this NHANES dataset. One will contain demographic variables, and the other with have some physical measurements. Then we&amp;rsquo;ll join them back together. Let&amp;rsquo;s create the two sub-datasets first&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#Filter out rows with data from 2009-2010 and Age &amp;gt; 5, &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#select a subset (4) of the variables, then get rid of &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#all duplicate rows. Assign the output to object &#39;dem_data&#39;.&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
            &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;SurveyYr&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;2009_10&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
            &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Age&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
            &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ID&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Gender&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Age&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Education&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
            &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#similar as above, but with a different filter and &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#selecting different variables. Save as &#39;phys_data&#39;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;NHANES&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
             &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;SurveyYr&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;2009_10&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
             &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Height&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;180&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;  &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
             &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ID&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Height&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;BMI&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Pulse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
             &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now explore them a bit&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#view the first 6 rows of each - note the shared ID column&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      ID Gender   Age Education   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;624 male      34 High School &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;630 female    49 Some College&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;638 male       9 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;646 male       8 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;647 female    45 College Grad&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;654 male      66 Some College&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      ID Height   BMI Pulse&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;624   165.  32.2    70&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;625   105.  15.3    &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;630   168.  30.6    86&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;638   133.  16.8    82&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;646   131.  20.6    72&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;647   167.  27.2    62&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#preview in another way - note the different numbers of observations (rows)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 3,217&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ ID        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 51624, 51630, 51638, 51646, 51647, 51654, 51656, 51657, 516…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Gender    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; male, female, male, male, female, male, male, male, female,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Age       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 34, 49, 9, 8, 45, 66, 58, 54, 10, 58, 50, 9, 33, 60, 16, 56…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Education &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; High School, Some College, NA, NA, College Grad, Some Colle…&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 3,021&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 4&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ ID     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 51624, 51625, 51630, 51638, 51646, 51647, 51654, 51657, 51659,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Height &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 164.7, 105.4, 168.4, 133.1, 130.6, 166.7, 169.5, 169.4, 141.8,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ BMI    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 32.22, 15.30, 30.57, 16.82, 20.64, 27.24, 23.67, 26.03, 19.20,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Pulse  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; 70, NA, 86, 82, 72, 62, 60, 76, 80, 94, 74, 92, 84, 76, 64, 70…&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s use the shared ID column to join the two datasets together. We&amp;rsquo;ll do this in 4 different ways to compare different types of joins: &lt;code&gt;inner_join()&lt;/code&gt;, &lt;code&gt;left_join()&lt;/code&gt;, &lt;code&gt;right_join()&lt;/code&gt;, and &lt;code&gt;full_join()&lt;/code&gt;. &lt;strong&gt;Pay attention to the number of rows in the joined dataset each time and how it relates to the number of rows in each of the two individual datasets&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;The basic structure of the dplyr &lt;code&gt;*_join()&lt;/code&gt; functions is&amp;hellip;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;*_join(dataframe &#39;x&#39;, dataframe &#39;y&#39;, by = shared column name)&lt;/code&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;1---inner_join&#34;&gt;1 - &lt;code&gt;inner_join()&lt;/code&gt;&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#perform an inner join&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;join_inner&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;inner_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ID&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#preview the new object&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_inner&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      ID Gender   Age Education    Height   BMI Pulse&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;624 male      34 High School    165.  32.2    70&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;630 female    49 Some College   168.  30.6    86&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;638 male       9 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             133.  16.8    82&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;646 male       8 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             131.  20.6    72&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;647 female    45 College Grad   167.  27.2    62&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;654 male      66 Some College   170.  23.7    60&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#get dimensions&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_inner&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 2806    7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;2---left_join&#34;&gt;2 - &lt;code&gt;left_join()&lt;/code&gt;&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#perform an left join&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;join_left&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;left_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ID&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#preview the new object&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_left&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      ID Gender   Age Education    Height   BMI Pulse&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;624 male      34 High School    165.  32.2    70&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;630 female    49 Some College   168.  30.6    86&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;638 male       9 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             133.  16.8    82&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;646 male       8 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             131.  20.6    72&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;647 female    45 College Grad   167.  27.2    62&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;654 male      66 Some College   170.  23.7    60&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#get dimensions&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_left&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3217    7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;3---right_join&#34;&gt;3 - &lt;code&gt;right_join()&lt;/code&gt;&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#perform an right join&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;join_right&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;right_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ID&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#preview the new object&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_right&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      ID Gender   Age Education    Height   BMI Pulse&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;624 male      34 High School    165.  32.2    70&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;630 female    49 Some College   168.  30.6    86&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;638 male       9 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             133.  16.8    82&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;646 male       8 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             131.  20.6    72&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;647 female    45 College Grad   167.  27.2    62&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;654 male      66 Some College   170.  23.7    60&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#get dimensions&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_right&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3021    7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;4---full_join&#34;&gt;4 - &lt;code&gt;full_join()&lt;/code&gt;&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#perform an full join&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;join_full&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;full_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;dem_data&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;phys_data&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;ID&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#preview the new object&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_full&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;      ID Gender   Age Education    Height   BMI Pulse&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;624 male      34 High School    165.  32.2    70&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;630 female    49 Some College   168.  30.6    86&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;638 male       9 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             133.  16.8    82&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;646 male       8 &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;             131.  20.6    72&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;647 female    45 College Grad   167.  27.2    62&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;51&lt;/span&gt;&lt;span&gt;654 male      66 Some College   170.  23.7    60&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#get dimensions&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;join_full&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 3432    7&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;breakout-rooms&#34;&gt;Breakout rooms&lt;/h2&gt;
&lt;p&gt;We&amp;rsquo;re going to add to our backyard birds dataset. I found a dataset that has life history data for a large number of species (birds and others). We&amp;rsquo;ll use species names to merge some of these life history variables in to the occurrence data we already have.&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re new and haven&amp;rsquo;t yet gotten the backyard bird dataset, get it first by running the code below. Otherwise, you can skip this step&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# create a directory called data that contains a subdirectory called birds&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;data/birds/&#39;&lt;/span&gt;, recursive &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# set the location of the file&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_file_url&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt;
&lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# set the path for the downloaded file&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#download&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file_url&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Now &lt;strong&gt;(everybody)&lt;/strong&gt;, read in the bird data for this session&amp;hellip;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Parsed with column specification:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; cols(&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   order = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   family = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   genus = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   locality = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   stateProvince = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLatitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLongitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   eventDate = &lt;span style=&#39;color: #0000BB;&#39;&gt;col_datetime(format = &#34;&#34;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species_en = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   range = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; )&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Reduce the backyard bird dataset and keep just the following columns: &lt;strong&gt;species, locality, stateProvince, eventDate, species_en&lt;/strong&gt;&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Use &lt;code&gt;select()&lt;/code&gt; to pull out the columns you want. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;pre&gt;&lt;code&gt;birds &amp;lt;- birds %&amp;gt;% select(species, locality, stateProvince, eventDate, species_en)
&lt;/code&gt;&lt;/pre&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Check to make sure things look right - how many columns does the birds dataset now have?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Use the &lt;code&gt;dim()&lt;/code&gt; function. Or the &lt;code&gt;ncol()&lt;/code&gt; function. Or &lt;code&gt;glimpse()&lt;/code&gt;. Or &lt;code&gt;head()&lt;/code&gt;. Or &lt;code&gt;str()&lt;/code&gt;. Or even &lt;code&gt;summary()&lt;/code&gt;. There&amp;rsquo;s lots of ways to do this. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 311441     5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now download and read in the new life history dataset (tab separated) available at &lt;a href=&#34;https://github.com/biodash/biodash.github.io/raw/master/assets/data/birds/esa_life_history_data_cc.tsv&#34;&gt;https://github.com/biodash/biodash.github.io/raw/master/assets/data/birds/esa_life_history_data_cc.tsv&lt;/a&gt;. Then explore it a bit - how many rows and columns are there?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Use the &lt;code&gt;download.file()&lt;/code&gt; function like we did previously for the bird dataset. You&amp;rsquo;ll need to define the arguments &amp;lsquo;url&amp;rsquo; and &amp;lsquo;destfile&amp;rsquo; inside the parentheses. You can put the file anywhere you want, but I&amp;rsquo;d suggest in the same directory as the bird file we got, so, for example, the destination file could be &amp;ldquo;data/birds/life_history_data.tsv&amp;rdquo;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#download the file from online and save it as a &#39;.tsv&#39; file (since it&#39;s tab delimited)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://github.com/biodash/biodash.github.io/raw/master/assets/data/birds/esa_life_history_data_cc.tsv&#34;&lt;/span&gt;,
destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;data/birds/life_history_data.tsv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#read the data in to R as an object named &#39;life_hist&#39;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;life_hist&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;file &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;data/birds/life_history_data.tsv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Parsed with column specification:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; cols(&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   order = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   family = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   genus = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   common_name = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   female_maturity_d = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   litter_or_clutch_size_n = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   litters_or_clutches_per_y = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   adult_body_mass_g = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   maximum_longevity_y = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   egg_mass_g = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   incubation_d = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   fledging_age_d = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   longevity_y = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   adult_svl_cm = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; )&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#preview the data&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;life_hist&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 21,322&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 16&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ class                     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Av…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ order                     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Accipitriformes&#34;, &#34;Accipitriformes&#34;, &#34;Acci…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ family                    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Accipitridae&#34;, &#34;Accipitridae&#34;, &#34;Accipitrid…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ genus                     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Accipiter&#34;, &#34;Accipiter&#34;, &#34;Accipiter&#34;, &#34;Acc…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species                   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Accipiter albogularis&#34;, &#34;Accipiter badius&#34;…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ common_name               &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Pied Goshawk&#34;, &#34;Shikra&#34;, &#34;Bicolored Hawk&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ female_maturity_d         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 363.468, NA, NA, 363.468, NA, NA, 547.8…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ litter_or_clutch_size_n   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 3.250, 2.700, NA, 4.000, NA, 2.700, 4.2…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ litters_or_clutches_per_y &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 1, NA, NA, 1, NA, NA, 1, NA, 1, NA, 1, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_body_mass_g         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 251.500, 140.000, 345.000, 142.000, 203.500…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ maximum_longevity_y       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, 19.90000, NA, 2…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ egg_mass_g                &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 21.00, 32.00, NA, 21.85, NA, 32.00, 19.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ incubation_d              &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 30.00, NA, NA, 32.50, NA, NA, 33.00, NA…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ fledging_age_d            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 32.00, NA, NA, 42.50, NA, NA, 24.25, NA…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ longevity_y               &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, 12.58333, NA, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_svl_cm              &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 30.00, 39.50, NA, 33.50, NA, 39.50, 29.…&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;This new dataset contains life history data for more than just birds. What Classes of organisms are represented in the &amp;lsquo;Class&amp;rsquo; variable?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Try using a combination of the &lt;code&gt;select()&lt;/code&gt; and &lt;code&gt;distinct()&lt;/code&gt; functions to pull out the column you&amp;rsquo;re interested in, and then to get the distinct values, respectively. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;life_hist&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;class&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 x 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class   &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Aves    &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Mammalia&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Reptilia&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-5&#34;&gt;Exercise 5&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Reduce the life history dataset down to keep just the rows for Class &lt;strong&gt;Aves&lt;/strong&gt; and the columns &lt;strong&gt;species, adult_body_mass_g, adult_svl_cm, longevity_y, litter_or_clutch_size_n&lt;/strong&gt;. What are the dimensions now?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Use &lt;code&gt;filter()&lt;/code&gt; along with an appropriate logical expression to keep the rows we want. Use &lt;code&gt;select()&lt;/code&gt; to get the desired columns. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# pull out target rows and columns&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;life_hist&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;class&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Aves&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;adult_svl_cm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;litter_or_clutch_size_n&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 9802    5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-6&#34;&gt;Exercise 6&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Preview each dataset again, just to make sure you&amp;rsquo;re clear about what&amp;rsquo;s in each one. Are there any columns that are shared between the two?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Consider &lt;code&gt;glimpse()&lt;/code&gt; or &lt;code&gt;head()&lt;/code&gt; to preview the datasets (tibbles/data frames). If you want to use a function to find shared columns, try a combination of &lt;code&gt;intersect()&lt;/code&gt; and &lt;code&gt;names().&lt;/code&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 311,441&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 12&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ class            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Ave…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ order            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Passeriformes&#34;, &#34;Passeriformes&#34;, &#34;Passeriformes&#34;, &#34;…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ family           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Corvidae&#34;, &#34;Corvidae&#34;, &#34;Corvidae&#34;, &#34;Corvidae&#34;, &#34;Cor…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ genus            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Cyanocitta&#34;, &#34;Cyanocitta&#34;, &#34;Cyanocitta&#34;, &#34;Cyanocitt…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Cyanocitta cristata&#34;, &#34;Cyanocitta cristata&#34;, &#34;Cyano…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ locality         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;44805 Ashland&#34;, &#34;45244 Cincinnati&#34;, &#34;44132 Euclid&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ stateProvince    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ decimalLatitude  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 40.86166, 39.10666, 41.60768, 39.24236, 39.28207, 41…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ decimalLongitude &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; -82.31558, -84.32972, -81.50085, -84.35545, -84.4688…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ eventDate        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;&lt;span&gt; 2007-02-16, 2007-02-17, 2007-02-17, 2007-02-19, 200…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species_en       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blu…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ range            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 9,802&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species                 &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Accipiter albogularis&#34;, &#34;Accipiter badius&#34;, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_body_mass_g       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 251.500, 140.000, 345.000, 142.000, 203.500, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_svl_cm            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 30.00, 39.50, NA, 33.50, NA, 39.50, 29.00…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ longevity_y             &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, 12.58333, NA, 12.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ litter_or_clutch_size_n &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 3.250, 2.700, NA, 4.000, NA, 2.700, 4.250…&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/sets.html&#39;&gt;intersect&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/names.html&#39;&gt;names&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/names.html&#39;&gt;names&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] &#34;species&#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-7&#34;&gt;Exercise 7&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Now lets join them together based on their shared variable. Not all species in the backyard bird (Ohio) dataset are included in the life history dataset. Likewise, there are life history data for many species that aren&amp;rsquo;t in the Ohio dataset. We want to keep all the Ohio observations, and merge in life history data for species where it&amp;rsquo;s availble, but we also don&amp;rsquo;t want to add in life history data for species that aren&amp;rsquo;t in the Ohio dataset. Choose an appropriate join function with those things in mind.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Try a &lt;code&gt;left_join()&lt;/code&gt;, defining the Ohio backyard bird dataset as the &amp;lsquo;x&amp;rsquo; dataset in the join and the life history data as the &amp;lsquo;y&amp;rsquo; dataset. Get details on that function with &lt;code&gt;?left_join&lt;/code&gt;. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;left_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;x &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;, y &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-8&#34;&gt;Exercise 8&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;What are the longest- and shortest-living bird species in Ohio based on the data in the longevity_y column?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Try using &lt;code&gt;select()&lt;/code&gt; to pull out just the columns species and longevity_y, then use &lt;code&gt;distinct()&lt;/code&gt; to get the unique rows, then &lt;code&gt;arrange()&lt;/code&gt; based on the longevity_y column. You might also find the dplyr function &lt;code&gt;desc()&lt;/code&gt; helpful.&lt;/p&gt;
&lt;p&gt;Alternatively, you could try grouping by species, then use &lt;code&gt;summarise()&lt;/code&gt; to get either the max, min, or mean value for longevity_y for each species (there&amp;rsquo;s just one value for each species, so all of those statistics give the same value in this case). Then sort (arrange) the resulting summarized data frame on the longevity value.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#option 1 - shortest-lived birds&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 171 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species              longevity_y&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                      &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Loxia leucoptera            4   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Spiza americana             4   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Certhia americana           4.6 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Acanthis hornemanni         4.6 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Tringa flavipes             4.75&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Podiceps grisegena          4.8 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Calcarius lapponicus        5   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Anthus rubescens            5.1 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Perdix perdix               5.17&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Regulus satrapa             5.32&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 161 more rows&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#option 1 - longest-lived birds&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;desc&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 171 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species                  longevity_y&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                          &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Larus argentatus                33.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Larus glaucoides                33  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Larus thayeri                   33  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Haliaeetus leucocephalus        33.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Larus fuscus                    32.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Aquila chrysaetos               32  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Anas platyrhynchos              29  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Larus delawarensis              28.6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Asio otus                       27.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Cygnus olor                     27.7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 161 more rows&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#option 2 - shortest-lived birds&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;summarise&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;longevity &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;longevity&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 171 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species              longevity&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                    &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Loxia leucoptera          4   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Spiza americana           4   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Acanthis hornemanni       4.6 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Certhia americana         4.6 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Tringa flavipes           4.75&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Podiceps grisegena        4.8 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Calcarius lapponicus      5   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Anthus rubescens          5.1 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Perdix perdix             5.17&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Regulus satrapa           5.32&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 161 more rows&lt;/span&gt;&lt;/span&gt;

    
&lt;span class=&#39;c&#39;&gt;#option 2 - longest-lived birds&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;summarise&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;longevity &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/Extremes.html&#39;&gt;max&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;desc&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;longevity&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 171 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species                  longevity&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                        &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Larus argentatus              33.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Larus glaucoides              33  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Larus thayeri                 33  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Haliaeetus leucocephalus      33.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Larus fuscus                  32.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Aquila chrysaetos             32  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Anas platyrhynchos            29  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Larus delawarensis            28.6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Asio otus                     27.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Cygnus olor                   27.7&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 161 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;bonus-time&#34;&gt;Bonus time!&lt;/h2&gt;
&lt;h3 id=&#34;bonus-1&#34;&gt;Bonus 1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;What species in Ohio has the largest ratio of adult body mass to length (measured as snout vent length, or &amp;lsquo;adult_svl_cm&amp;rsquo;)?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Use &lt;code&gt;mutate()&lt;/code&gt; to create a new variable containing the body mass divided by svl, then arrange the dataset using that new variable to get the species with the highest value.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;ratio &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;/&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;adult_svl_cm&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;ratio&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;desc&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;ratio&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 170 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species_en     ratio&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;          &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Mute Swan       71.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Wild Turkey     68.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Trumpeter Swan  64.9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Bald Eagle      59.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Golden Eagle    56.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Canada Goose    48.3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Tundra Swan     47.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Cackling Goose  44.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Snow Goose      35.1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Snowy Owl       32.8&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 160 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-2&#34;&gt;Bonus 2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;There are 2 additional joins we haven&amp;rsquo;t talked about - semi_join() and anti_join(). Take a look at the documentation to see what these do. Use one of them to find what species in the backyard birds dataset are not in the life history dataset.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Use &lt;code&gt;anti_join()&lt;/code&gt; and &lt;code&gt;distinct()&lt;/code&gt;.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;anti_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
                                                     &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species                       species_en           &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Dendrocopos pubescens         Downy Woodpecker     &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Spizelloides arborea          American Tree Sparrow&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Otus asio                     Eastern Screech Owl  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Larus minutus                 Little Gull          &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Anas rubripes x platyrhynchos &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                   &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;span&gt;                            &lt;/span&gt;&lt;span style=&#39;color: #BB0000;&#39;&gt;NA&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-3&#34;&gt;Bonus 3&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;The life history dataset we downloaded above is actually a modified version of the original file, which is located at &amp;lsquo;&lt;a href=&#34;http://www.esapubs.org/archive/ecol/E096/269/Data_Files/Amniote_Database_Aug_2015.csv&#34;&gt;http://www.esapubs.org/archive/ecol/E096/269/Data_Files/Amniote_Database_Aug_2015.csv&lt;/a&gt;&amp;rsquo;&lt;/p&gt;
&lt;p&gt;Try starting with the original file and repeating what we did above - merging the variables &lt;strong&gt;species, adult_body_mass_g, adult_svl_cm, longevity_y, litter_or_clutch_size_n&lt;/strong&gt; in to the original birds dataset. First, make sure to get it read in correctly. Then pay attention to the species column in the life history dataset - what needs to be done before a join/merge can be performed?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Hints (click here)
&lt;/summary&gt;
&lt;p&gt;Pay attention to how missing data are coded in this dataset (it&amp;rsquo;s -999). Also, data are very sparse for some of the variables - in other words, they have lots of missing data. This seems to cause a problem with the &lt;code&gt;read_csv()&lt;/code&gt; function, as it only considers the first 1000 rows for the purpose of defining the class of each column. This can be a problem if all of the first 1000 rows are missing. Finally, it appears that even though this is a comma separated file (commas define the column breaks), there are a few instances where commas are used within a field. This happens in the &amp;lsquo;common name&amp;rsquo; column in a few cases where multiple common names are listed for a specific observation. This is one example of something that can become quite frustrating when trying to get data loaded in, and is worth keeping an eye out for. Fortunately, in our case, it only seems to happen for non-bird species in this dataset, which we filter out anyway, so it can be dealt with. However, if it had impacted any of the bird observations, I think fixing this might require a solution outside of R - possibly a command line approach.&lt;/p&gt;
&lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt;
Solutions (click here)
&lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;#download&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;http://www.esapubs.org/archive/ecol/E096/269/Data_Files/Amniote_Database_Aug_2015.csv&#34;&lt;/span&gt;, 
destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;data/birds/orig_life_history.csv&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#read the data in to R as an object named &#39;full_life_hist&#39;&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;full_life_hist&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_csv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;data/birds/orig_life_history.csv&#34;&lt;/span&gt;, 
                  na &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;-999&#34;&lt;/span&gt;, 
                  col_types &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;cols&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;birth_or_hatching_svl_cm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                  weaning_d &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,gestation_d &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
                  weaning_weight_g &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
                  male_svl_cm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
                  female_svl_cm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                  no_sex_svl_cm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, 
                  female_body_mass_at_maturity_g &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
                  female_svl_at_maturity_cm &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#get the original version of the birds dataset&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Parsed with column specification:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; cols(&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   order = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   family = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   genus = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   locality = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   stateProvince = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLatitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLongitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   eventDate = &lt;span style=&#39;color: #0000BB;&#39;&gt;col_datetime(format = &#34;&#34;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species_en = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   range = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; )&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#subset each for the columns and rows we want&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;full_life_hist&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;class&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Aves&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;adult_svl_cm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;litter_or_clutch_size_n&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;locality&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;stateProvince&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;eventDate&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 311,441&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Cyanocitta cristata&#34;, &#34;Cyanocitta cristata&#34;, &#34;Cyanocit…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ locality      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;44805 Ashland&#34;, &#34;45244 Cincinnati&#34;, &#34;44132 Euclid&#34;, &#34;4…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ stateProvince &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ eventDate     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;&lt;span&gt; 2007-02-16, 2007-02-17, 2007-02-17, 2007-02-19, 2007-0…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species_en    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue J…&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 9,802&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species                 &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;albogularis&#34;, &#34;badius&#34;, &#34;bicolor&#34;, &#34;brachyur…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_body_mass_g       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 251.500, 140.000, 345.000, 142.000, 203.500, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_svl_cm            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 30.00, 39.50, NA, 33.50, NA, 39.50, 29.00…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ longevity_y             &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, 12.58333, NA, 12.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ litter_or_clutch_size_n &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 3.250, 2.700, NA, 4.000, NA, 2.700, 4.250…&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#notice the species column in the life history data doesn&#39;t include the genus name. Since the names don&#39;t match in the species column from each dataset, a join won&#39;t work. Add the genus variable in from the original life history data...&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;full_life_hist&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;class&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Aves&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
                  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;genus&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;adult_body_mass_g&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;adult_svl_cm&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;longevity_y&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;litter_or_clutch_size_n&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#now use mutate to replace the species column so it includes both the genus and species...&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;species &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/paste.html&#39;&gt;paste0&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;genus&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34; &#34;&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;genus&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#preview again&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 311,441&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Cyanocitta cristata&#34;, &#34;Cyanocitta cristata&#34;, &#34;Cyanocit…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ locality      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;44805 Ashland&#34;, &#34;45244 Cincinnati&#34;, &#34;44132 Euclid&#34;, &#34;4…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ stateProvince &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ eventDate     &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;&lt;span&gt; 2007-02-16, 2007-02-17, 2007-02-17, 2007-02-19, 2007-0…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species_en    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue J…&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 9,802&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species                 &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Accipiter albogularis&#34;, &#34;Accipiter badius&#34;, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_body_mass_g       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 251.500, 140.000, 345.000, 142.000, 203.500, …&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ adult_svl_cm            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 30.00, 39.50, NA, 33.50, NA, 39.50, 29.00…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ longevity_y             &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, 12.58333, NA, 12.…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ litter_or_clutch_size_n &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; NA, 3.250, 2.700, NA, 4.000, NA, 2.700, 4.250…&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;#now we can join&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;joined_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;left_join&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;life_hist_aves&lt;/span&gt;, by &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Session 2: dplyr core verbs</title>
      <link>https://biodash.github.io/codeclub/02_dplyr-core-verbs/</link>
      <pubDate>Mon, 30 Nov 2020 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/02_dplyr-core-verbs/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;prep-homework&#34;&gt;Prep homework&lt;/h2&gt;
&lt;h3 id=&#34;basic-computer-setup&#34;&gt;Basic computer setup&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions, which also has pointers for if you&amp;rsquo;re new to R or RStudio.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;new-to-dplyr&#34;&gt;New to dplyr?&lt;/h3&gt;
&lt;p&gt;If you&amp;rsquo;ve never used &lt;code&gt;dplyr&lt;/code&gt; before (or even if you have), you may find &lt;a href=&#34;https://github.com/rstudio/cheatsheets/blob/master/data-transformation.pdf&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this cheat sheet&lt;/a&gt; useful.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;getting-started&#34;&gt;Getting Started&lt;/h2&gt;
&lt;h3 id=&#34;want-to-download-an-r-script-with-the-content-from-todays-session&#34;&gt;Want to download an R script with the content from today&amp;rsquo;s session?&lt;/h3&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# directory for Code Club Session 2:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S02&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# directory for our script&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# (&#34;recursive&#34; to create two levels at once.)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S02/scripts/&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# save the url location for today&#39;s script&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;todays_R_script&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/02_dplyr-core-verbs/2_Dplyr_one-table_verbs.R&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# indicate the name of the new script file&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;Session2_dplyr_core&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;S02/scripts/Session2_script.R&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# go get that file! &lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;todays_R_script&lt;/span&gt;,
              destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Session2_dplyr_core&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---what-is-data-wrangling&#34;&gt;1 - What is data wrangling?&lt;/h2&gt;
&lt;p&gt;It has been estimated that the process of getting your data into the appropriate formats takes about 80% of the total time of analysis. We will talk about formatting as tidy data (e.g., such that each column is a single variable, each row is a single observation, and each cell is a single value, you can learn more about tidy data &lt;a href=&#34;https://r4ds.had.co.nz/tidy-data.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;) in a future session of Code Club.&lt;/p&gt;
&lt;p&gt;The package &lt;a href=&#34;https://dplyr.tidyverse.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dplyr&lt;/code&gt;&lt;/a&gt;, as part of the &lt;a href=&#34;https://www.rdocumentation.org/packages/tidyverse/versions/1.3.0&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;tidyverse&lt;/code&gt;&lt;/a&gt; has a number of very helpful functions that will help you get your data into a format suitable for your analysis.&lt;/p&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;&lt;strong&gt;What will we go over today&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;These five core &lt;code&gt;dplyr()&lt;/code&gt; verbs will help you get wrangling.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/select.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;select()&lt;/code&gt;&lt;/a&gt; - picks variables (i.e., columns) based on their names&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; - picks observations (i.e., rows) based on their values&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/mutate.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;mutate()&lt;/code&gt;&lt;/a&gt; - makes new variables, keeps existing columns&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/arrange.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;arrange()&lt;/code&gt;&lt;/a&gt; - sorts rows based on values in columns&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://dplyr.tidyverse.org/reference/summarise.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;summarize()&lt;/code&gt;&lt;/a&gt; - reduces values down to a summary form&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2---get-ready-to-wrangle&#34;&gt;2 - Get ready to wrangle&lt;/h2&gt;
&lt;p&gt;&lt;strong&gt;Let&amp;rsquo;s get set up and grab some data so that we can get familiar with these verbs&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;You can do this locally, or at OSC. You can find instructions if you are having trouble &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;First load your libraries.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching packages&lt;/span&gt;&lt;span&gt; ─────────────────────────────────────── tidyverse 1.3.0 ──&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2&lt;/span&gt;&lt;span&gt; 3.3.2     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;purrr  &lt;/span&gt;&lt;span&gt; 0.3.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;tibble &lt;/span&gt;&lt;span&gt; 3.0.4     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr  &lt;/span&gt;&lt;span&gt; 1.0.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr  &lt;/span&gt;&lt;span&gt; 1.1.2     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stringr&lt;/span&gt;&lt;span&gt; 1.4.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;readr  &lt;/span&gt;&lt;span&gt; 1.4.0     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;forcats&lt;/span&gt;&lt;span&gt; 0.5.0&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt;&lt;span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt;&lt;span&gt; masks &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;&lt;span&gt;::filter()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;&lt;span&gt;    masks &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;&lt;span&gt;::lag()&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Then let&amp;rsquo;s access the &lt;a href=&#34;https://stat.ethz.ch/R-manual/R-devel/library/datasets/html/iris.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;iris&lt;/a&gt; dataset that comes pre-loaded in base R. We will take that data frame and assign it to a new object called &lt;code&gt;iris_data&lt;/code&gt;. Then we will look at our data.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# look at the first 6 rows, all columns&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Sepal.Length Sepal.Width Petal.Length Petal.Width Species&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1          5.1         3.5          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2          4.9         3.0          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3          4.7         3.2          1.3         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4          4.6         3.1          1.5         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5          5.0         3.6          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6          5.4         3.9          1.7         0.4  setosa&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# check the structure of iris_data&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 150&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 5&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Sepal.Length &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 5.1, 4.9, 4.7, 4.6, 5.0, 5.4, 4.6, 5.0, 4.4, 4.9, 5.4, 4…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Sepal.Width  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 3.5, 3.0, 3.2, 3.1, 3.6, 3.9, 3.4, 3.4, 2.9, 3.1, 3.7, 3…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Petal.Length &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 1.4, 1.4, 1.3, 1.5, 1.4, 1.7, 1.4, 1.5, 1.4, 1.5, 1.5, 1…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Petal.Width  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 0.2, 0.2, 0.2, 0.2, 0.2, 0.4, 0.3, 0.2, 0.2, 0.1, 0.2, 0…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ Species      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt; setosa, setosa, setosa, setosa, setosa, setosa, setosa, …&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This dataset contains the measurements (in cm) of &lt;code&gt;Sepal.Length&lt;/code&gt;, &lt;code&gt;Sepal.Width&lt;/code&gt;, &lt;code&gt;Petal.Length&lt;/code&gt;, and &lt;code&gt;Petal.Width&lt;/code&gt; for three different &lt;code&gt;Species&lt;/code&gt; of iris, &lt;em&gt;setosa&lt;/em&gt;, &lt;em&gt;versicolor&lt;/em&gt;, and &lt;em&gt;virginica&lt;/em&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3---using-select&#34;&gt;3 - Using &lt;code&gt;select()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;select()&lt;/code&gt; allows you to pick certain columns to be included in your data frame.&lt;/p&gt;
&lt;p&gt;We will create a dew data frame called iris_petals_species that includes the columns &lt;code&gt;Species&lt;/code&gt;, &lt;code&gt;Petal.Length&lt;/code&gt; and &lt;code&gt;Petal.Width&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;iris_petals_species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Petal.Length&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;Petal.Width&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What does our new data frame look like?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;iris_petals_species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Species Petal.Length Petal.Width&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1  setosa          1.4         0.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2  setosa          1.4         0.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3  setosa          1.3         0.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4  setosa          1.5         0.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5  setosa          1.4         0.2&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6  setosa          1.7         0.4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Note - look what happened to the order of the columns!&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;p&gt;&lt;strong&gt;This is not the only way to select columns.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You could also subset by indexing with the square brackets, but you can see how much more readable using &lt;code&gt;select()&lt;/code&gt; is. It&amp;rsquo;s nice not to have to refer back to remember what column is which index.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;iris_data_indexing&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;,&lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;:&lt;/span&gt;&lt;span class=&#39;m&#39;&gt;5&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;iris_data_indexing&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Petal.Length Petal.Width Species&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3          1.3         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4          1.5         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6          1.7         0.4  setosa&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;iris_data_c&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;[&lt;/span&gt;,&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/c.html&#39;&gt;c&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;Petal.Length&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Petal.Width&#34;&lt;/span&gt;, &lt;span class=&#39;s&#39;&gt;&#34;Species&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;]&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;iris_data_c&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Petal.Length Petal.Width Species&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3          1.3         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4          1.5         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6          1.7         0.4  setosa&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4---using-filterhttpsrdrriorstatsfilterhtml&#34;&gt;4 - Using &lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=https://raw.githubusercontent.com/allisonhorst/stats-illustrations/master/rstats-artwork/dplyr_filter.jpg width=&#34;95%&#34;&gt;
&lt;figcaption&gt;
Artwork by &lt;a href=&#34;https://github.com/allisonhorst/stats-illustrations&#34;&gt;Allison Horst&lt;/a&gt;.
&lt;/figcaption&gt;
&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://rdrr.io/r/stats/filter.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;filter()&lt;/code&gt;&lt;/a&gt; allows you to pick certain observations (i.e, rows) based on their values to be included in your data frame.&lt;/p&gt;
&lt;p&gt;We will create a new data frame that only includes information about the irises where their &lt;code&gt;Species&lt;/code&gt; is &lt;em&gt;setosa&lt;/em&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;iris_setosa&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;setosa&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Let&amp;rsquo;s check the dimensions of our data frame. Remember, our whole data set is 150 observations, and we are expecting 50 observations per &lt;code&gt;Species&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;iris_setosa&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 50  5&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;5---using-mutate&#34;&gt;5 - Using &lt;code&gt;mutate()&lt;/code&gt;&lt;/h2&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=https://raw.githubusercontent.com/allisonhorst/stats-illustrations/master/rstats-artwork/dplyr_mutate.png width=&#34;95%&#34;&gt;
&lt;figcaption&gt;
Artwork by &lt;a href=&#34;https://github.com/allisonhorst/stats-illustrations&#34;&gt;Allison Horst&lt;/a&gt;.
&lt;/figcaption&gt;
&lt;/p&gt;
&lt;p&gt;&lt;code&gt;mutate()&lt;/code&gt; allows you to make new variables, while keeping all your existing columns.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s make a new column that is the ratio of &lt;code&gt;Sepal.Length&lt;/code&gt;/&lt;code&gt;Sepal.Width&lt;/code&gt;&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;iris_sepal_length_to_width&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;Sepal.Length_div_Sepal.Width &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;Sepal.Length&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;/&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Sepal.Width&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;iris_sepal_length_to_width&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Sepal.Length Sepal.Width Petal.Length Petal.Width Species&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1          5.1         3.5          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2          4.9         3.0          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3          4.7         3.2          1.3         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4          4.6         3.1          1.5         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5          5.0         3.6          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6          5.4         3.9          1.7         0.4  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Sepal.Length_div_Sepal.Width&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1                     1.457143&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2                     1.633333&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3                     1.468750&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4                     1.483871&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5                     1.388889&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6                     1.384615&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;&lt;strong&gt;Note &amp;ndash; see the new column location&lt;/strong&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;6---using-arrange&#34;&gt;6 - Using &lt;code&gt;arrange()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;Very often you will want to order your data frame by some values. To do this, you can use &lt;code&gt;arrange()&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Let&amp;rsquo;s arrange the values in our &lt;code&gt;iris_data&lt;/code&gt; by &lt;code&gt;Sepal.Length&lt;/code&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;iris_data_sort_Sepal.Length&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Sepal.Length&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;iris_data_sort_Sepal.Length&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Sepal.Length Sepal.Width Petal.Length Petal.Width Species&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1          4.3         3.0          1.1         0.1  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2          4.4         2.9          1.4         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3          4.4         3.0          1.3         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 4          4.4         3.2          1.3         0.2  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 5          4.5         2.3          1.3         0.3  setosa&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 6          4.6         3.1          1.5         0.2  setosa&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What if we want to arrange by &lt;code&gt;Sepal.Length&lt;/code&gt;, but within &lt;code&gt;Species&lt;/code&gt;? We can do that using the helper &lt;a href=&#34;https://dplyr.tidyverse.org/reference/group_by.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;group_by()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Sepal.Length&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 150 x 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# Groups:   Species [3]&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    Sepal.Length Sepal.Width Petal.Length Petal.Width Species&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;        &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt;          4.3         3            1.1         0.1 setosa &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt;          4.4         2.9          1.4         0.2 setosa &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt;          4.4         3            1.3         0.2 setosa &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt;          4.4         3.2          1.3         0.2 setosa &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt;          4.5         2.3          1.3         0.3 setosa &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt;          4.6         3.1          1.5         0.2 setosa &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt;          4.6         3.4          1.4         0.3 setosa &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt;          4.6         3.6          1           0.2 setosa &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt;          4.6         3.2          1.4         0.2 setosa &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt;          4.7         3.2          1.3         0.2 setosa &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 140 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;7---using-summarize&#34;&gt;7 - Using &lt;code&gt;summarize()&lt;/code&gt;&lt;/h2&gt;
&lt;p&gt;By using &lt;code&gt;summarize()&lt;/code&gt;, you can create a new data frame that has the summary output you have requested.&lt;/p&gt;
&lt;p&gt;We can calculate the mean &lt;code&gt;Sepal.Length&lt;/code&gt; across our dataset.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Sepal.Length&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;       mean&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1 5.843333&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;What if we want to calculate means for each &lt;code&gt;Species&lt;/code&gt;?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;mean &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/mean.html&#39;&gt;mean&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Sepal.Length&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Species     mean&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;      &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; setosa      5.01&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; versicolor  5.94&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; virginica   6.59&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;We can integrate some helper functions into our code to simply get out a variety of outputs. We can use &lt;a href=&#34;https://dplyr.tidyverse.org/reference/across.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;across()&lt;/code&gt;&lt;/a&gt; to apply our summary aross a set of columns. I really like this function.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;across&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;where&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;is.numeric&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;nv&#39;&gt;mean&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 x 5&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Species    Sepal.Length Sepal.Width Petal.Length Petal.Width&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;             &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;        &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt;       &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; setosa             5.01        3.43         1.46       0.246&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; versicolor         5.94        2.77         4.26       1.33 &lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; virginica          6.59        2.97         5.55       2.03&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;This can also be useful for counting observations per group. Here, how many iris observations do we have per &lt;code&gt;Species&lt;/code&gt;?&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;tally&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Species        n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;      &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; setosa        50&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; versicolor    50&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; virginica     50&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt;      Species  n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 1     setosa 50&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 2 versicolor 50&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; 3  virginica 50&lt;/span&gt;


&lt;span class=&#39;nv&#39;&gt;iris_data&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;Species&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;n &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;n&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 3 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   Species        n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;fct&amp;gt;&lt;/span&gt;&lt;span&gt;      &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; setosa        50&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; versicolor    50&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; virginica     50&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;8---breakout-rooms&#34;&gt;8 - Breakout rooms!&lt;/h2&gt;
&lt;h3 id=&#34;read-in-data&#34;&gt;Read in data&lt;/h3&gt;
&lt;p&gt;Now you try! We are going to use the Great Backyard Birds dataset we downloaded two weeks ago and you will apply the functions we have learned above to investigate this dataset.&lt;/p&gt;
&lt;p&gt;If you weren&amp;rsquo;t here for &lt;a href=&#34;https://biodash.github.io/codeclub/01_backyard-birds/&#34;&gt;Session 1&lt;/a&gt;, get the birds data set.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# create a directory called S02&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;S02&#39;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# within S02, create a directory called data, within, a directory called birds&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#39;data/birds/&#39;&lt;/span&gt;, recursive &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Download the file from the internet.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# set the location of the file&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_file_url&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# set the path for the downloaded file&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# download &lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file_url&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If you were here for &lt;a href=&#34;https://biodash.github.io/codeclub/01_backyard-birds/&#34;&gt;Session 1&lt;/a&gt;, join back in! Let&amp;rsquo;s read in our data.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#39;data/birds/backyard-birds_Ohio.tsv&#39;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BBBB;&#39;&gt;──&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;font-weight: bold;&#39;&gt;Column specification&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #00BBBB;&#39;&gt;────────────────────────────────────────────────────────&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; cols(&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   order = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   family = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   genus = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   locality = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   stateProvince = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLatitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLongitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   eventDate = &lt;span style=&#39;color: #0000BB;&#39;&gt;col_datetime(format = &#34;&#34;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species_en = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   range = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; )&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h3 id=&#34;exercises&#34;&gt;Exercises&lt;/h3&gt;
&lt;p&gt;Below you can find our breakout room exercises for today.&lt;/p&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Investigate the structure of the birds dataset.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Solution (click here) &lt;/summary&gt;
&lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 311,441&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 12&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ class            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Ave…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ order            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Passeriformes&#34;, &#34;Passeriformes&#34;, &#34;Passeriformes&#34;, &#34;…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ family           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Corvidae&#34;, &#34;Corvidae&#34;, &#34;Corvidae&#34;, &#34;Corvidae&#34;, &#34;Cor…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ genus            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Cyanocitta&#34;, &#34;Cyanocitta&#34;, &#34;Cyanocitta&#34;, &#34;Cyanocitt…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Cyanocitta cristata&#34;, &#34;Cyanocitta cristata&#34;, &#34;Cyano…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ locality         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;44805 Ashland&#34;, &#34;45244 Cincinnati&#34;, &#34;44132 Euclid&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ stateProvince    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ decimalLatitude  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 40.86166, 39.10666, 41.60768, 39.24236, 39.28207, 41…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ decimalLongitude &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; -82.31558, -84.32972, -81.50085, -84.35545, -84.4688…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ eventDate        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;&lt;span&gt; 2007-02-16, 2007-02-17, 2007-02-17, 2007-02-19, 200…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species_en       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blu…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ range            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-2&#34;&gt;Exercise 2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;Create a new data frame that removes the column &lt;code&gt;range&lt;/code&gt;.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;&lt;br&gt; Try using select(). Remember, you can tell select() what you want to keep, and what you want to remove. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;birds_no_range&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;select&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;range&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds_no_range&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 11&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class order family genus species locality stateProvince decimalLatitude&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Aves  Pass… Corvi… Cyan… Cyanoc… 44805 A… Ohio                     40.9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Aves  Pass… Corvi… Cyan… Cyanoc… 45244 C… Ohio                     39.1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Aves  Pass… Corvi… Cyan… Cyanoc… 44132 E… Ohio                     41.6&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Aves  Pass… Corvi… Cyan… Cyanoc… 45242 C… Ohio                     39.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Aves  Pass… Corvi… Cyan… Cyanoc… 45246 C… Ohio                     39.3&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Aves  Pass… Corvi… Cyan… Cyanoc… 44484 W… Ohio                     41.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 3 more variables: decimalLongitude &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, eventDate &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   species_en &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-3&#34;&gt;Exercise 3&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;How many unique species of birds have been observed?.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Try using &lt;code&gt;summarize()&lt;/code&gt; with a &lt;code&gt;group_by()&lt;/code&gt; helper. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# using a combo of group_by() and summarize()&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;unique_birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; `summarise()` ungrouping output (override with `.groups` argument)&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;unique_birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# question - are there really 170 different birds observed?  take a look at this summary&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 170   1&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# a one line, base R approach&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/length.html&#39;&gt;length&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/unique.html&#39;&gt;unique&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;$&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 170&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# another base R approach using distinct() and nrow()&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# find distinct occurences&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# counts rows&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 170&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# using n_distinct()&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;summarize&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nf&#39;&gt;n_distinct&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 1 x 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   `n_distinct(species_en)`&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;                      &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt;                      170&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-4&#34;&gt;Exercise 4&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;How many times have Bald Eagles been observed?.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Try using filter(). Remember the syntax you need to use to indicate you are looking for a Bald Eagle. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;birds_bald_eagle&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bald Eagle&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds_bald_eagle&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 381  12&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-5&#34;&gt;Exercise 5&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;How many times have any kind of eagle been observed?. Group hint: there are only Bald Eagle and Golden Eagle in this dataset.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;There is a way to denote OR within filter(). &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt; More Hints (click here) &lt;/summary&gt;
&lt;p&gt;You denote OR by using the vertical bar. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;birds_alleagles&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Bald Eagle&#34;&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;|&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;Golden Eagle&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds_alleagles&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 386  12&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;exercise-6&#34;&gt;Exercise 6&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;What is the northern most location of the bird observations in Ohio?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Try using arrange(). You can arrange in both ascending and descending order. You can also use your Ohio knowledge to check if you&amp;rsquo;ve done this correctly. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;birds_sort_lat&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;decimalLatitude&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds_sort_lat&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 12&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class order family genus species locality stateProvince decimalLatitude&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;    &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                   &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Aves  Pass… Cardi… Card… Cardin… Conneaut Ohio                     41.9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Aves  Pass… Ember… Zono… Zonotr… Conneaut Ohio                     41.9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Aves  Colu… Colum… Zena… Zenaid… Conneaut Ohio                     41.9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Aves  Pici… Picid… Dend… Dendro… Conneaut Ohio                     41.9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; Aves  Anse… Anati… Anas  Anas p… Conneaut Ohio                     41.9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Aves  Pass… Turdi… Sial… Sialia… Conneaut Ohio                     41.9&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 4 more variables: decimalLongitude &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, eventDate &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;#   species_en &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span style=&#39;color: #555555;&#39;&gt;, range &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h2 id=&#34;bonus-time&#34;&gt;Bonus time!&lt;/h2&gt;
&lt;h3 id=&#34;bonus-1&#34;&gt;Bonus 1&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;What is the most commonly observed bird in Ohio?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Try using tally() and a little helper term.&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;unique_birds_tally&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;tally&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;sort &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/head.html&#39;&gt;head&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;unique_birds_tally&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 6 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species_en            n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;             &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;1&lt;/span&gt;&lt;span&gt; Northern Cardinal &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;23&lt;/span&gt;&lt;span&gt;064&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;2&lt;/span&gt;&lt;span&gt; Mourning Dove     &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;19&lt;/span&gt;&lt;span&gt;135&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;3&lt;/span&gt;&lt;span&gt; Dark-eyed Junco   &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;18&lt;/span&gt;&lt;span&gt;203&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;4&lt;/span&gt;&lt;span&gt; Downy Woodpecker  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;17&lt;/span&gt;&lt;span&gt;196&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;5&lt;/span&gt;&lt;span&gt; House Sparrow     &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;15&lt;/span&gt;&lt;span&gt;939&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;6&lt;/span&gt;&lt;span&gt; Blue Jay          &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;15&lt;/span&gt;&lt;span&gt;611&lt;/span&gt;&lt;/span&gt;


&lt;span class=&#39;c&#39;&gt;# another option&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; 
  &lt;span class=&#39;nf&#39;&gt;count&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;species_en&lt;/span&gt;, sort &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; 

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 170 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species_en                 n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                  &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Northern Cardinal      &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;23&lt;/span&gt;&lt;span&gt;064&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Mourning Dove          &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;19&lt;/span&gt;&lt;span&gt;135&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Dark-eyed Junco        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;18&lt;/span&gt;&lt;span&gt;203&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Downy Woodpecker       &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;17&lt;/span&gt;&lt;span&gt;196&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; House Sparrow          &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;15&lt;/span&gt;&lt;span&gt;939&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Blue Jay               &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;15&lt;/span&gt;&lt;span&gt;611&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; American Goldfinch     &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;14&lt;/span&gt;&lt;span&gt;732&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; House Finch            &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;14&lt;/span&gt;&lt;span&gt;551&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Tufted Titmouse        &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;14&lt;/span&gt;&lt;span&gt;409&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Black-capped Chickadee &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;13&lt;/span&gt;&lt;span&gt;471&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 160 more rows&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-2&#34;&gt;Bonus 2&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;What is the least commonly observed bird (or birds) in Ohio?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt;
&lt;p&gt;Try using the data frame you&amp;rsquo;ve created in the previous exercise. &lt;br&gt;&lt;/p&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;unique_birds_tally&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 170 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species_en               n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Arctic Redpoll           1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Clay-colored Sparrow     1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Dickcissel               1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Eurasian Wigeon          1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Great Egret              1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Green Heron              1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Grey Partridge           1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Harris&#39;s Sparrow         1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Lesser Yellowlegs        1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Lincoln&#39;s Sparrow        1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# … with 160 more rows&lt;/span&gt;&lt;/span&gt;

  
&lt;span class=&#39;c&#39;&gt;# or, if you knew the rarest was those observed only once  &lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;unique_birds_tally&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/stats/filter.html&#39;&gt;filter&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;==&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 19 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    species_en                        n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt;                         &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt; Arctic Redpoll                    1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt; Clay-colored Sparrow              1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt; Dickcissel                        1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt; Eurasian Wigeon                   1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt; Great Egret                       1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt; Green Heron                       1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt; Grey Partridge                    1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt; Harris&#39;s Sparrow                  1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt; Lesser Yellowlegs                 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt; Lincoln&#39;s Sparrow                 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;11&lt;/span&gt;&lt;span&gt; Loggerhead Shrike                 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;12&lt;/span&gt;&lt;span&gt; Nelson&#39;s Sparrow                  1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;13&lt;/span&gt;&lt;span&gt; Northern Rough-winged Swallow     1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;14&lt;/span&gt;&lt;span&gt; Orchard Oriole                    1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;15&lt;/span&gt;&lt;span&gt; Prairie Falcon                    1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;16&lt;/span&gt;&lt;span&gt; Red-throated Loon                 1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;17&lt;/span&gt;&lt;span&gt; Ross&#39;s Goose                      1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;18&lt;/span&gt;&lt;span&gt; Warbling Vireo                    1&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;19&lt;/span&gt;&lt;span&gt; Western Osprey                    1&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;hr&gt;
&lt;h3 id=&#34;bonus-3&#34;&gt;Bonus 3&lt;/h3&gt;
&lt;div class=&#34;alert puzzle&#34;&gt;
&lt;div&gt;
&lt;p&gt;In what year were the most Bald Eagles observed?&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt; You may want to convert your date column to a more simplified year-only date. Check out the package lubridate. &lt;br&gt;
&lt;/details&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;https://lubridate.tidyverse.org&#39;&gt;lubridate&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Attaching package: &#39;lubridate&#39;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; The following objects are masked from &#39;package:base&#39;:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     date, intersect, setdiff, union&lt;/span&gt;

&lt;span class=&#39;nv&#39;&gt;birds_bald_eagle_year&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_bald_eagle&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;mutate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;year &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;http://lubridate.tidyverse.org/reference/year.html&#39;&gt;year&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;eventDate&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt; &lt;span class=&#39;c&#39;&gt;# year() takes a date and outputs only year&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;group_by&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;year&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;%&amp;gt;%&lt;/span&gt;
  &lt;span class=&#39;nf&#39;&gt;tally&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;arrange&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds_bald_eagle_year&lt;/span&gt;, &lt;span class=&#39;o&#39;&gt;-&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;n&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;# A tibble: 11 x 2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;     year     n&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;int&amp;gt;&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 1&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;008    81&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 2&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;006    66&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 3&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;009    58&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 4&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;007    40&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 5&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;005    30&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 6&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;004    26&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 7&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;000    23&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 8&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;001    23&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt; 9&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;003    15&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;10&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;2&lt;/span&gt;&lt;span&gt;002    14&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #555555;&#39;&gt;11&lt;/span&gt;&lt;span&gt;  &lt;/span&gt;&lt;span style=&#39;text-decoration: underline;&#39;&gt;1&lt;/span&gt;&lt;span&gt;999     5&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Session 1: Backyard Birds</title>
      <link>https://biodash.github.io/codeclub/01_backyard-birds/</link>
      <pubDate>Wed, 04 Nov 2020 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/01_backyard-birds/</guid>
      <description>&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;h2 id=&#34;prep-homework&#34;&gt;Prep homework&lt;/h2&gt;
&lt;h4 id=&#34;basic-computer-setup&#34;&gt;Basic computer setup&lt;/h4&gt;
&lt;p&gt;If you didn&amp;rsquo;t already do this, please follow the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions.&lt;/p&gt;
&lt;h4 id=&#34;test-if-it-works&#34;&gt;Test if it works&lt;/h4&gt;
&lt;p&gt;Please open RStudio locally or &lt;a href=&#34;https://biodash.github.io/codeclub-setup/#osc-run-rstudio&#34;&gt;start an OSC RStudio Server session&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Nov 19 addition: If you&amp;rsquo;re working locally, test if you can load the &lt;em&gt;tidyverse&lt;/em&gt; package with &lt;a href=&#34;http://tidyverse.tidyverse.org&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;library(&amp;quot;tidyverse&amp;quot;)&lt;/code&gt;&lt;/a&gt; inside R.&lt;/strong&gt; (If you haven&amp;rsquo;t installed the &lt;em&gt;tidyverse&lt;/em&gt; yet, please go to the &lt;a href=&#34;https://biodash.github.io/codeclub-setup/#install-tidy&#34;&gt;Code Club Computer Setup&lt;/a&gt; instructions.)&lt;/p&gt;
&lt;p&gt;If you have not used RStudio before, take a moment to explore what&amp;rsquo;s in the panels and tabs. (It may help to check out &lt;a href=&#34;https://www.youtube.com/watch?v=ByxF3xjN2JQ&amp;amp;list=PLxhIMi78eQegFm3XqsylVa-Lm7nfiUshe&amp;amp;t=2m15s&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Mike Sovic&amp;rsquo;s 1-minute intro to the RStudio interface&lt;/a&gt; or &lt;a href=&#34;https://fast.wistia.net/embed/iframe/520zbd3tij?videoFoam=true&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;RStudio&amp;rsquo;s 3-minute intro&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;If you&amp;rsquo;re able to do so, please open RStudio again a bit before Code Club starts &amp;ndash; and in case you run into issues, please join the Zoom call early and we&amp;rsquo;ll troubleshoot.&lt;/p&gt;
&lt;h4 id=&#34;new-to-r&#34;&gt;New to R?&lt;/h4&gt;
&lt;p&gt;If you&amp;rsquo;re completely new to R, it will be useful to have a look at some of the resources listed on our &lt;a href=&#34;https://biodash.github.io/codeclub-novice/&#34;&gt;New to R?&lt;/a&gt; page prior to Code Club.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;slides&#34;&gt;Slides&lt;/h2&gt;
&lt;p&gt;On Friday, we started with a couple of &lt;a href=&#34;https://biodash.github.io/slides/CC01/&#34;&gt;introductory slides&lt;/a&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;hr&gt;
&lt;h2 id=&#34;1---create-an-rstudio-project&#34;&gt;1 - Create an RStudio Project&lt;/h2&gt;
&lt;p&gt;Projects are an RStudio-specific concept that create a special file (&lt;code&gt;.Rproj&lt;/code&gt;), primarily to designate a directory as the working directory for everything within it. We recommend &lt;em&gt;creating exactly one separate Project for each research project&lt;/em&gt; with an R component &amp;ndash; and for things like Code Club.&lt;/p&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;&lt;strong&gt;Why use Projects?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;In brief, Projects help you to organize your work and to make it more portable.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;They record which scripts (and R Markdown files) are open in RStudio, and will reopen all of those when you reopen the project. This becomes quite handy, say, when you work on three different projects, each of which uses a number of scripts.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;When using Projects, you generally don&amp;rsquo;t have to manually set your working directory, and can use &lt;em&gt;relative file paths&lt;/em&gt; to refer to files within the project. This way, even if you move the project directory, or copy it to a different computer, the same paths will still work. (This would not be the case if you used &lt;a href=&#34;https://rdrr.io/r/base/getwd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;setwd()&lt;/code&gt;&lt;/a&gt; which will generally require you to use an absolute path, e.g. &lt;a href=&#34;https://rdrr.io/r/base/getwd.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;setwd(&amp;quot;C:/Users/Jelmer/Documents/&amp;quot;)&lt;/code&gt;&lt;/a&gt;.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Projects encourage you to organize research projects inside self-contained directories, rather than with files spread around your computer. This can save you a lot of headaches and increases reproducibility. And because R will restart whenever you switch Projects, there is no risk of unwanted cross-talk between your projects.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;p&gt;&lt;strong&gt;Let&amp;rsquo;s create an RStudio Project for Code Club:&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Open RStudio locally or &lt;a href=&#34;https://biodash.github.io/codeclub-setup/#osc-run-rstudio&#34;&gt;start an OSC RStudio Server session&lt;/a&gt;.&lt;br&gt;
(&lt;em&gt;If you&amp;rsquo;re at OSC&lt;/em&gt;, you should see a file &lt;code&gt;0_CODECLUB.md&lt;/code&gt; that&amp;rsquo;s open in your top-left panel. You can ignore/close this file.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;If you&amp;rsquo;re working locally&lt;/em&gt;, create a directory wherever you like on your computer for all things Code Club. You can do this in R using &lt;a href=&#34;https://rdrr.io/r/base/files2.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;dir.create(&amp;quot;path/to/your/dir&amp;quot;)&lt;/code&gt;&lt;/a&gt;, or outside of R.&lt;br&gt;
(&lt;em&gt;If you&amp;rsquo;re at OSC&lt;/em&gt;, skip this step because you&amp;rsquo;re automatically inside a Code Club-specific, personal directory.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;code&gt;File&lt;/code&gt; (top menu bar) &amp;gt; &lt;code&gt;New Project&lt;/code&gt;, and then select &lt;code&gt;Existing Directory&lt;/code&gt;.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;If you&amp;rsquo;re working locally&lt;/em&gt;, select the Code Club directory that you created in the previous step.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;If you&amp;rsquo;re working at OSC&lt;/em&gt;, keep the default choice &amp;ldquo;&lt;a href=&#34;https://rdrr.io/r/base/tilde.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;~&lt;/code&gt;&lt;/a&gt;&amp;rdquo; (i.e., &lt;em&gt;home&lt;/em&gt;), which is the directory you started in when entering the RStudio Server session.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After RStudio automatically reloads, you should see the file ending in &lt;code&gt;.Rproj&lt;/code&gt; in the RStudio &lt;code&gt;Files&lt;/code&gt; tab in the lower right pane, and you will have the Project open. All done for now!&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;(For future Code Club sessions: RStudio will by default reopen the most recently used Project, and therefore, OSC users will have the Project automatically opened. If you&amp;rsquo;re working locally and are also using other Projects, you can open this Project with &lt;code&gt;File&lt;/code&gt; &amp;gt; &lt;code&gt;Open Project&lt;/code&gt; inside RStudio, or by clicking the &lt;code&gt;.Rproj&lt;/code&gt; file in your file browser, which will open RStudio &lt;em&gt;and&lt;/em&gt; the Project.)&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;2---orienting-ourselves&#34;&gt;2 - Orienting ourselves&lt;/h2&gt;
&lt;h4 id=&#34;where-are-we&#34;&gt;Where are we?&lt;/h4&gt;
&lt;p&gt;We don&amp;rsquo;t need to set our working directory, because our newly created Project is open, and therefore, our working directory is the directory that contains the &lt;code&gt;.Rproj&lt;/code&gt; file.&lt;/p&gt;
&lt;p&gt;To see where you are, type or copy into the console (bottom left):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Print the working directory:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/getwd.html&#39;&gt;getwd&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# List the files in your current directory:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/list.files.html&#39;&gt;dir&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;          &lt;span class=&#39;c&#39;&gt;# This should print at least the `.RProj` file.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id=&#34;create-directories&#34;&gt;Create directories&lt;/h4&gt;
&lt;p&gt;Create two new directories &amp;ndash; one for this session, and one for a dataset that we will download shortly (and will be reusing across sessions):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Dir for Code Club Session 1:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;S01&#34;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Dir for our bird data:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# (&#34;recursive&#34; to create two levels at once.)&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/files2.html&#39;&gt;dir.create&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;s&#39;&gt;&#34;data/birds/&#34;&lt;/span&gt;, recursive &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;TRUE&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id=&#34;create-a-script&#34;&gt;Create a script&lt;/h4&gt;
&lt;p&gt;To keep a record of what we are doing, and to easily modify and rerun earlier commands, we&amp;rsquo;ll want to save our commands in a script and execute them from there, rather than typing our commands directly in the console.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;code&gt;File&lt;/code&gt; (top menu bar) &amp;gt; &lt;code&gt;New File&lt;/code&gt; &amp;gt; &lt;code&gt;R script&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Save the script (&lt;code&gt;File&lt;/code&gt; &amp;gt; &lt;code&gt;Save&lt;/code&gt;) as &lt;code&gt;S01.R&lt;/code&gt; inside your &lt;code&gt;S01&lt;/code&gt; directory.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;first-line-of-the-script&#34;&gt;First line of the script&lt;/h4&gt;
&lt;p&gt;We will now load the core set of 8 &lt;em&gt;tidyverse&lt;/em&gt; packages all at once. To do so, type/copy the command below on the first line of the script, and then &lt;strong&gt;execute it&lt;/strong&gt; by clicking &lt;code&gt;Run&lt;/code&gt; (top right of script pane) or by pressing &lt;code&gt;Ctrl Enter&lt;/code&gt; (Windows/Linux, this should also work in your browser) or &lt;code&gt;⌘ Enter&lt;/code&gt; (Mac).&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# If you&#39;re working locally, and did not install it yet:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# install.packages(&#34;tidyverse&#34;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Load the tidyverse (meta)package:&lt;/span&gt;
&lt;span class=&#39;kr&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/library.html&#39;&gt;library&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;&lt;a href=&#39;http://tidyverse.tidyverse.org&#39;&gt;tidyverse&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Attaching packages&lt;/span&gt;&lt;span&gt; ─────────────────────────────────────── tidyverse 1.3.0 ──&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;ggplot2&lt;/span&gt;&lt;span&gt; 3.3.2     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;purrr  &lt;/span&gt;&lt;span&gt; 0.3.4&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;tibble &lt;/span&gt;&lt;span&gt; 3.0.4     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr  &lt;/span&gt;&lt;span&gt; 1.0.2&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;tidyr  &lt;/span&gt;&lt;span&gt; 1.1.2     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stringr&lt;/span&gt;&lt;span&gt; 1.4.0&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;readr  &lt;/span&gt;&lt;span&gt; 1.3.1     &lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;✔&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;forcats&lt;/span&gt;&lt;span&gt; 0.5.0&lt;/span&gt;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; ── &lt;span style=&#39;font-weight: bold;&#39;&gt;Conflicts&lt;/span&gt;&lt;span&gt; ────────────────────────────────────────── tidyverse_conflicts() ──&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;filter()&lt;/span&gt;&lt;span&gt; masks &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;&lt;span&gt;::filter()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; &lt;span style=&#39;color: #BB0000;&#39;&gt;✖&lt;/span&gt;&lt;span&gt; &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;dplyr&lt;/span&gt;&lt;span&gt;::&lt;/span&gt;&lt;span style=&#39;color: #00BB00;&#39;&gt;lag()&lt;/span&gt;&lt;span&gt;    masks &lt;/span&gt;&lt;span style=&#39;color: #0000BB;&#39;&gt;stats&lt;/span&gt;&lt;span&gt;::lag()&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;If this worked, you should get the same output as shown in the code block above: it attached 8 packages, and it warns that some of its functions are now &amp;ldquo;masking&amp;rdquo; base R functions.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;The &lt;em&gt;tidyverse&lt;/em&gt; is a very popular and useful ecosystem of R packages for data analysis, which we will be using a lot in Code Club.&lt;/p&gt;
&lt;p&gt;When we refer to &amp;ldquo;&lt;em&gt;base R&lt;/em&gt;&amp;rdquo; as opposed to the &lt;em&gt;tidyverse&lt;/em&gt;, we mean functions that are loaded in R by default (without loading a package), and that can perform similar operations in a different way.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;3---getting-our-dataset&#34;&gt;3 - Getting our dataset&lt;/h2&gt;
&lt;p&gt;We downloaded a Great Backyard Bird Count (GBBC) &lt;a href=&#34;https://www.gbif.org/dataset/82cb293c-f762-11e1-a439-00145eb45e9a&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;dataset&lt;/a&gt; from the &lt;a href=&#34;https://www.gbif.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Global Biodiversity Information Facility (GBIF)&lt;/a&gt;. Because the file was 3.1 GB large, we selected only the records from Ohio and removed some uninformative columns. We also added columns with English names and the breeding range for each species. We&amp;rsquo;ll download the resulting much smaller file (41.5 MB) from our Github repo.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;the-great-backyard-bird-count&#34;&gt;The Great Backyard Bird Count&lt;/h3&gt;
&lt;p align=&#34;center&#34;&gt;
&lt;img src=GBBC_screenshot.png width=&#34;95%&#34;&gt;
&lt;/p&gt;
&lt;p&gt;The &lt;a href=&#34;https://gbbc.birdcount.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;GBBC&lt;/a&gt; is an annual citizen science event where everyone is encouraged to to identify and count birds in their backyard &amp;ndash; or anywhere else &amp;ndash; for at least 15 minutes, and report their sightings online. Since 2013, it is a global event, but it has been organized in the US and Canada since 1998.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h4 id=&#34;download-the-data&#34;&gt;Download the data&lt;/h4&gt;
&lt;p&gt;Let&amp;rsquo;s download the dataset using the &lt;a href=&#34;https://rdrr.io/r/utils/download.file.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;download.file()&lt;/code&gt;&lt;/a&gt; function:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# The URL to our file:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_file_url&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/data/birds/backyard-birds_Ohio.tsv&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# The path to the file we want to download to:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;data/birds/backyard-birds_Ohio.tsv&#34;&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# Download:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file_url&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;h4 id=&#34;read-the-data&#34;&gt;Read the data&lt;/h4&gt;
&lt;p&gt;Now, let&amp;rsquo;s read the file into R. The &lt;code&gt;.tsv&lt;/code&gt; extension (&amp;ldquo;tab-separated values&amp;rdquo;) tells us this is a plain text file in which columns are separated by tabs, so we will use a convenience function from the &lt;em&gt;readr&lt;/em&gt; package (which is loaded as part of the core set &lt;em&gt;tidyverse&lt;/em&gt; packages) for exactly this type of file:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Read the data:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_tsv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;file &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Parsed with column specification:&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; cols(&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   class = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   order = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   family = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   genus = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   locality = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   stateProvince = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLatitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   decimalLongitude = &lt;span style=&#39;color: #00BB00;&#39;&gt;col_double()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   eventDate = &lt;span style=&#39;color: #0000BB;&#39;&gt;col_datetime(format = &#34;&#34;)&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   species_en = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;span&gt;,&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt;   range = &lt;span style=&#39;color: #BB0000;&#39;&gt;col_character()&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; )&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;Done! We have now read our data into a &lt;em&gt;tibble&lt;/em&gt;, which is a type of data frame (formally a &lt;em&gt;data.frame&lt;/em&gt;): R&amp;rsquo;s object class to deal with tabular data wherein each column can contain a different type of data (numeric, characters/strings, etc).&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;4---exploring-backyard-birds&#34;&gt;4 - Exploring backyard birds&lt;/h2&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;h3 id=&#34;exercise-1&#34;&gt;Exercise 1&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;What&amp;rsquo;s in the dataset?&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Explore the dataset using some functions and methods you may know to get a quick overview of data(frames), and try to understand what you see. What does a single row represent, and what is in each column? (Be sure to check out the hints below at some point, especially if you&amp;rsquo;re stuck.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Pay attention to the data types (e.g., &amp;ldquo;character&amp;rdquo; or &lt;code&gt;chr&lt;/code&gt;) of the different columns, which several of these functions print. The output of our &lt;code&gt;read_tsv()&lt;/code&gt; command also printed this information &amp;ndash; this function parsed our columns as the types we see now. Were all the columns parsed correctly?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;How many rows and how many columns does the dataset have?&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;What are some questions you would like to explore with this dataset? We&amp;rsquo;ll collect some of these and try to answer them in later sessions. If your group has sufficient R skills already, you are also welcome to go ahead and try to answer one or more of these questions.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt; &lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Type an object&#39;s name to print it to screen:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# Same as above, but explicitly calling print():&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/print.html&#39;&gt;print&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;   

&lt;span class=&#39;c&#39;&gt;# For column-wise information (short for &#34;structure&#34;):&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/str.html&#39;&gt;str&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# tidyverse version of str():&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# In RStudio, open object in a separate tab:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/View.html&#39;&gt;View&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Note that in R, &lt;code&gt;dbl&lt;/code&gt; (for &amp;ldquo;double&amp;rdquo;) and &lt;code&gt;num&lt;/code&gt; (for &amp;ldquo;numeric&amp;rdquo;) are both used, and almost interchangeably so, for floating point numbers. (Integers are a separate type that are simply called &amp;ldquo;integers&amp;rdquo; and abbreviated as &lt;code&gt;int&lt;/code&gt;, but we have no integer columns in this dataset.)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;read_tsv()&lt;/code&gt; parsed our date as a &amp;ldquo;date-time&amp;rdquo; (&lt;code&gt;dttm&lt;/code&gt; or &lt;code&gt;POSIXct&lt;/code&gt; for short), which contains both a date and a time. In our case, it looks like the time is always &amp;ldquo;00:00:00&amp;rdquo; and thus doesn&amp;rsquo;t provide any information.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solutions (click here) &lt;/summary&gt; &lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Just printing the glimpse() output,&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;# which will show the number of rows and columns:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;glimpse&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; Rows: 311,441&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; Columns: 12&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ class            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Aves&#34;, &#34;Ave…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ order            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Passeriformes&#34;, &#34;Passeriformes&#34;, &#34;Passeriformes&#34;, &#34;…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ family           &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Corvidae&#34;, &#34;Corvidae&#34;, &#34;Corvidae&#34;, &#34;Corvidae&#34;, &#34;Cor…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ genus            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Cyanocitta&#34;, &#34;Cyanocitta&#34;, &#34;Cyanocitta&#34;, &#34;Cyanocitt…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species          &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Cyanocitta cristata&#34;, &#34;Cyanocitta cristata&#34;, &#34;Cyano…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ locality         &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;44805 Ashland&#34;, &#34;45244 Cincinnati&#34;, &#34;44132 Euclid&#34;,…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ stateProvince    &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohio&#34;, &#34;Ohi…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ decimalLatitude  &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; 40.86166, 39.10666, 41.60768, 39.24236, 39.28207, 41…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ decimalLongitude &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dbl&amp;gt;&lt;/span&gt;&lt;span&gt; -82.31558, -84.32972, -81.50085, -84.35545, -84.4688…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ eventDate        &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;dttm&amp;gt;&lt;/span&gt;&lt;span&gt; 2007-02-16, 2007-02-17, 2007-02-17, 2007-02-19, 200…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ species_en       &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blue Jay&#34;, &#34;Blu…&lt;/span&gt;&lt;/span&gt;
&lt;span class=&#39;c&#39;&gt;#&amp;gt; $ range            &lt;span style=&#39;color: #555555;font-style: italic;&#39;&gt;&amp;lt;chr&amp;gt;&lt;/span&gt;&lt;span&gt; NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, …&lt;/span&gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# You can also check the number of rows and columns directly using:&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/dim.html&#39;&gt;dim&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;          &lt;span class=&#39;c&#39;&gt;# Will return the number of rows and columns&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 311441     12&lt;/span&gt;


&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;nrow&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;         &lt;span class=&#39;c&#39;&gt;# Will return the number of rows&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 311441&lt;/span&gt;

&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/base/nrow.html&#39;&gt;ncol&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;nv&#39;&gt;birds&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;         &lt;span class=&#39;c&#39;&gt;# Will return the number of columns&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;#&amp;gt; [1] 12&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
&lt;hr&gt;
&lt;h2 id=&#34;bonus-material&#34;&gt;Bonus material&lt;/h2&gt;
&lt;p&gt;If your breakout group is done with Exercise 1, you can have a look at the bonus material below which includes another exercise. You can also have a look at this as homework. Or not at all!&lt;/p&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;readr-options-for-challenging-files&#34;&gt;&lt;code&gt;readr&lt;/code&gt; options for challenging files&lt;/h3&gt;
&lt;p&gt;Earlier, we successfully read in our file without specifying any arguments other than the file name to the &lt;code&gt;read_tsv()&lt;/code&gt; function, i.e. with all the default options. It is not always this easy!&lt;/p&gt;
&lt;p&gt;Some options for more complex cases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The more general counterpart of this function is &lt;code&gt;read_delim()&lt;/code&gt;, which allows you to specify the delimiter using the &lt;code&gt;sep&lt;/code&gt; argument, e.g. &lt;code&gt;delim=&amp;quot;\t&amp;quot;&lt;/code&gt; for tabs.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;There are also arguments to these functions for when you need to skip lines, when you don&amp;rsquo;t have column headers, when you need to specify the column types of some or all the columns, and so forth &amp;ndash; see this example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;nv&#39;&gt;my_df&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_delim&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  file &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;file.txt&#34;&lt;/span&gt;,
  delim &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;\t&#34;&lt;/span&gt;,             &lt;span class=&#39;c&#39;&gt;# Specify tab as delimiter&lt;/span&gt;
  col_names &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;kc&#39;&gt;FALSE&lt;/span&gt;,        &lt;span class=&#39;c&#39;&gt;# First line is not a header&lt;/span&gt;
  skip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;3&lt;/span&gt;,                 &lt;span class=&#39;c&#39;&gt;# Skip the first three lines&lt;/span&gt;
  comment &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;#&#34;&lt;/span&gt;,            &lt;span class=&#39;c&#39;&gt;# Skip any line beginning with a &#34;#&#34;&lt;/span&gt;
  col_types &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;cols&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;         &lt;span class=&#39;c&#39;&gt;# Specify column types&lt;/span&gt;
    col1 &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_character&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# ..We only need to specify columns for &lt;/span&gt;
    col2 &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_double&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;     &lt;span class=&#39;c&#39;&gt;# ..which we need non-automatic typing&lt;/span&gt;
    &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;puzzle&#34;&gt;
&lt;h3 id=&#34;exercise-2-optional&#34;&gt;Exercise 2 (Optional)&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Read this file!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Try to read the following file into R, which is a modified and much smaller version of the bird dataset.&lt;/p&gt;
&lt;p&gt;Make the function parse the &amp;ldquo;order&amp;rdquo; column as a factor, and the &amp;ldquo;year&amp;rdquo;, &amp;ldquo;month&amp;rdquo;, and &amp;ldquo;day&amp;rdquo; columns as whatever you think is sensible.&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Download and read the file:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds2_file_url&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/assets/data/birds/backyard-birds_read-challenge.txt&#34;&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds2_file&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;data/birds/backyard-birds_read-challenge.txt&#34;&lt;/span&gt;
&lt;span class=&#39;nf&#39;&gt;&lt;a href=&#39;https://rdrr.io/r/utils/download.file.html&#39;&gt;download.file&lt;/a&gt;&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;url &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds2_file_url&lt;/span&gt;, destfile &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds2_file&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# Your turn!&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;read_&lt;/span&gt;    &lt;span class=&#39;c&#39;&gt;# Complete the command&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;details&gt;
&lt;summary&gt; Hints (click here) &lt;/summary&gt; &lt;br&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The file is saved as &lt;code&gt;.txt&lt;/code&gt;, so the delimiter is not obvious &amp;ndash; first have a look at it (open it in RStudio, a text editor, or the terminal) to determine the delimiter. Then, use &lt;code&gt;read_delim()&lt;/code&gt; with manual specification of the delimiter using the &lt;code&gt;delim&lt;/code&gt; argument, or use a specialized convenience function.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Besides a leading line with no data, there is another problematic line further down. You will need both the &lt;code&gt;skip&lt;/code&gt; and &lt;code&gt;comment&lt;/code&gt; arguments to circumvent these.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Note that &lt;em&gt;readr&lt;/em&gt; erroneously parses &lt;code&gt;month&lt;/code&gt; as a character column if you don&amp;rsquo;t manually specify its type.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Note that you can also use a succinct column type specification like &lt;code&gt;col_types = &amp;quot;fc&amp;quot;&lt;/code&gt;, which would parse, for a two-column file, the first column as a factor and the second as a character &amp;ndash; type e.g. &lt;code&gt;?read_tsv&lt;/code&gt; for details.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Bare solution (click here) &lt;/summary&gt; &lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# With succint column type specification:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_csv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  file &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds2_file&lt;/span&gt;,
  skip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,
  comment &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;$&#34;&lt;/span&gt;,
  col_types &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;fcdiii&#34;&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# With long column type specification:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_csv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  file &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds2_file&lt;/span&gt;,
  skip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,
  comment &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;$&#34;&lt;/span&gt;,
  col_types &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;cols&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
    order &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_factor&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
    year &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;  &lt;span class=&#39;nf&#39;&gt;col_integer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
    month &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_integer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
    day &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_integer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;details&gt;
&lt;summary&gt; Solution with explanations (click here) &lt;/summary&gt; &lt;br&gt;
&lt;div class=&#34;highlight&#34;&gt;
&lt;pre class=&#39;chroma&#39;&gt;&lt;code class=&#39;language-r&#39; data-lang=&#39;r&#39;&gt;&lt;span class=&#39;c&#39;&gt;# With succinct column type specification:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_csv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;     &lt;span class=&#39;c&#39;&gt;# `read_csv()`: file is comma-delimited&lt;/span&gt;
  file &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds2_file&lt;/span&gt;,
  skip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,             &lt;span class=&#39;c&#39;&gt;# First line is not part of the dataframe&lt;/span&gt;
  comment &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;$&#34;&lt;/span&gt;,        &lt;span class=&#39;c&#39;&gt;# Line 228 is a comment that starts with `$`&lt;/span&gt;
  col_types &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;fcdiii&#34;&lt;/span&gt;  &lt;span class=&#39;c&#39;&gt;# &#34;f&#34; for factor, &#34;c&#34; for character,&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;                     &lt;span class=&#39;c&#39;&gt;# ..&#34;d&#34; for double (=numeric),&lt;/span&gt;
                        &lt;span class=&#39;c&#39;&gt;# ..&#34;i&#34; for integer.&lt;/span&gt;

&lt;span class=&#39;c&#39;&gt;# With long column type specification:&lt;/span&gt;
&lt;span class=&#39;nv&#39;&gt;birds2&lt;/span&gt; &lt;span class=&#39;o&#39;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;read_csv&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;
  file &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nv&#39;&gt;birds2_file&lt;/span&gt;,
  skip &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;m&#39;&gt;1&lt;/span&gt;,
  comment &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;s&#39;&gt;&#34;$&#34;&lt;/span&gt;,
  col_types &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;cols&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;        &lt;span class=&#39;c&#39;&gt;# We can omit columns for which we&lt;/span&gt;
    order &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_factor&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,  &lt;span class=&#39;c&#39;&gt;# ..accept the automatic parsing,&lt;/span&gt;
    year &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt;  &lt;span class=&#39;nf&#39;&gt;col_integer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;, &lt;span class=&#39;c&#39;&gt;# ..when using the long specification. &lt;/span&gt;
    month &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_integer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;,
    day &lt;span class=&#39;o&#39;&gt;=&lt;/span&gt; &lt;span class=&#39;nf&#39;&gt;col_integer&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;(&lt;/span&gt;&lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
    &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
  &lt;span class=&#39;o&#39;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;/div&gt;
&lt;/details&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;other-options-for-reading-tabular-data&#34;&gt;Other options for reading tabular data&lt;/h3&gt;
&lt;p&gt;There are also functions in &lt;em&gt;base R&lt;/em&gt; that read tabular data, such as &lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read.table()&lt;/code&gt;&lt;/a&gt; and &lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read.delim()&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;These are generally slower than the &lt;em&gt;readr&lt;/em&gt; functions, and have less sensible default options to their arguments. Particularly relevant is how columns with characters (strings) are parsed &amp;ndash; until R 4.0, which was released earlier this year, base R&amp;rsquo;s default behavior was to parse them as &lt;strong&gt;factors&lt;/strong&gt;, and this is generally not desirable&lt;sup id=&#34;fnref:1&#34;&gt;&lt;a href=&#34;#fn:1&#34; class=&#34;footnote-ref&#34; role=&#34;doc-noteref&#34;&gt;1&lt;/a&gt;&lt;/sup&gt;. &lt;em&gt;readr&lt;/em&gt; functions will never convert columns with strings to factors.&lt;/p&gt;
&lt;p&gt;If speed is important, such as when reading in very large files (~ 100s of MBs or larger), you should consider using the &lt;code&gt;fread()&lt;/code&gt; function from the &lt;em&gt;data.table&lt;/em&gt; package.&lt;/p&gt;
&lt;p&gt;Finally, some examples of reading other types of files:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Read excel files directly using the &lt;em&gt;readxl&lt;/em&gt; package.&lt;/li&gt;
&lt;li&gt;Read Google Sheets directly from the web using the &lt;em&gt;googlesheets4&lt;/em&gt; package.&lt;/li&gt;
&lt;li&gt;Read non-tabular data using the base R &lt;a href=&#34;https://rdrr.io/r/base/readLines.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;readLines()&lt;/code&gt;&lt;/a&gt; function.&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt; &lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;section class=&#34;footnotes&#34; role=&#34;doc-endnotes&#34;&gt;
&lt;hr&gt;
&lt;ol&gt;
&lt;li id=&#34;fn:1&#34; role=&#34;doc-endnote&#34;&gt;
&lt;p&gt;You can check which version of R you are running by typing &lt;a href=&#34;https://rdrr.io/r/utils/sessionInfo.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;sessionInfo()&lt;/code&gt;&lt;/a&gt;. You can also check directly how strings are read by default with &lt;a href=&#34;https://rdrr.io/r/base/data.frame.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;default.stringsAsFactors()&lt;/code&gt;&lt;/a&gt;. To avoid conversion to factors, specify &lt;code&gt;stringsAsFactors = FALSE&lt;/code&gt; in your &lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read.table()&lt;/code&gt;&lt;/a&gt; / &lt;a href=&#34;https://rdrr.io/r/utils/read.table.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;code&gt;read.delim()&lt;/code&gt;&lt;/a&gt; function call. &lt;a href=&#34;#fnref:1&#34; class=&#34;footnote-backref&#34; role=&#34;doc-backlink&#34;&gt;&amp;#x21a9;&amp;#xfe0e;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;/section&gt;
</description>
    </item>
    
    <item>
      <title>Welcome to Code Club</title>
      <link>https://biodash.github.io/codeclub/00_welcome-to-codeclub/</link>
      <pubDate>Mon, 19 Oct 2020 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub/00_welcome-to-codeclub/</guid>
      <description>&lt;hr&gt;
&lt;br&gt;
&lt;p&gt;&lt;strong&gt;Welcome to OSU Code Club! Materials for each episode will be provided in posts like this one,
collected in the &lt;a href=&#34;https://biodash.github.io/codeclub/&#34;&gt;Code Club Sessions page&lt;/a&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;For more information about OSU Code Club, and a form to sign up,
see the &lt;a href=&#34;https://biodash.github.io/codeclub-about/&#34;&gt;About Code Club page&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;For info on upcoming sessions, see &lt;a href=&#34;https://biodash.github.io/codeclub-schedule/&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can code locally or in your browser, see our &lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;page with computer setup instructions&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If you are completely new to R, see our &lt;a href=&#34;https://biodash.github.io/codeclub-novice/&#34;&gt;page with resources and tips&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You can also &lt;a href=&#34;https://biodash.github.io/codeclub-suggest/&#34;&gt;suggest a topic to be covered at Code Club&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br/&gt; &lt;br/&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>LICENSE: CC-BY-SA</title>
      <link>https://biodash.github.io/license/</link>
      <pubDate>Sat, 04 Jan 2020 00:00:00 +0100</pubDate>
      <guid>https://biodash.github.io/license/</guid>
      <description>&lt;p&gt;All material is released under a &lt;a href=&#34;http://creativecommons.org/licenses/by-sa/4.0/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Creative Commons Attribution-ShareAlike 4.0 International License&lt;/a&gt;.&lt;/p&gt;
&lt;center&gt;
&lt;i class=&#34;fab fa-creative-commons fa-2x&#34;&gt;&lt;/i&gt;&lt;i class=&#34;fab fa-creative-commons-by fa-2x&#34;&gt;&lt;/i&gt;&lt;i class=&#34;fab fa-creative-commons-sa fa-2x&#34;&gt;&lt;/i&gt;
&lt;/center&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://biodash.github.io/admin/config.yml</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/admin/config.yml</guid>
      <description></description>
    </item>
    
    <item>
      <title></title>
      <link>https://biodash.github.io/codeclub-about/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub-about/</guid>
      <description>&lt;h1 id=&#34;about-osu-code-club&#34;&gt;About OSU Code Club&lt;/h1&gt;
&lt;hr&gt;
&lt;br&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;&lt;div&gt;
&lt;p&gt;Code Club will restart at the end of August&lt;/p&gt;
&lt;p&gt;During the first part of the semester,
we will cover how to make a website with Quarto/RMarkdown and Git/GitHub.
During the second part of the semester, we will learn about R Shiny.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://forms.office.com/r/SgmdwJXEXx&#34;&gt;See this form for more information and to sign up!&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;OSU Code Club is a regularly occurring, interactive, online and in-person gathering to improve coding skills.
We aim for a supportive and fun culture of learning together, and hope to offer something to participants at any experience level.&lt;/p&gt;
&lt;p&gt;In each meeting, a presenter first introduces a concept or tool to be used for a challenge.
Then, we work on the challenge in small groups, and finally,
we reconvene to see what approaches were taken and to share lessons learned.&lt;/p&gt;
&lt;p&gt;So far, we have focused entirely on &lt;strong&gt;the R language&lt;/strong&gt; and its surrounding ecosystem (R Markdown, Shiny, etc).
Depending on interest, we may in the future also cover Python, the Unix shell (terminal),
running your analyses at the Ohio Supercomputer Center, and so on.&lt;/p&gt;
&lt;h3 id=&#34;learn-more-about--and-get-ready-for--code-club&#34;&gt;Learn more about -and get ready for- Code Club&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://biodash.github.io/codeclub-schedule/&#34;&gt;Schedule&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;#sign-up&#34;&gt;Form to sign up&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://biodash.github.io/codeclub-setup/&#34;&gt;Computer setup instructions&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/&#34;&gt;Resources and tips for R novices&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://biodash.github.io/codeclub-schedule/#previous-semesters&#34;&gt;List of previous sessions by semester in table form&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/&#34;&gt;List of previous sessions as a blogroll&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://biodash.github.io/codeclub-suggest/&#34;&gt;Form to suggest topics&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;more-information&#34;&gt;More information&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Each week, &lt;strong&gt;materials and suggested reading&lt;/strong&gt; will be posted up front at the &lt;a href=&#34;https://biodash.github.io/codeclub/&#34;&gt;Sessions page&lt;/a&gt;.
Like at a Journal Club, doing some preparatory homework by reading these materials will help you get the most out of it.
[Note for the Summer &amp;lsquo;22 sessions: as we will be working through a book, we may not post additional materials online.]&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Each session is intended to be &lt;strong&gt;mostly stand-alone&lt;/strong&gt; to allow for occasional participation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To allow for a welcoming environment for participants at all levels of experience,
we ask everyone to be &lt;strong&gt;respectful, patient, and collaborative&lt;/strong&gt; when interacting at Code Club.
This is not a competitive event.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;There will be no consistent analysis type or data type &amp;mdash;
instead, we will focus on &lt;strong&gt;building general skills&lt;/strong&gt; and applying those to a wide variety of data.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The idea for this Code Club was taken from a recent paper in PLoS Computational Biology:
&lt;a href=&#34;https://journals.plos.org/ploscompbiol/article?id=10.1371/journal.pcbi.1008119&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Ten simple rules to increase computational skills among biologists with Code   Clubs&lt;/a&gt;.
We liked this idea because of the high level of interaction and because gradual,
well-spaced practice is an excellent way to retain what you learn.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;organizers&#34;&gt;Organizers&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/authors/admin/&#34;&gt;Jelmer Poelstra&lt;/a&gt; - Bioinformatician at &lt;a href=&#34;http://mcic.osu.edu/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;MCIC&lt;/a&gt; Wooster&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/authors/mike-sovic/&#34;&gt;Mike Sovic&lt;/a&gt; - Asst. Director at the Infectious Diseases Institute AMSL - Genomics Lab&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/authors/stephen-opiyo/&#34;&gt;Stephen Opiyo&lt;/a&gt; - Biostatistician at &lt;a href=&#34;http://mcic.osu.edu/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;MCIC&lt;/a&gt; Columbus&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/authors/michael-broe/&#34;&gt;Michael Broe&lt;/a&gt; - Bioinformatician at &lt;a href=&#34;https://eeob.osu.edu/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;EEOB&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/authors/jessica-cooperstone/&#34;&gt;Jessica Cooperstone&lt;/a&gt; - Asst. Professor at &lt;a href=&#34;https://hcs.osu.edu/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;HCS&lt;/a&gt; &amp;amp; &lt;a href=&#34;https://fst.osu.edu/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;FST&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;sign-up&#34;&gt;Sign up&lt;/h2&gt;
&lt;p&gt;To sign up, please fill out the Google Form below. Hope to see you at Code Club!&lt;/p&gt;
&lt;iframe src=&#34;https://docs.google.com/forms/d/e/1FAIpQLSd_N7FkNlPnCN76J1UMCi4SlCkkG2Bq0l2llxsd7EGkdlDawA/viewform?embedded=true&#34; width=&#34;800&#34; height=&#34;1404&#34; frameborder=&#34;0&#34; marginheight=&#34;0&#34; marginwidth=&#34;0&#34;&gt;Loading…&lt;/iframe&gt;
&lt;p&gt;&lt;br/&gt; &lt;br/&gt; &lt;br/&gt;&lt;/p&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://biodash.github.io/codeclub-novice/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub-novice/</guid>
      <description>&lt;h1 id=&#34;code-club-br-r----getting-started-and-some-tips&#34;&gt;Code Club: &lt;br/&gt; R &amp;ndash; Getting Started and Some Tips&lt;/h1&gt;
&lt;hr&gt;
&lt;br&gt;
&lt;h2 id=&#34;new-to-r&#34;&gt;New to R?&lt;/h2&gt;
&lt;p&gt;If you are completely new to R, we recommend watching at least the first couple of
videos from &lt;a href=&#34;https://www.youtube.com/playlist?list=PLxhIMi78eQegFm3XqsylVa-Lm7nfiUshe&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Mike Sovic&amp;rsquo;s Youtube playlist of short videos on R&lt;/a&gt;,
and ideally all of them, prior to attending Code Club. Here is the first video:&lt;/p&gt;

&lt;div style=&#34;position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden;&#34;&gt;
  &lt;iframe src=&#34;https://www.youtube.com/embed/ByxF3xjN2JQ&#34; style=&#34;position: absolute; top: 0; left: 0; width: 100%; height: 100%; border:0;&#34; allowfullscreen title=&#34;YouTube Video&#34;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;br&gt;
&lt;p&gt;In case you want to do more self-study (note that this is &lt;em&gt;not&lt;/em&gt; required/needed),
here are some additional resources:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;A useful and fun written tutorial is &lt;a href=&#34;https://rforcats.net/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R for cats&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;For a more systematic and lengthy introduction to R, see
&lt;a href=&#34;https://kingaa.github.io/R_Tutorial/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;A Tutorial Introduction to R&lt;/a&gt;
(this gets fairly advanced after section 9).&lt;/li&gt;
&lt;li&gt;Excellent comprehensive introductions are the &lt;a href=&#34;https://www.edx.org/course/data-science-r-basics&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R Basics&lt;/a&gt;
and &lt;a href=&#34;https://www.edx.org/course/data-science-visualization&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Visualization&lt;/a&gt; classes by Rafael Irizarry
that can be freely accessed; you do have to create an account.&lt;/li&gt;
&lt;li&gt;OSU TDAI videos:
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://mediasite.osu.edu/Mediasite/Play/f7d6605508f842d09fd5b5ec9c88619a1d&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Installing R / R Studio&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://mediasite.osu.edu/Mediasite/Play/3d2f076f64854b57a6e5e5a99b60d6781d&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;R / R Studio Introduction&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Also, don&amp;rsquo;t hesitate to reach out to the &lt;a href=&#34;https://biodash.github.io/codeclub-about/#organizers&#34;&gt;Code Club organizers&lt;/a&gt;
if you have any questions!&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;miscellaneous-r-tips&#34;&gt;Miscellaneous R tips&lt;/h2&gt;
&lt;h3 id=&#34;useful-settings&#34;&gt;Useful settings&lt;/h3&gt;
&lt;p&gt;By default, R will try to save your &amp;ldquo;environment&amp;rdquo; (e.g., your loaded data, variables, etc)
when you exit, and then reload everything the way it was upon restarting R. However, this is bad!
You should always be able to reproduce your environment given a set of commands
saved in an R script or R Markdown document, whereas saving and reloading your environment
encourages you to be sloppy about this.&lt;/p&gt;
&lt;p&gt;To disable this in RStudio, go to &lt;code&gt;Tools&lt;/code&gt; &amp;gt; &lt;code&gt;Global Options&lt;/code&gt; &amp;gt; &lt;code&gt;General&lt;/code&gt; and set the options
as follows:&lt;/p&gt;














&lt;figure  id=&#34;figure-recommended-rrstudio-settings&#34;&gt;
  &lt;div class=&#34;d-flex justify-content-center&#34;&gt;
    &lt;div class=&#34;w-100&#34; &gt;
        &lt;img alt=&#34;Recommended R/RStudio settings&#34; srcset=&#34;
               /codeclub-novice/r_environment_hue775a74660cf2a97927d5d9828f7cef1_14520_ac3a5c6a57b22de9496b2353b2adf819.png 400w,
               /codeclub-novice/r_environment_hue775a74660cf2a97927d5d9828f7cef1_14520_94b480b5086118c73ecca09a306fc635.png 760w,
               /codeclub-novice/r_environment_hue775a74660cf2a97927d5d9828f7cef1_14520_1200x1200_fit_lanczos_2.png 1200w&#34;
               src=&#34;https://biodash.github.io/codeclub-novice/r_environment_hue775a74660cf2a97927d5d9828f7cef1_14520_ac3a5c6a57b22de9496b2353b2adf819.png&#34;
               width=&#34;500px&#34;
               height=&#34;128&#34;
               loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;figcaption&gt;
      Recommended R/RStudio settings
    &lt;/figcaption&gt;&lt;/figure&gt;
&lt;p&gt;To start R in the same way from the command line:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;R&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;--&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;no&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;save&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;--&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;no&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;restore&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;-&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;data&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;installing-r-packages&#34;&gt;Installing R packages&lt;/h3&gt;
&lt;h4 id=&#34;cran-packages&#34;&gt;CRAN packages&lt;/h4&gt;
&lt;p&gt;To install an R package that is available at &lt;a href=&#34;https://cran.r-project.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;CRAN&lt;/a&gt;, the default R package repository,
from within R (e.g. in the R console in RStudio), use the &lt;code&gt;install.packages()&lt;/code&gt; function.&lt;/p&gt;
&lt;p&gt;The &lt;code&gt;install.packages()&lt;/code&gt; function will handle dependencies within R &amp;ndash; i.e., it will install other R packages
that your package depends on. Occasionally, when the install function needs to compile
a package from source, errors arise that relate to missing system dependencies (i.e. software outside of R).&lt;/p&gt;
&lt;p&gt;On &lt;strong&gt;Mac&lt;/strong&gt; and &lt;strong&gt;Linux&lt;/strong&gt;, these system dependencies are best installed outside of R,
such as with &lt;code&gt;homebrew&lt;/code&gt; on Mac or &lt;code&gt;apt&lt;/code&gt; on Ubuntu.
The errror message you got when trying to install an R package should tell you which system dependencies are needed.&lt;/p&gt;
&lt;p&gt;On Windows, you can use the &lt;code&gt;installr&lt;/code&gt; package to install such dependencies or other software from within R &amp;ndash; for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;installr&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;    &lt;span class=&#34;c1&#34;&gt;# Install the installr package first&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;installlr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;install.RStudio&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;    &lt;span class=&#34;c1&#34;&gt;# Install RStudio&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;installr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;install.python&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;      &lt;span class=&#34;c1&#34;&gt;# Install Python&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;
&lt;h4 id=&#34;system-setup-to-installing-packages-from-source&#34;&gt;System setup to installing packages &amp;ldquo;from source&amp;rdquo;&lt;/h4&gt;
&lt;p&gt;Sometimes you need to install a package from source, that is,
you need to compile the package rather than simply installing a pre-existing binary.
(On &lt;strong&gt;Linux&lt;/strong&gt;, where installing from source is often needed, this should work without additional steps.)
On &lt;strong&gt;Windows&lt;/strong&gt; and &lt;strong&gt;Mac&lt;/strong&gt;, installing from source is generally only needed when you
install a package from outside of CRAN (such as from Github, see below),
&lt;em&gt;but&lt;/em&gt; you will need to make sure you have the following non-R software:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;On &lt;strong&gt;Windows&lt;/strong&gt;, you will need &lt;em&gt;Rtools&lt;/em&gt; (&lt;a href=&#34;http://cran.r-project.org/bin/windows/Rtools/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Rtools installation instructions&lt;/a&gt;).&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;On a Mac, you will need &lt;em&gt;Xcode&lt;/em&gt; (which can be installed from the Mac App store).&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can test whether or not you are able to install packages from source using the &lt;em&gt;devtools&lt;/em&gt; package:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;devtools&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;    &lt;span class=&#34;c1&#34;&gt;# Install the devtools package&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;devtools&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;has_devel&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;           &lt;span class=&#34;c1&#34;&gt;# Check whether you can install packages from source&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;For a bit more info, see &lt;a href=&#34;https://rstats.wtf/set-up-an-r-dev-environment.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this page&lt;/a&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;installing-packages-from-github&#34;&gt;Installing packages from Github&lt;/h4&gt;
&lt;p&gt;To install a package from Github, use either the &lt;em&gt;devtools&lt;/em&gt; or the &lt;em&gt;remotes&lt;/em&gt; package &amp;ndash; for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;devtools&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;                &lt;span class=&#34;c1&#34;&gt;# Install the devtools package&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;devtools&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;install_github&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;kbroman/broman&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Install from a repository using &amp;#34;&amp;lt;username&amp;gt;/&amp;lt;repo-name&amp;gt;&amp;#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will install the package &lt;em&gt;from source&lt;/em&gt;, so you will need to make sure you are able to do so
by following the instructions in the section right above this one.&lt;/p&gt;
&lt;br&gt;
&lt;h4 id=&#34;installing-packages-from-bioconductor&#34;&gt;Installing packages from Bioconductor&lt;/h4&gt;
&lt;p&gt;If you&amp;rsquo;re doing bioinformatic analyses in R, you will probably run into packages
that are not on CRAN but on &lt;a href=&#34;https://bioconductor.org/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Bioconductor&lt;/a&gt;.
To install a package from Bioconductor, use the &lt;em&gt;BiocManager&lt;/em&gt; package &amp;ndash; for example:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;BiocManager&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;  &lt;span class=&#34;c1&#34;&gt;# Install the BiocManager package&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;BiocManager&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;install&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;edgeR&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;    &lt;span class=&#34;c1&#34;&gt;# Install the edgeR package from Bioconductor&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;br&gt;
&lt;h3 id=&#34;updating-r&#34;&gt;Updating R&lt;/h3&gt;
&lt;p&gt;Consider updating R if you have an older version of R installed.
&lt;strong&gt;Specifically, in the first session of Code Club, we&amp;rsquo;ve seen problems when installing
the &lt;em&gt;tidyverse&lt;/em&gt; with R versions below &lt;code&gt;R 3.6&lt;/code&gt;.&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;You can check which version of R you have by looking at the first lines of
output when running the following command inside R:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;sessionInfo&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;to-update&#34;&gt;To update:&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Windows&lt;/strong&gt;: You can update R from within R. The &lt;code&gt;updateR()&lt;/code&gt; function will also take care
of updating your packages:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;installr&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;n&#34;&gt;installr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;updateR&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Mac&lt;/strong&gt;: Download and install the latest &lt;code&gt;.pkg&lt;/code&gt; file as if you were installing it for the first time.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Linux&lt;/strong&gt;: In Ubuntu, if you installed R with &lt;code&gt;apt&lt;/code&gt; or &lt;code&gt;apt-get&lt;/code&gt;, you can use &lt;code&gt;apt-get upgrade&lt;/code&gt; in a terminal.
Otherwise, download and install the latest version after removing the old one.
&lt;a href=&#34;https://rtask.thinkr.fr/installation-of-r-4-0-on-ubuntu-20-04-lts-and-tips-for-spatial-packages/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Rtask has some instructions&lt;/a&gt; for upgrading to
R 4.0 in Ubuntu (along with upgrading to Ubuntu 20.04).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;h4 id=&#34;re-installing-your-packages-after-updating-mac-and-linux&#34;&gt;Re-installing your packages after updating (Mac and Linux)&lt;/h4&gt;
&lt;p&gt;While the &lt;code&gt;installr::updateR()&lt;/code&gt; function for &lt;strong&gt;Windows&lt;/strong&gt; users takes care of reinstalling
your packages along with updating R,
&lt;strong&gt;Mac&lt;/strong&gt; and &lt;strong&gt;Linux&lt;/strong&gt; users will have to manually re-install their packages.
Some people prefer to re-install these packages on the fly, which can end up being a way
to get rid of packages you no longer use.&lt;/p&gt;
&lt;p&gt;But if you want immediately reinstall all your packages, run this before you upgrade:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;my_packages&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;installed.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;saveRDS&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;my_packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;my_packages.rds&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Then, after you&amp;rsquo;ve installed the latest R version:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;my_packages&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;&amp;lt;-&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;readRDS&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;CurrentPackages.rds&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;my_packages[1&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;]&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will only work for packages available on CRAN. Of course, you can check your list
for Github-only and Bioconductor packages and then install those with their respective commands
(see below). Yes, this can be a bit of a hassle!&lt;/p&gt;
&lt;p&gt;&lt;br/&gt; &lt;br/&gt; &lt;br/&gt;&lt;/p&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://biodash.github.io/events/2023-02_aws/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/events/2023-02_aws/</guid>
      <description>&lt;h1 id=&#34;online-aws-workshop&#34;&gt;Online AWS Workshop&lt;/h1&gt;
&lt;p&gt;Tuesday, February 28th, 2023 &amp;ndash; 3-5 pm &amp;ndash; online-only&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;p&gt;Code Club will organize a free workshop from 3-5 pm on Amazon Web Services (AWS),
led by AWS instructors.
The workshop will take place on Tuesday February 28th, 2023, from 3-5 pm.&lt;/p&gt;
&lt;h3 id=&#34;why-cloud-computing-with-aws&#34;&gt;Why cloud computing with AWS?&lt;/h3&gt;
&lt;p&gt;When you are working with datasets that are too large to be analyzed with your
personal computer,
you&amp;rsquo;ll need access to a more powerful infrastructure.&lt;/p&gt;
&lt;p&gt;At Ohio State, we are lucky to have access to the excellent high-performance
computing resources at the Ohio Supercomputer Center (OSC) HPC,
but another way to access such resources is with &amp;ldquo;cloud computing&amp;rdquo; services,
such as those offered by Amazon Web Services (AWS).&lt;/p&gt;
&lt;p&gt;Some advantages of cloud computing over HPCs include that it&amp;rsquo;s available
globally with the same interface,
that there&amp;rsquo;s a wider array of resources for specific requirements,
that there is no &amp;ldquo;queuing&amp;rdquo; of compute jobs,
and that you have full administrative rights to the cloud machine you are using.&lt;/p&gt;
&lt;h3 id=&#34;workshop-description&#34;&gt;Workshop description&lt;/h3&gt;
&lt;p&gt;Here is what will be covered during this general immersion day on AWS:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;High level introduction to the AWS cloud and an overview of the
Elastic Compute Cloud (EC2) &lt;em&gt;[15 mins]&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Launching, configuring, and customizing a web server on Amazon EC2 using the
AWS Management Console (Lab) &lt;em&gt;[45 mins]&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Details on AWS storage products and features such as EBS, S3, EFS, Glacier &lt;em&gt;[15 mins]&lt;/em&gt;&lt;/li&gt;
&lt;li&gt;Simple Storage Service (S3) Hands on Lab.
In this lab, you will create an S3 bucket,
add objects to your bucket, and access the data from EC2 &lt;em&gt;[45 mins]&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;practicalities&#34;&gt;Practicalities&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The workshop will be online-only, via Zoom
(we&amp;rsquo;ll send the link when you sign up).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The workshop is free, and anyone at OSC can join.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You don&amp;rsquo;t need an AWS account, any specific software,
or any specific experience to participate.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Please use the form below to sign up!&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Thanks to Code Club participant Margo Freed for suggesting this workshop
and helping to organize it!&lt;/p&gt;
&lt;h3 id=&#34;sign-up&#34;&gt;Sign up&lt;/h3&gt;
&lt;p&gt;To sign up for the AWS workshop, please fill out the Google Form below.&lt;/p&gt;
&lt;iframe src=&#34;https://docs.google.com/forms/d/e/1FAIpQLSfX3OdSi5z7V6uPc1mwnj5NMZjIlEe_bvdfWE4XOZkCzrfdhA/viewform?embedded=true&#34; width=&#34;800&#34; height=&#34;1404&#34; frameborder=&#34;0&#34; marginheight=&#34;0&#34; marginwidth=&#34;0&#34;&gt;Loading…&lt;/iframe&gt;
&lt;p&gt;&lt;br&gt; &lt;br&gt;&lt;/p&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://biodash.github.io/suggest/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/suggest/</guid>
      <description>&lt;h1 id=&#34;suggest-a-topic-or-event&#34;&gt;Suggest a topic or event&lt;/h1&gt;
&lt;hr&gt;
&lt;br&gt;
&lt;p&gt;If there is a topic you would like to see covered on this website,
an event you would like to see happen,
or an event you think should be listed under &lt;a href=&#34;https://biodash.github.io/events/&#34;&gt;Events&lt;/a&gt;,
please fill out the form below.
You can also indicate whether you would like to help with this content or event!&lt;/p&gt;
&lt;iframe src=&#34;https://docs.google.com/forms/d/e/1FAIpQLSe13_VaCw5lMBgckIYrrU22wXcq5krMRjA9V_3dobcCt7UV6Q/viewform?embedded=true&#34; width=&#34;640&#34; height=&#34;1046&#34; frameborder=&#34;0&#34; marginheight=&#34;0&#34; marginwidth=&#34;0&#34;&gt;Loading…&lt;/iframe&gt;
&lt;p&gt;&lt;br/&gt; &lt;br/&gt; &lt;br/&gt;&lt;/p&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://biodash.github.io/support/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/support/</guid>
      <description>&lt;h1 id=&#34;bioinformatics-support&#34;&gt;Bioinformatics support&lt;/h1&gt;
&lt;hr&gt;
&lt;br&gt;
&lt;h2 id=&#34;available-support&#34;&gt;Available support&lt;/h2&gt;
&lt;p&gt;Need assistance with bioinformatics, high-throughput sequencing data analysis, working with big data, etc?
See below for some support options for OSU researchers.&lt;/p&gt;
&lt;h3 id=&#34;mcic&#34;&gt;MCIC&lt;/h3&gt;
&lt;p&gt;The &lt;a href=&#34;https://mcic.osu.edu/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Molecular and Cellular Imaging Center (MCIC)&lt;/a&gt;
is an OSU core facility with locations at the Wooster and Columbus campuses.
Among other things, the MCIC provides end-to-end support for genomics projects &amp;mdash;
from experimental design, library preparation, and sequencing,
to infrastructure for and assistance with data analysis.&lt;/p&gt;
&lt;p&gt;The bioinformatics section of the MCIC, the &lt;a href=&#34;%28https://mcic.osu.edu/bioinformatics%29&#34;&gt;MCBL (MCIC Computational Biology Laboratory)&lt;/a&gt;,
works based on a membership model. MCBL members have access to bioinformatics support,
our project at the Ohio Supercomputer Center for storage and computing,
our two in-house servers, our computer lab in Wooster,
and free access to workshops.
To become a member, please fill out &lt;a href=&#34;https://mcic.osu.edu/bioinformatics/mcbl-registration-form&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;this form&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;For bioinformatics consultation,
feel free to contact &lt;a href=&#34;mailto:poelstra.1@osu.edu&#34;&gt;Jelmer Poelstra&lt;/a&gt;.&lt;/p&gt;
&lt;h3 id=&#34;eeob&#34;&gt;EEOB&lt;/h3&gt;
&lt;p&gt;Research Scientist Michael Broe provides bioinformatics support to faculty and students in the Department of Evolution, Ecology and Organismal Biology. His primary role is to assist graduate students learning various types of computational analysis, but he also works directly with PIs. Types of analysis include whole genome assembly, genome annotation, transcriptomics, RADseq, hybrid capture pipelines, variant calling etc. Michael also teaches a 7 week Introduction to Computation in Biology for incoming EEOB graduate students each year, covering R, Python, and Unix.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;request-support&#34;&gt;Request support&lt;/h2&gt;
&lt;iframe src=&#34;https://docs.google.com/forms/d/e/1FAIpQLSfC-g3YSG84KBerEwRLilje4kz7-9WRIevzHAUNTMQKgKmCuQ/viewform?embedded=true&#34; width=&#34;640&#34; height=&#34;1078&#34; frameborder=&#34;0&#34; marginheight=&#34;0&#34; marginwidth=&#34;0&#34;&gt;Loading…&lt;/iframe&gt;
&lt;p&gt;&lt;br/&gt; &lt;br/&gt; &lt;br/&gt;&lt;/p&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title></title>
      <link>https://biodash.github.io/tutorials/2021-01_rnaseq/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/tutorials/2021-01_rnaseq/</guid>
      <description>&lt;h1 id=&#34;an-introduction-to-rna-seq-br-data-processing-and-analysis&#34;&gt;An introduction to RNA-seq &lt;br&gt; data processing and analysis&lt;/h1&gt;
&lt;hr&gt;
&lt;br&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Date&lt;/th&gt;
&lt;th&gt;Topic&lt;/th&gt;
&lt;th&gt;Slides&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;2021-01-08&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Introductory notes on RNA-seq and NGS data&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;01-rnaseq_intro.html&#34; target=&#34;_blank&#34;&gt;&lt;span style=&#34;color: #4b5357;&#34;&gt;&lt;i class=&#34;fas fa-desktop fa-lg&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2021-01-29&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Running FastQC for many files at OSC&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;02-fastqc-run.html&#34; target=&#34;_blank&#34;&gt;&lt;span style=&#34;color: #4b5357;&#34;&gt;&lt;i class=&#34;fas fa-desktop fa-lg&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2021-02-05&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Interpreting FastQC output&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;03-fastqc-output.html&#34; target=&#34;_blank&#34;&gt;&lt;span style=&#34;color: #4b5357;&#34;&gt;&lt;i class=&#34;fas fa-desktop fa-lg&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2021-02-12&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Running MultiQC&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;04-multiqc.html&#34; target=&#34;_blank&#34;&gt;&lt;span style=&#34;color: #4b5357;&#34;&gt;&lt;i class=&#34;fas fa-desktop fa-lg&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2021-02-17&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Preprocessing FASTQ files&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;02-preprocess-fastq.html&#34; target=&#34;_blank&#34;&gt;&lt;span style=&#34;color: #4b5357;&#34;&gt;&lt;i class=&#34;fas fa-desktop fa-lg&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2021-02-17&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Intro to RNAseq alignment and STAR&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;05-star-index.html&#34; target=&#34;_blank&#34;&gt;&lt;span style=&#34;color: #4b5357;&#34;&gt;&lt;i class=&#34;fas fa-desktop fa-lg&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2021-02-26&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;RNAseq read alignment with STAR&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;06-star-align.html&#34; target=&#34;_blank&#34;&gt;&lt;span style=&#34;color: #4b5357;&#34;&gt;&lt;i class=&#34;fas fa-desktop fa-lg&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2021-03-05&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Getting to know BAM files&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;07-bam.html&#34; target=&#34;_blank&#34;&gt;&lt;span style=&#34;color: #4b5357;&#34;&gt;&lt;i class=&#34;fas fa-desktop fa-lg&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2021-03-12/19&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Creating a gene count table with feautureCounts&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;08-featureCounts.html&#34; target=&#34;_blank&#34;&gt;&lt;span style=&#34;color: #4b5357;&#34;&gt;&lt;i class=&#34;fas fa-desktop fa-lg&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2021-03-26&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Differential expression analysis with DESeq2 &amp;ndash; Part I&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;09-DE.html&#34; target=&#34;_blank&#34;&gt;&lt;span style=&#34;color: #4b5357;&#34;&gt;&lt;i class=&#34;fas fa-desktop fa-lg&#34;&gt;&lt;/i&gt;&lt;/span&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;br/&gt; &lt;br/&gt; &lt;br/&gt;&lt;/p&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>About the BioDASH website</title>
      <link>https://biodash.github.io/about/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/about/</guid>
      <description>&lt;br&gt;
&lt;p&gt;The BioDASH website aims to assemble bioinformatic and computational training resources for researchers at The Ohio State University.
It&amp;rsquo;s a joint initiative by bioinformaticians at OSU&amp;rsquo;s &lt;a href=&#34;https://mcic.osu.edu/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Molecular and Cellular Imaging Center (MCIC)&lt;/a&gt; - &lt;a href=&#34;https://mcbl.readthedocs.io/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Computational Biology Lab&lt;/a&gt;, the &lt;a href=&#34;https://caps.osu.edu/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Center for Applied Plant Sciences (CAPS)&lt;/a&gt;,
and the &lt;a href=&#34;https://eeob.osu.edu/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Department of Evolution, Ecology and Organismal Biology (EEOB)&lt;/a&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;h2 id=&#34;main-contributors&#34;&gt;Main Contributors&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://biodash.github.io/authors/admin/&#34;&gt;Jelmer Poelstra, MCIC Wooster&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://biodash.github.io/authors/mike-sovic/&#34;&gt;Mike Sovic, CAPS&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;https://biodash.github.io/authors/michael-broe/&#34;&gt;Michael Broe, EEOB&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;h2 id=&#34;suggest-a-topic-or-event&#34;&gt;Suggest a topic or event&lt;/h2&gt;
&lt;p&gt;If there is a topic you would like to see covered on this website,
an OSU event you would like to see happen,
or an event you think should be listed under &lt;a href=&#34;https://biodash.github.io/events/&#34;&gt;Events&lt;/a&gt;,
please fill out the form below.
You can also indicate whether you would like to help with this content or event!&lt;/p&gt;
&lt;iframe src=&#34;https://docs.google.com/forms/d/e/1FAIpQLSe13_VaCw5lMBgckIYrrU22wXcq5krMRjA9V_3dobcCt7UV6Q/viewform?embedded=true&#34; width=&#34;640&#34; height=&#34;1046&#34; frameborder=&#34;0&#34; marginheight=&#34;0&#34; marginwidth=&#34;0&#34;&gt;Loading…&lt;/iframe&gt;
&lt;p&gt;&lt;br/&gt; &lt;br/&gt; &lt;br/&gt;&lt;/p&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Computer Setup for Code Club</title>
      <link>https://biodash.github.io/codeclub-setup/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub-setup/</guid>
      <description>&lt;hr&gt;
&lt;br&gt;
&lt;p&gt;Here, you will find general information about computer setup for Code Club.
Additional setup instructions for individual sessions will appear in the posts for each session.&lt;/p&gt;
&lt;h2 id=&#34;summary&#34;&gt;Summary&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Install R and RStudio
(if you have an older version of R, then consider &lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/#updating-r&#34;&gt;updating R&lt;/a&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Install the &lt;em&gt;tidyverse&lt;/em&gt; package and test if you can load it.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Prefer not to install anything locally?
&lt;a href=&#34;mailto:poelstra.1@osu.edu&#34;&gt;Contact Jelmer&lt;/a&gt; to be added to the Ohio Supercomputer project for Code Club.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Run into issues or have questions?&lt;/strong&gt;
Don&amp;rsquo;t hesitate to &lt;a href=&#34;mailto:poelstra.1@osu.edu&#34;&gt;contact Jelmer&lt;/a&gt; or
one of the other organizers.
You can also come to Code Club Zoom 15 minutes early,
and one or more of the organizers should be there already.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;local&#34;&gt;Local installation&lt;/h2&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h3 id=&#34;already-have-r-installed&#34;&gt;Already have R installed?&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Please check your version of R &amp;ndash; this information is printed to the console
when you start R, and you can also get it by typing &lt;code&gt;sessionInfo()&lt;/code&gt; and checking
the first line of the output.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Currently (January 2023), we would recommend R version &lt;code&gt;4.2.0&lt;/code&gt; or higher.
And since we&amp;rsquo;ll work with the &amp;ldquo;base R pipe&amp;rdquo;,
you&amp;rsquo;ll definitely need version &lt;code&gt;4.1.0&lt;/code&gt; or higher.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To update R, &lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/#updating-r&#34;&gt;see this page for instructions&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Make sure you have installed the &lt;em&gt;tidyverse&lt;/em&gt; package (try &lt;code&gt;library(tidyverse)&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;h3 id=&#34;install-r&#34;&gt;Install R&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Windows&lt;/strong&gt;: Download and run the &lt;code&gt;.exe&lt;/code&gt; file for the latest version of R from &lt;a href=&#34;https://cran.r-project.org/bin/windows/base/&#34;&gt;https://cran.r-project.org/bin/windows/base/&lt;/a&gt;,
by clicking the large &lt;code&gt;Download R [version-number] for Windows&lt;/code&gt; link at the top of the gray box.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Mac&lt;/strong&gt;: Download and run the &lt;code&gt;.pkg&lt;/code&gt; file for the latest version of R from &lt;a href=&#34;https://cran.r-project.org/bin/macosx/&#34;&gt;https://cran.r-project.org/bin/macosx/&lt;/a&gt;,
by clicking the link just below &lt;code&gt;Latest release&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;On a &lt;strong&gt;Linux&lt;/strong&gt; distribution, you can also install R using the website above, but you may prefer to use
a package manager instead &amp;ndash; for instance, seee &lt;a href=&#34;https://linuxize.com/post/how-to-install-r-on-ubuntu-20-04/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;these instructions&lt;/a&gt;
for installing the latest R version on Ubuntu 20.04 using the &lt;code&gt;apt&lt;/code&gt; package manager.&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;install-rstudio&#34;&gt;Install RStudio&lt;/h3&gt;
&lt;p&gt;RStudio is a so-called Integrated Development Environment (IDE) for R,
with side-by-side panes for an R script, an R concole, plots, help documents, and much more.
While it is perfectly possible to use R without RStudio, RStudio has become
the de facto standard for working with R and is very useful.&lt;/p&gt;
&lt;p&gt;To install RStudio, go to the &lt;a href=&#34;https://rstudio.com/products/rstudio/download/#download&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;RStudio download page&lt;/a&gt;
and download and run the installer file for your operating system.&lt;/p&gt;
&lt;h3 id=&#34;install-tidy&#34;&gt;Install the &lt;em&gt;tidyverse&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;To install or update the &lt;em&gt;tidyverse&lt;/em&gt;, which is a collection of useful R packages,
copy the following command into an R console, and press Enter:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;tidyverse&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;test-tidy&#34;&gt;Test whether you can load the &lt;em&gt;tidyverse&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;When you issue the command &lt;code&gt;library(tidyverse)&lt;/code&gt; in your R console inside RStudio,
you should get output similar to what is shown below:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tidyverse&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

── &lt;span class=&#34;n&#34;&gt;Attaching&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;packages&lt;/span&gt; ──────────────────────────────────────────────────────────
───────────────────────────────────────────── &lt;span class=&#34;n&#34;&gt;tidyverse&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1.3.1&lt;/span&gt; ──
✔ &lt;span class=&#34;n&#34;&gt;ggplot2&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;3.3.6&lt;/span&gt;     ✔ &lt;span class=&#34;n&#34;&gt;purrr&lt;/span&gt;   &lt;span class=&#34;m&#34;&gt;0.3.4&lt;/span&gt;
✔ &lt;span class=&#34;n&#34;&gt;tibble&lt;/span&gt;  &lt;span class=&#34;m&#34;&gt;3.1.7&lt;/span&gt;     ✔ &lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;   &lt;span class=&#34;m&#34;&gt;1.0.9&lt;/span&gt;
✔ &lt;span class=&#34;n&#34;&gt;tidyr&lt;/span&gt;   &lt;span class=&#34;m&#34;&gt;1.2.0&lt;/span&gt;     ✔ &lt;span class=&#34;n&#34;&gt;stringr&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1.4.0&lt;/span&gt;
✔ &lt;span class=&#34;n&#34;&gt;readr&lt;/span&gt;   &lt;span class=&#34;m&#34;&gt;2.1.2&lt;/span&gt;     ✔ &lt;span class=&#34;n&#34;&gt;forcats&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0.5.1&lt;/span&gt;
── &lt;span class=&#34;n&#34;&gt;Conflicts&lt;/span&gt; ───────────────────────────────────────────────────────────────────
─────────────────────────────────────── &lt;span class=&#34;nf&#34;&gt;tidyverse_conflicts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; ──
✖ &lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;masks&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;stats&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
✖ &lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;lag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;    &lt;span class=&#34;n&#34;&gt;masks&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;stats&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;lag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you get an error instead, please try to troubleshoot it by following any instructions
given, or by Googling the error message.
It may be necessary to update R itself, see &lt;a href=&#34;https://biodash.github.io/codeclub-novice/#updating-r&#34;&gt;here&lt;/a&gt; for instructions.
You can also send the &lt;a href=&#34;https://biodash.github.io/codeclub-about/#organizers&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;organizers of Code Club&lt;/a&gt; an email.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;osc&#34;&gt;Alternative: Use RStudio Server at OSC&lt;/h2&gt;
&lt;p&gt;Upon request (&lt;a href=&#34;mailto:poelstra.1@osu.edu&#34;&gt;contact Jelmer&lt;/a&gt;),
you can get access to the &lt;a href=&#34;http://osc.edu&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Ohio Supercomputer Center (OSC)&lt;/a&gt;
Classroom Project for Code Club (&lt;code&gt;PAS1838&lt;/code&gt;).
This way, you can code in RStudio from your browser rather than with a local installation.
This is a good option if you prefer not to install anything or if you run
into problems during installations.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;After you asked for access to the OSC project,
you should receive an email from OSC that you have been added to the Code Club OSC project.&lt;/strong&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;If you already have an OSC account&lt;/em&gt;,
you shouldn&amp;rsquo;t need to do anything to gain access,
although the email may ask you to confirm/accept your being added to project.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;em&gt;If you do not yet have an OSC account&lt;/em&gt;,
the email you received from OSC should have a link to do so.
Alternatively, follow the instructions below to sign up and get access to the project.&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Instructions to sign up at OSC (click here)
&lt;/summary&gt;
&lt;p&gt;To sign up:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Go to &lt;a href=&#34;https://my.osc.edu/&#34;&gt;https://my.osc.edu/&lt;/a&gt; and click the blue &amp;ldquo;&lt;em&gt;Sign Up&lt;/em&gt;&amp;rdquo; bar.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In the bottom right portion of the form where you provide your info (see screenshot below),
you should enter Code Club&amp;rsquo;s Project Code, which is &lt;code&gt;PAS1838&lt;/code&gt;.
&lt;strong&gt;If you want to use OSC, please do this on a day prior to your first Code Club participation.&lt;/strong&gt;
This way, there is time to troubleshoot if needed. Moreover, the &lt;code&gt;Code Club&lt;/code&gt; option on the
Interactive Apps page below can take a few hours to appear after you become a member of the project.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;














&lt;figure  id=&#34;figure-enter-project-code-pas1838-in-the-red-box-click-to-enlarge&#34;&gt;
  &lt;div class=&#34;d-flex justify-content-center&#34;&gt;
    &lt;div class=&#34;w-100&#34; &gt;
        &lt;img alt=&#34;Enter Project Code PAS1838 in the red box (click to enlarge)&#34; srcset=&#34;
               /codeclub-setup/osc_signup2_hua473c09b47dfb2ad5c85dfdabf5fb37e_191989_48633aab0d4689e76c11fd860130b602.png 400w,
               /codeclub-setup/osc_signup2_hua473c09b47dfb2ad5c85dfdabf5fb37e_191989_2b36e8feff1616616e4ed73973a582e3.png 760w,
               /codeclub-setup/osc_signup2_hua473c09b47dfb2ad5c85dfdabf5fb37e_191989_1200x1200_fit_lanczos_2.png 1200w&#34;
               src=&#34;https://biodash.github.io/codeclub-setup/osc_signup2_hua473c09b47dfb2ad5c85dfdabf5fb37e_191989_48633aab0d4689e76c11fd860130b602.png&#34;
               width=&#34;600px&#34;
               height=&#34;352&#34;
               loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;figcaption&gt;
      Enter Project Code PAS1838 in the red box (click to enlarge)
    &lt;/figcaption&gt;&lt;/figure&gt;
&lt;/details&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h3 id=&#34;osc-run-rstudio&#34;&gt;Run RStudio Server from the OSC website&lt;/h3&gt;
&lt;p&gt;&lt;a href=&#34;https://ondemand.osc.edu/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;OSC OnDemand&lt;/a&gt; lets you access OSC resources through your
browser and run applications like RStudio.
It has a separate access point, &lt;a href=&#34;https://class.osc.edu/&#34;&gt;https://class.osc.edu/&lt;/a&gt;,
for &amp;ldquo;classroom projects&amp;rdquo; such as this one.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;To get started, go to &lt;a href=&#34;https://class.osc.edu/&#34;&gt;https://class.osc.edu/&lt;/a&gt; and log in with your OSC username and password.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click on &lt;code&gt;Apps&lt;/code&gt; in the blue top bar, and select &lt;code&gt;RStudio Server: Form&lt;/code&gt;, as shown below:&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;














&lt;figure  &gt;
  &lt;div class=&#34;d-flex justify-content-center&#34;&gt;
    &lt;div class=&#34;w-100&#34; &gt;
        &lt;img alt=&#34;&#34; srcset=&#34;
               /codeclub-setup/osc_rstudio-app_hu5d2794141d30b7e06cc47ba981a2b8c2_1459090_c37f4e17ece95eafcfd184f7e6a0cf91.png 400w,
               /codeclub-setup/osc_rstudio-app_hu5d2794141d30b7e06cc47ba981a2b8c2_1459090_b38b19dac7d661ce74479fc75e9df71c.png 760w,
               /codeclub-setup/osc_rstudio-app_hu5d2794141d30b7e06cc47ba981a2b8c2_1459090_1200x1200_fit_lanczos_2.png 1200w&#34;
               src=&#34;https://biodash.github.io/codeclub-setup/osc_rstudio-app_hu5d2794141d30b7e06cc47ba981a2b8c2_1459090_c37f4e17ece95eafcfd184f7e6a0cf91.png&#34;
               width=&#34;600px&#34;
               height=&#34;292&#34;
               loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;ol start=&#34;3&#34;&gt;
&lt;li&gt;
&lt;p&gt;Now, you&amp;rsquo;re on a page from which you can launch an RStudio server that will run on an OSC cluster.
As shown below, make sure that &amp;ldquo;Code Club&amp;rdquo; is selected under &lt;code&gt;Class Materials&lt;/code&gt;,
and change the select &lt;code&gt;Number of hours&lt;/code&gt; to 2. Then click &lt;code&gt;Launch&lt;/code&gt;.&lt;/p&gt;














&lt;figure  &gt;
  &lt;div class=&#34;d-flex justify-content-center&#34;&gt;
    &lt;div class=&#34;w-100&#34; &gt;
        &lt;img alt=&#34;&#34; srcset=&#34;
               /codeclub-setup/osc_rstudio-form_hub6d2809d2996a4828d802ebfd109f6b6_55951_b72a8d76a2ea58673524d755355078c8.png 400w,
               /codeclub-setup/osc_rstudio-form_hub6d2809d2996a4828d802ebfd109f6b6_55951_784d94ada379ef5765f29dd2713533af.png 760w,
               /codeclub-setup/osc_rstudio-form_hub6d2809d2996a4828d802ebfd109f6b6_55951_1200x1200_fit_lanczos_2.png 1200w&#34;
               src=&#34;https://biodash.github.io/codeclub-setup/osc_rstudio-form_hub6d2809d2996a4828d802ebfd109f6b6_55951_b72a8d76a2ea58673524d755355078c8.png&#34;
               width=&#34;500px&#34;
               height=&#34;487&#34;
               loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You should see a box like this:&lt;/p&gt;














&lt;figure  &gt;
  &lt;div class=&#34;d-flex justify-content-center&#34;&gt;
    &lt;div class=&#34;w-100&#34; &gt;
        &lt;img alt=&#34;&#34; srcset=&#34;
               /codeclub-setup/osc_queued_huc3ed6df64fbea5dadc1acb0cb07e10cb_56181_902905312ca4907660451da833ceef12.png 400w,
               /codeclub-setup/osc_queued_huc3ed6df64fbea5dadc1acb0cb07e10cb_56181_39b9a2588d5225b8dab247e6d67b9f9f.png 760w,
               /codeclub-setup/osc_queued_huc3ed6df64fbea5dadc1acb0cb07e10cb_56181_1200x1200_fit_lanczos_2.png 1200w&#34;
               src=&#34;https://biodash.github.io/codeclub-setup/osc_queued_huc3ed6df64fbea5dadc1acb0cb07e10cb_56181_902905312ca4907660451da833ceef12.png&#34;
               width=&#34;600px&#34;
               height=&#34;248&#34;
               loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Your job usually starts running within seconds, and the color of the top
bar will then switch from blue (&amp;ldquo;Queued&amp;rdquo; and then &amp;ldquo;Starting&amp;rdquo;) to green (&amp;ldquo;Running&amp;rdquo;):&lt;/p&gt;














&lt;figure  &gt;
  &lt;div class=&#34;d-flex justify-content-center&#34;&gt;
    &lt;div class=&#34;w-100&#34; &gt;
        &lt;img alt=&#34;&#34; srcset=&#34;
               /codeclub-setup/osc_running_hu32aac4d5b44ea72be94473389cd43207_52763_7b33c269991f7d644b63865a1e99840f.png 400w,
               /codeclub-setup/osc_running_hu32aac4d5b44ea72be94473389cd43207_52763_96b087f3b9a65b243692b16660660d3c.png 760w,
               /codeclub-setup/osc_running_hu32aac4d5b44ea72be94473389cd43207_52763_1200x1200_fit_lanczos_2.png 1200w&#34;
               src=&#34;https://biodash.github.io/codeclub-setup/osc_running_hu32aac4d5b44ea72be94473389cd43207_52763_7b33c269991f7d644b63865a1e99840f.png&#34;
               width=&#34;600px&#34;
               height=&#34;250&#34;
               loading=&#34;lazy&#34; data-zoomable /&gt;&lt;/div&gt;
  &lt;/div&gt;&lt;/figure&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Click &lt;code&gt;Connect to RStudio Server&lt;/code&gt; at the bottom of the box,
and an RStudio Server instance will open.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id=&#34;test-whether-you-can-load-the-tidyverse&#34;&gt;Test whether you can load the &lt;em&gt;tidyverse&lt;/em&gt;&lt;/h3&gt;
&lt;p&gt;Several commonly used packages will be automatically available to you at OSC,
and that should include the &lt;em&gt;tidyverse&lt;/em&gt;.
Test whether you can load the &lt;em&gt;tidyverse&lt;/em&gt; by running &lt;code&gt;library(tidyverse)&lt;/code&gt;,
and check whether you get output similar to what is shown below
(exact versions of packages may differ):&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;tidyverse&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;

── &lt;span class=&#34;n&#34;&gt;Attaching&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;packages&lt;/span&gt; ──────────────────────────────────────────────────────────
───────────────────────────────────────────── &lt;span class=&#34;n&#34;&gt;tidyverse&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1.3.1&lt;/span&gt; ──
✔ &lt;span class=&#34;n&#34;&gt;ggplot2&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;3.3.6&lt;/span&gt;     ✔ &lt;span class=&#34;n&#34;&gt;purrr&lt;/span&gt;   &lt;span class=&#34;m&#34;&gt;0.3.4&lt;/span&gt;
✔ &lt;span class=&#34;n&#34;&gt;tibble&lt;/span&gt;  &lt;span class=&#34;m&#34;&gt;3.1.7&lt;/span&gt;     ✔ &lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;   &lt;span class=&#34;m&#34;&gt;1.0.9&lt;/span&gt;
✔ &lt;span class=&#34;n&#34;&gt;tidyr&lt;/span&gt;   &lt;span class=&#34;m&#34;&gt;1.2.0&lt;/span&gt;     ✔ &lt;span class=&#34;n&#34;&gt;stringr&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;1.4.0&lt;/span&gt;
✔ &lt;span class=&#34;n&#34;&gt;readr&lt;/span&gt;   &lt;span class=&#34;m&#34;&gt;2.1.2&lt;/span&gt;     ✔ &lt;span class=&#34;n&#34;&gt;forcats&lt;/span&gt; &lt;span class=&#34;m&#34;&gt;0.5.1&lt;/span&gt;
── &lt;span class=&#34;n&#34;&gt;Conflicts&lt;/span&gt; ───────────────────────────────────────────────────────────────────
─────────────────────────────────────── &lt;span class=&#34;nf&#34;&gt;tidyverse_conflicts&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; ──
✖ &lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;masks&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;stats&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;filter&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
✖ &lt;span class=&#34;n&#34;&gt;dplyr&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;lag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;    &lt;span class=&#34;n&#34;&gt;masks&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;stats&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;lag&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;If you get an error, install the &lt;em&gt;tidyverse&lt;/em&gt; as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;tidyverse&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;osc-more&#34;&gt;More about OSC&lt;/h3&gt;
&lt;p&gt;The above instructions should be all you need to access RStudio using OSC,
but there is lot more to OSC than that!
For more information about using OSC, see the excellent &lt;a href=&#34;https://www.osc.edu/resources/getting_started&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Getting Started materials&lt;/a&gt;
on their website (make sure not to miss the &lt;a href=&#34;https://www.osc.edu/resources/getting_started/howto&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;HOWTOs&lt;/a&gt;).
Also, Mike Sovic has a &lt;a href=&#34;https://www.youtube.com/playlist?list=PLxhIMi78eQeiJ0p7REEU5i7kJK3Vk2ek3&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;YouTube playlist &amp;ldquo;Getting Started With High Performance
Computing (HPC)&amp;quot;&lt;/a&gt;
at his channel &lt;a href=&#34;https://www.youtube.com/channel/UC2dB6jDTbqzlTM6edzfBSGQ&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;The Data Point&lt;/a&gt;.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;more&#34;&gt;More info&lt;/h2&gt;
&lt;p&gt;Please see our &lt;strong&gt;&lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/&#34;&gt;R Resources and Tips&lt;/a&gt;&lt;/strong&gt; page for:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/#r-resources&#34;&gt;Resources to get started with R&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/#useful-settings&#34;&gt;Useful R and RStudio settings&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/#installing-r-packages&#34;&gt;The basics of installing packages in R&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href=&#34;https://biodash.github.io/tutorials/r-resources-tips/#updating-r&#34;&gt;Instructions for updating R&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br/&gt; &lt;br/&gt; &lt;br/&gt;&lt;/p&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Information for Code Club Presenters</title>
      <link>https://biodash.github.io/codeclub-present/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub-present/</guid>
      <description>&lt;hr&gt;
&lt;br&gt;
&lt;h2 id=&#34;introduction&#34;&gt;Introduction&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Each Code Club session should be represented by one post on the website at &lt;a href=&#34;https://biodash.github.io/codeclub/&#34;&gt;https://biodash.github.io/codeclub/&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Regular presenters will be given direct access to the &lt;a href=&#34;https://github.com/biodash/biodash.github.io&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Github repository&lt;/a&gt;
and will be able to push a new post to the website directly.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Occasional presenters can either send their material directly to &lt;a href=&#34;mailto:poelstra.1@osu.edu&#34;&gt;Jelmer&lt;/a&gt;
or create a &amp;ldquo;pull request&amp;rdquo; with their new post.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Content should be written in R Markdown (&lt;code&gt;.Rmd&lt;/code&gt;) or &amp;ldquo;plain&amp;rdquo; Markdown (&lt;code&gt;.md&lt;/code&gt;).
If you write in &lt;code&gt;.Rmd&lt;/code&gt;, you need to render to &lt;code&gt;.md&lt;/code&gt; locally.
Conversion of &lt;code&gt;.md&lt;/code&gt; to an HTML file suitable for the website will be done
automatically upon pushing the master branch of the repository.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Make sure to get the session materials onto the website &lt;em&gt;at least several days before the session&lt;/em&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;getting-your-files-onto-the-site&#34;&gt;Getting your files onto the site&lt;/h2&gt;
&lt;h3 id=&#34;1-get-the-repo&#34;&gt;1: Get the repo&lt;/h3&gt;
&lt;p&gt;You only need to do this if you want to create a pull request or push your content to the website
directly. If you want to send your (R) Markdown file by email, skip this and continue to Step 2.&lt;/p&gt;
&lt;p&gt;The following assumes you have git &lt;a href=&#34;https://github.com/git-guides/install-git&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;installed&lt;/a&gt;,
&lt;a href=&#34;https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github/set-up-git#setting-up-git&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;set up&lt;/a&gt;,
have &lt;a href=&#34;https://github.com/join&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;a Github account&lt;/a&gt;,
and have your git &lt;a href=&#34;https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github/set-up-git#next-steps-authenticating-with-github-from-git&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;linked up to Github&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&#34;option-a-fork-the-repo-to-prep-for-a-pull-request&#34;&gt;Option A: Fork the repo to prep for a Pull Request&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Fork the repo&lt;/strong&gt;:
go to &lt;a href=&#34;https://github.com/biodash/biodash.github.io&#34;&gt;https://github.com/biodash/biodash.github.io&lt;/a&gt; and click the &lt;code&gt;Fork&lt;/code&gt; button
way in the top-right corner of the page.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Get the URL for your repo&lt;/strong&gt;:
In your forked repo,
click the green &lt;code&gt;Code&lt;/code&gt; button and copy the URL for the repo
to your clipboard (either the HTTPS or the SSH URL; the former will be less likely
to lead to authentication problems).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Go to a dir that you would like to be the parent dir of the Biodash/Codeclub repo:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;nb&#34;&gt;cd&lt;/span&gt; my-dir
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Clone your forked repo&lt;/strong&gt;, using the URL that you copied
to your clipboard:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;git clone https://github.com/&amp;lt;YOUR-USERNAME&amp;gt;/biodash.github.io.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Move into the newly cloned (downloaded) repository dir:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;nb&#34;&gt;cd&lt;/span&gt; biodash.github.io
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Add the original repository as an &amp;ldquo;upstream&amp;rdquo; remote&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;git remote add upstream https://github.com/biodash/biodash.github.io.git
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;You can check which remote repos (i.e., repos on Github)
are linked to your local repo using:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;git remote -v
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This should show &lt;i&gt;your forked repo&lt;/i&gt; as &amp;ldquo;origin&amp;rdquo;,
and the &lt;i&gt;original repo&lt;/i&gt; as &amp;ldquo;upstream&amp;rdquo;.
You won&amp;rsquo;t be able to push to the original repo,
but you can push to your forked repo and then submit a &lt;i&gt;pull request&lt;/i&gt;,
as we&amp;rsquo;ll do below.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;option-b-clone-the-repo-directly-direct-access-required&#34;&gt;Option B: Clone the repo directly (direct access required)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Go to a dir that you would like to be the parent dir of the Biodash/Codeclub repo:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;&lt;span class=&#34;nb&#34;&gt;cd&lt;/span&gt; my-dir
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Clone the website repo&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;git clone https://github.com/biodash/biodash.github.io.git &lt;span class=&#34;c1&#34;&gt;# Using HTTPS&lt;/span&gt;
&lt;span class=&#34;c1&#34;&gt;# Or: `git clone git@github.com:biodash/biodash.github.io.git` using SSH&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create a new branch&lt;/strong&gt; (by way of example called &amp;ldquo;my-branch&amp;rdquo;) and switch to it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;git checkout -b my-branch
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Creating a new branch is not strictly necessary but it may be safer/easier
to experiment in.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;2-create-a-code-club-post&#34;&gt;2: Create a Code Club post&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Here, we&amp;rsquo;ll use the &lt;em&gt;hugodown&lt;/em&gt; package to create a Markdown skeleton for our post,
and below we&amp;rsquo;ll also use &lt;em&gt;hugodown&lt;/em&gt; to preview the site.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
Note that you can easily bypass &lt;i&gt;hugodown&lt;/i&gt; by simply copying the YAML header from
the first code club session
(see &lt;a href=&#34;https://raw.githubusercontent.com/biodash/biodash.github.io/master/content/codeclub/01_backyard-birds/index.Rmd&#34;&gt;here&lt;/a&gt;
for the &lt;code&gt;.Rmd&lt;/code&gt; file) into a new file and taking it from there.
&lt;/div&gt;
&lt;p&gt;If you don&amp;rsquo;t have the &lt;em&gt;hugodown&lt;/em&gt; package installed, install it:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;remotes&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;install_github&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;r-lib/hugodown&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt; &lt;span class=&#34;c1&#34;&gt;# Or equivalently, use devtools::install_githhub()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;A &lt;em&gt;post bundle&lt;/em&gt; is a separate folder for a post which will hold the R Markdown file
that contains the post, as well as associated images and so on.
To create a post bundle along with a R Markdown file that already has many useful YAML header tags:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;hugodown&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;use_post&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#39;codeclub/&amp;lt;session-number&amp;gt;_&amp;lt;short-title&amp;gt;&amp;#39;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;span class=&#34;c1&#34;&gt;# An example would be: hugodown::use_post(&amp;#39;codeclub/01_intro-to-R&amp;#39;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;The &lt;code&gt;&amp;lt;session-number&amp;gt;&lt;/code&gt; is the actual Code Club session number,
and &lt;code&gt;&amp;lt;short-title&amp;gt;&lt;/code&gt; is a short title that you would like to give the post,
which will be used for links and the folder name.&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
The name of the &lt;code&gt;.Rmd&lt;/code&gt; file will be &lt;code&gt;index.Rmd&lt;/code&gt;,
and it should keep that name!
Keep this name also if you create your &lt;code&gt;.Rmd&lt;/code&gt; manually or by copying
the file from another Code Club session.
It will eventually turn into &lt;code&gt;index.html&lt;/code&gt;,
which is the name that will trigger the file to be displayed on the website.
&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Fill out some of the YAML, such as the &lt;code&gt;title&lt;/code&gt;, &lt;code&gt;subtitle&lt;/code&gt;, &lt;code&gt;authors&lt;/code&gt; (in kebab-case, e.g. john-doe,
to link to your author profile; note that Jelmer&amp;rsquo;s name here is &amp;ldquo;admin&amp;rdquo;),
and optionally &lt;code&gt;tags&lt;/code&gt; and &lt;code&gt;summary&lt;/code&gt;
(the &lt;code&gt;summary&lt;/code&gt; will appear on Biodash&amp;rsquo;s front page in the &amp;ldquo;Recent Posts&amp;rdquo; widget;
this can be good to fill out here because the default summary can be awkward,
as it combines headers and paragraphs).&lt;/p&gt;
&lt;div class=&#34;alert alert-warning&#34;&gt;
&lt;div&gt;
If you specify a date using the `date` tag in the YAML,
and this date is in the future (e.g. the date of the Code Club session),
the page will not be built and will thus not appear on the website!
Specifiying the date using `date` or `lastmod` in the YAML is not particularly
useful anyway --
when you edit the post after the specified date, it will use the edit date.
&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Write the contents of your Code Club session that you would like to share with participants, in R Markdown format.
For formatting tips, see &lt;a href=&#34;https://biodash.github.io/codeclub-present/#format&#34;&gt;below&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;p&gt;&lt;strong&gt;If you want participants to load an R Markdown file or script:&lt;/strong&gt;&lt;br&gt;
An easy solution is to place the file in the same directory as your post, and include it in your git commit,
so it will be uploaded to Github. In that case, the URL to the file for direct downloads for participants will be:
&lt;code&gt;https://raw.githubusercontent.com/biodash/biodash.github.io/master/docs/codeclub/&amp;lt;session-number&amp;gt;_&amp;lt;short-title&amp;gt;/&amp;lt;filename&amp;gt;&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;In your post, include a function call like &lt;code&gt;file.download(&amp;lt;script-URL&amp;gt;)&lt;/code&gt; for participants to get the file &amp;ndash;
this will work both for participants working locally and those working in an OSC RStudio Server instance.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;If your session contains a dataset:&lt;/strong&gt;&lt;br&gt;
Like for the markdown/script, place the file(s) in the same directory as your post.
If you have a markdown/script for participants, include &lt;code&gt;file.download(&amp;lt;dataset-URL&amp;gt;)&lt;/code&gt; in this file,
otherwise include it directly in your post.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Convert your &lt;code&gt;.Rmd&lt;/code&gt; (R Markdown) file to a &lt;code&gt;.md&lt;/code&gt; (Markdown) file.&lt;/strong&gt;&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
Hugo renders &lt;code&gt;.md&lt;/code&gt; but not &lt;code&gt;.Rmd&lt;/code&gt; to HTML,
so we have to always render to &lt;code&gt;.md&lt;/code&gt; first when writing in &lt;code&gt;.Rmd&lt;/code&gt;.
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Since your output is specified as &lt;code&gt;hugodown::md_document&lt;/code&gt;,
this is done most easily by &amp;ldquo;knitting&amp;rdquo; your post in RStudio by clicking &lt;code&gt;Knit&lt;/code&gt; in the top bar,
or by pressing &lt;code&gt;Ctrl + Shift + K&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;preview-build&#34;&gt;3: Preview your post or build the website (optional)&lt;/h3&gt;
&lt;p&gt;You can do this in two ways, from RStudio or from the command line.&lt;/p&gt;
&lt;h4 id=&#34;option-a-in-rstudio&#34;&gt;Option A: In RStudio&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Install Hugo:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;hugodown&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;hugo_install&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;0.66.0&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Preview the website:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;hugodown&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;hugo_start&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;

&lt;span class=&#34;c1&#34;&gt;#&amp;gt; Starting server on port 1313&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will provide a preview RStudio.
To look at it in a browser, go to &lt;code&gt;localhost:1313&lt;/code&gt;,
where 1313 corresponds to the port returned in the R console (see above).&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h4 id=&#34;option-b-from-the-command-line&#34;&gt;Option B: From the command line&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Install Hugo using &lt;a href=&#34;https://gohugo.io/getting-started/installing/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;these instructions&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Serve the website locally:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;hugo serve
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;You will see a message that includes &amp;ldquo;&lt;em&gt;Web Server is available at [&amp;hellip;]&lt;/em&gt;&amp;rdquo;.
Click the link or copy and paste the address into a browser, and you will see the rendered website.&lt;/p&gt;
&lt;p&gt;The server will keep running and will update whenever you save changes in a file
that is within the website directory, until you stop it using &lt;code&gt;Ctrl + C&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
&lt;h4 id=&#34;side-note-building-the-website&#34;&gt;Side note: Building the website&lt;/h4&gt;
&lt;p&gt;Note that you don&amp;rsquo;t need to &lt;em&gt;build&lt;/em&gt; the website,
because it will be built automatically from Markdown files whenever you push to
(the master branch of) the Github repo.&lt;/p&gt;
&lt;p&gt;But as background info, or in case automatic builds fail,
here is how you &lt;em&gt;would&lt;/em&gt; build the site:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Using Hugo from the shell:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;hugo -d docs/
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Using &lt;em&gt;hugodown&lt;/em&gt; in R:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;n&#34;&gt;hugodown&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;::&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;hugo_build&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;dest&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;docs&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;The entire rendered website is in the &lt;code&gt;docs/&lt;/code&gt; dir; HTML files rendered from Markdown
files will be placed there, any images and other files will be copied there, and so on.&lt;/p&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;4-commit&#34;&gt;4: Commit&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Add the files from your post:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;git add codeclub/&amp;lt;your-post-name&amp;gt;/*
  
&lt;span class=&#34;c1&#34;&gt;## Or, e.g. if you added files elswehere too, or have built the site:&lt;/span&gt;
&lt;span class=&#34;c1&#34;&gt;# git add *&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Check if all your changes and new files have been staged:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;git status
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Commit:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;git commit -m &lt;span class=&#34;s2&#34;&gt;&amp;#34;Add CodeClub session &amp;lt;session-nr&amp;gt; by &amp;lt;your-name&amp;gt;&amp;#34;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;5-push-or-submit-pull-request&#34;&gt;5: Push or submit pull request&lt;/h3&gt;
&lt;p&gt;Your Markdown (&lt;code&gt;.md&lt;/code&gt;) file(s) will be built along with the rest of the website by Hugo.
Using Github Actions, this will be done automatically upon pushing to the master branch on Github,
which is all we need to do.
Note that the built website will be committed by Github Actions not to the master
branch but to the &lt;em&gt;gh-actions&lt;/em&gt; branch.&lt;/p&gt;
&lt;h4 id=&#34;option-a-create-a-pull-request&#34;&gt;Option A: Create a pull request&lt;/h4&gt;
&lt;p&gt;When you create a &lt;em&gt;pull request&lt;/em&gt;, you are asking the maintainers of a repository
to &lt;em&gt;pull&lt;/em&gt; your changes into their repository.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Pull from the original repo&lt;/strong&gt; to make sure your repo is up-to-date:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;git pull upstream master      &lt;span class=&#34;c1&#34;&gt;# &amp;#34;upstream&amp;#34; refers to the original Github repo&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will first fetch the upstream changes and then merge them into your
local repo, thus keeping your local changes.
If git does not manage to perform this merge automatically,
which can happen if the same parts of the same files have been edited
both locally and upstream, there will be a &lt;em&gt;merge conflict&lt;/em&gt; which you will
need to &lt;a href=&#34;https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/resolving-a-merge-conflict-on-github&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;resolve manually&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Push to your forked repo&lt;/strong&gt;:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;git push origin master        &lt;span class=&#34;c1&#34;&gt;# &amp;#34;origin&amp;#34; refers to your forked Github repo&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Create the &lt;em&gt;pull request&lt;/em&gt;&lt;/strong&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Go to the Pull requests page of our repo at &lt;a href=&#34;https://github.com/biodash/biodash.github.io/pulls&#34;&gt;https://github.com/biodash/biodash.github.io/pulls&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Click the green button on the right that says &lt;code&gt;New pull request&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Under the large &lt;code&gt;Compare changes&lt;/code&gt; header, click &lt;code&gt;Compare across forks&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;In the drop-down menu to the right of the arrow, select your fork.&lt;/li&gt;
&lt;li&gt;Enter a &lt;strong&gt;title&lt;/strong&gt; (e.g. &amp;ldquo;&lt;em&gt;New Post: Session 6&lt;/em&gt;&amp;quot;) and &lt;strong&gt;description&lt;/strong&gt; (say a little more about the post) for the pull request.&lt;/li&gt;
&lt;li&gt;Click the green button &lt;code&gt;Send pull request&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For a more detailed step-by-step of creating a pull request from a fork,
see &lt;a href=&#34;https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/creating-a-pull-request-from-a-fork&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;h4 id=&#34;option-b-push-to-the-site-repo-direct-access-required&#34;&gt;Option B: Push to the site repo (direct access required)&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Merge your branch with the main (master) branch:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;git checkout master       &lt;span class=&#34;c1&#34;&gt;# Move to the master branch prior to merging&lt;/span&gt;
git merge my-branch       &lt;span class=&#34;c1&#34;&gt;# Merge into master (assuming your branch was named &amp;#34;my-branch&amp;#34;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Push to the master branch:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-sh&#34; data-lang=&#34;sh&#34;&gt;git push origin master
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h3 id=&#34;6-install-packages-at-osc-optional&#34;&gt;6: Install packages at OSC (optional)&lt;/h3&gt;
&lt;p&gt;Many R packages are already installed at OSC (nearly 200 for R 4.0.2), including the &lt;em&gt;tidyverse&lt;/em&gt;.
You can check which packages have been installed by typing, in an R session at OSC:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will list packages by library, which should include two locations available to all
OSC users (starting with &lt;code&gt;/usr/local/R&lt;/code&gt;), your personal library, and the Code Club library
(&lt;code&gt;/fs/ess/PAS1838/CODECLUB/Rpkgs&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;If you want to make another package available to Code Club participants, you can do so
as follows in an RStudio Server session at OSC:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;install.packages&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;&amp;lt;pkg-name&amp;gt;&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;n&#34;&gt;lib&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;/fs/ess/PAS1838/CODECLUB/Rpkgs&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This library is available to all members of the Code Club OSC classroom project.
To check specifically which packages are available in this library &amp;ndash; and whether your newly
installed package has indeed been installed here, type:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;lib.loc&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;s&#34;&gt;&amp;#34;/fs/ess/PAS1838/CODECLUB/Rpkgs&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Alternatively, you can let participants working at OSC install the packages themselves,
like participants that work locally will have to do.&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;format&#34;&gt;Formatting tips&lt;/h2&gt;
&lt;h3 id=&#34;miscellaneous&#34;&gt;Miscellaneous&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;If you want a &lt;strong&gt;Table of Contents&lt;/strong&gt; (TOC) for your file, add a line &lt;code&gt;toc: true&lt;/code&gt; to the &lt;code&gt;YAML&lt;/code&gt;
(&lt;em&gt;not&lt;/em&gt; indented, as it is not an option of the output format).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To add an image, put it in the same directory as the markdown file,
and refer to it without prepending a path.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt; will insert a line break,
which can be useful to get more space between sections.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I add lines above each major section header using &lt;code&gt;----&lt;/code&gt; (preceded by a &lt;code&gt;&amp;lt;br&amp;gt;&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;del&gt;Add a line that reads &lt;code&gt;source_extension: &#39;.Rmd&#39;&lt;/code&gt; (not indented) to your R Markdown,
which will ensure that there is a link to the source document at the top of your post.&lt;/del&gt;&lt;br&gt;
&lt;em&gt;EDIT: I have removed these source links for now.
They were also visible in the &amp;ldquo;Recent Posts&amp;rdquo; widget on the home page,
and some people clicked on that link rather than the website link.
Then, they ended up on in the Github repo but didn&amp;rsquo;t even know they were
in the wrong place since the contents of the post is present.&lt;/em&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;h3 id=&#34;hidden-sections&#34;&gt;Hidden sections&lt;/h3&gt;
&lt;p&gt;It can be useful to provide solutions to small challenges in the file,
but to hide them by default. This can be done with a little HTML:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-{html}&#34; data-lang=&#34;{html}&#34;&gt;&amp;lt;details&amp;gt;
&amp;lt;summary&amp;gt;
Solution (click here)
&amp;lt;/summary&amp;gt;

&amp;lt;br&amp;gt;
... Your solution - this can be a long section including a code block...
```{r}
install.packages(&amp;quot;tidyverse&amp;quot;)
```
&amp;lt;/details&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This is rendered as:&lt;/p&gt;
&lt;details&gt;
&lt;summary&gt;
Solution (click here)
&lt;/summary&gt;
&lt;br&gt;
&lt;p&gt;&amp;hellip; Your solution - this can be a long section including a code block&amp;hellip;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-{r}&#34; data-lang=&#34;{r}&#34;&gt;install.packages(&amp;quot;tidyverse&amp;quot;)
&lt;/code&gt;&lt;/pre&gt;&lt;/details&gt;
&lt;br&gt;
&lt;h3 id=&#34;infoalert-notes&#34;&gt;Info/alert notes&lt;/h3&gt;
&lt;p&gt;To produce boxes to draw attention to specific content,
you can use two classes specific to the &lt;a href=&#34;https://themes.gohugo.io/academic/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Hugo Academic Theme&lt;/a&gt;
(now branded as &lt;a href=&#34;https://wowchemy.com/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&amp;ldquo;Wowchemy&amp;rdquo;&lt;/a&gt;).&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;alert-note&lt;/code&gt; for a blue box with an info symbol:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-{HTML}&#34; data-lang=&#34;{HTML}&#34;&gt;&amp;lt;div class=&amp;quot;alert alert-note&amp;quot;&amp;gt;
&amp;lt;div&amp;gt;
This is an alert note.
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Which is rendered as:&lt;/p&gt;
&lt;div class=&#34;alert alert-note&#34;&gt;
&lt;div&gt;
This is an alert note.
&lt;/div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;alert-warning&lt;/code&gt; for a red box with a warning symbol:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-{HTML}&#34; data-lang=&#34;{HTML}&#34;&gt;&amp;lt;div class=&amp;quot;alert alert-warning&amp;quot;&amp;gt;
&amp;lt;div&amp;gt;
This is an alert warning.
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Which is rendered as:&lt;/p&gt;
&lt;div class=&#34;alert alert-warning&#34;&gt;
&lt;div&gt;
This is an alert warning.
&lt;div&gt;
&lt;/div&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;I also added a custom class, &lt;code&gt;puzzle&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-{HTML}&#34; data-lang=&#34;{HTML}&#34;&gt;&amp;lt;div class=&amp;quot;alert puzzle&amp;quot;&amp;gt;
&amp;lt;div&amp;gt;
This is a puzzle div, for do-it-yourself challenges.
&amp;lt;/div&amp;gt;
&amp;lt;/div&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;div class=&#34;puzzle&#34;&gt;
&lt;div&gt;
This is a puzzle div, for do-it-yourself challenges.
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Custom classes and other custom formatting can be written in CSS
in the &lt;code&gt;assets/scss/custom.scss&lt;/code&gt; file.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;All of these classes can also be called using pandoc&amp;rsquo;s &lt;code&gt;:::&lt;/code&gt; notation
when you&amp;rsquo;re writing in &lt;code&gt;.Rmd&lt;/code&gt; (but not if you&amp;rsquo;re writing in &lt;code&gt;.md&lt;/code&gt;), e.g.:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;:::puzzle
This is a puzzle div, for do-it-yourself challenges.
:::
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;br&gt;
&lt;h3 id=&#34;code-highlighting&#34;&gt;Code highlighting&lt;/h3&gt;
&lt;div class=&#34;alert alert-warning&#34;&gt;
&lt;div&gt;
Code highlighting doesn&#39;t work with out of the box with &lt;code&gt;.Rmd&lt;/code&gt; files.
But it should be possible to get it to work, stay tuned!
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Hugo supports the highlighting of specific lines of code
using the syntax below in &lt;code&gt;md&lt;/code&gt; documents:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;```r {hl_lines=[1,&amp;quot;3-4&amp;quot;]}
library(&amp;quot;tidyverse&amp;quot;)
weight_df %&amp;gt;%
  mutate(mean_weight = mean(weight)) %&amp;gt;%
  select(mean_weight, everything())
dim(weight_df)
```
&lt;/code&gt;&lt;/pre&gt;&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-r&#34; data-lang=&#34;r&#34;&gt;&lt;span class=&#34;hl&#34;&gt;&lt;span class=&#34;nf&#34;&gt;library&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;s&#34;&gt;&amp;#34;tidyverse&amp;#34;&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;weight_df&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
&lt;span class=&#34;hl&#34;&gt;  &lt;span class=&#34;nf&#34;&gt;mutate&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mean_weight&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;=&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;mean&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;weight&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;))&lt;/span&gt; &lt;span class=&#34;o&#34;&gt;%&amp;gt;%&lt;/span&gt;
&lt;/span&gt;&lt;span class=&#34;hl&#34;&gt;  &lt;span class=&#34;nf&#34;&gt;select&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;mean_weight&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;,&lt;/span&gt; &lt;span class=&#34;nf&#34;&gt;everything&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;())&lt;/span&gt;
&lt;/span&gt;&lt;span class=&#34;nf&#34;&gt;dim&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;(&lt;/span&gt;&lt;span class=&#34;n&#34;&gt;weight_df&lt;/span&gt;&lt;span class=&#34;p&#34;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id=&#34;shortcodes&#34;&gt;Shortcodes&lt;/h3&gt;
&lt;div class=&#34;alert alert-warning&#34;&gt;
&lt;div&gt;
Like code highlighting, shortcodes only work with &lt;code&gt;.md&lt;/code&gt; files.
The &lt;i&gt;blogdown&lt;/i&gt; package has a &lt;code&gt;shortcode()&lt;/code&gt; function to support them
(see &lt;a href=&#34;https://bookdown.org/yihui/blogdown/content.html#shortcode&#34;&gt;here&lt;/a&gt;),
but &lt;i&gt;hugodown&lt;/i&gt; does not support them.
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;Hugo shortcodes are little code snippets for specific content.
Some of these are specific to Wowchemy,
and others are available for any Hugo site.&lt;/p&gt;
&lt;h4 id=&#34;highlight-text&#34;&gt;Highlight text&lt;/h4&gt;
&lt;p&gt;You can highlight text as follows:&lt;/p&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;Here is some &lt;span class=&#34;o&#34;&gt;{{&lt;/span&gt;&amp;lt; hl &amp;gt;&lt;span class=&#34;o&#34;&gt;}}&lt;/span&gt;highlighted text&lt;span class=&#34;o&#34;&gt;{{&lt;/span&gt;&amp;lt; /hl &amp;gt;&lt;span class=&#34;o&#34;&gt;}}&lt;/span&gt;.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;This will render as:&lt;/p&gt;
&lt;h4 id=&#34;icons&#34;&gt;Icons&lt;/h4&gt;
&lt;p&gt;Wowchemy supports shortcodes for icons, for instance:&lt;/p&gt;

  &lt;i class=&#34;fab fa-r-project  pr-1 fa-fw&#34;&gt;&lt;/i&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;o&#34;&gt;{{&lt;/span&gt;&amp;lt; icon &lt;span class=&#34;nv&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;r-project&amp;#34;&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;pack&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;fab&amp;#34;&lt;/span&gt; &amp;gt;&lt;span class=&#34;o&#34;&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
  &lt;i class=&#34;fab fa-python  pr-1 fa-fw&#34;&gt;&lt;/i&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;o&#34;&gt;{{&lt;/span&gt;&amp;lt; icon &lt;span class=&#34;nv&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;python&amp;#34;&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;pack&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;fab&amp;#34;&lt;/span&gt; &amp;gt;&lt;span class=&#34;o&#34;&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;
  &lt;i class=&#34;fas fa-terminal  pr-1 fa-fw&#34;&gt;&lt;/i&gt;
&lt;div class=&#34;highlight&#34;&gt;&lt;pre class=&#34;chroma&#34;&gt;&lt;code class=&#34;language-bash&#34; data-lang=&#34;bash&#34;&gt;&lt;span class=&#34;o&#34;&gt;{{&lt;/span&gt;&amp;lt; icon &lt;span class=&#34;nv&#34;&gt;name&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;terminal&amp;#34;&lt;/span&gt; &lt;span class=&#34;nv&#34;&gt;pack&lt;/span&gt;&lt;span class=&#34;o&#34;&gt;=&lt;/span&gt;&lt;span class=&#34;s2&#34;&gt;&amp;#34;fas&amp;#34;&lt;/span&gt; &amp;gt;&lt;span class=&#34;o&#34;&gt;}}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h4 id=&#34;general-hugo-shortcodes&#34;&gt;General Hugo shortcodes&lt;/h4&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;To embed a Youtube video, use the following, replacing &amp;ldquo;videoID&amp;rdquo; by the actual ID
(&lt;a href=&#34;https://www.youtube.com/watch?v=ID&#34;&gt;https://www.youtube.com/watch?v=ID&lt;/a&gt;) in&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-{bash}&#34; data-lang=&#34;{bash}&#34;&gt;{{&amp;lt; youtube ID &amp;gt;}}
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;To embed a Tweet, use the following, replacing &amp;ldquo;tweetID&amp;rdquo; by the actual ID
(&lt;a href=&#34;https://twitter.com/user/status/ID):&#34;&gt;https://twitter.com/user/status/ID):&lt;/a&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&#34;language-{bash}&#34; data-lang=&#34;{bash}&#34;&gt;{{&amp;lt; tweet ID &amp;gt;}}
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For more info and more shortcodes,
see the &lt;a href=&#34;https://gohugo.io/content-management/shortcodes/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;Hugo documentation on shortcodes&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;br/&gt; &lt;br/&gt; &lt;br/&gt; &lt;br/&gt;&lt;/p&gt;
</description>
    </item>
    
    <item>
      <title>Schedule for Code Club</title>
      <link>https://biodash.github.io/codeclub-schedule/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub-schedule/</guid>
      <description>&lt;hr&gt;
&lt;h2 id=&#34;code-club-will-restart-at-the-end-of-august&#34;&gt;Code Club will restart at the end of August&lt;/h2&gt;
&lt;p&gt;During the first part of the semester,
we will cover how to make a website with Quarto/RMarkdown and Git/GitHub.
During the second part of the semester, we will learn about R Shiny.&lt;/p&gt;
&lt;p&gt;&lt;a href=&#34;https://forms.office.com/r/SgmdwJXEXx&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;See this form for more information and to sign up!&lt;/a&gt;&lt;/p&gt;
&lt;br&gt;
&lt;hr&gt;
&lt;h2 id=&#34;previous-semesters&#34;&gt;Previous semesters&lt;/h2&gt;
&lt;p&gt;Ask us for access to the Zoom recordings of previous Code Club sessions!&lt;/p&gt;
&lt;h3 id=&#34;spring-23&#34;&gt;Spring &amp;lsquo;23&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;R4DS = &lt;a href=&#34;https://r4ds.hadley.nz/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;The R for Data Science book (2nd edition)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Session&lt;/th&gt;
&lt;th&gt;Date&lt;/th&gt;
&lt;th&gt;Presenter&lt;/th&gt;
&lt;th&gt;Topic + link to BioDASH page&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;S05E01&lt;/td&gt;
&lt;td&gt;Jan 26&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s05e01_pipes/&#34;&gt;&lt;strong&gt;R4DS, Ch. 4: Pipes&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S05E02&lt;/td&gt;
&lt;td&gt;Feb 02&lt;/td&gt;
&lt;td&gt;Stephen&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s05e02/&#34;&gt;&lt;strong&gt;R4DS, Ch. 6: Tidy Data, I&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S05E03&lt;/td&gt;
&lt;td&gt;Feb 09&lt;/td&gt;
&lt;td&gt;Jessica &amp;amp; Daniel&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s05e03/&#34;&gt;&lt;strong&gt;R4DS, Ch. 6: Tidy Data, II&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S05E04&lt;/td&gt;
&lt;td&gt;Feb 16&lt;/td&gt;
&lt;td&gt;Michael&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://r4ds.hadley.nz/workflow-style.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;R4DS, Ch. 7: Code Style&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S05E05&lt;/td&gt;
&lt;td&gt;Feb 23&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s05e05/&#34;&gt;&lt;strong&gt;R4DS, Ch. 8: Data Import, I&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S05E06&lt;/td&gt;
&lt;td&gt;Mar 02&lt;/td&gt;
&lt;td&gt;Stephen&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://r4ds.hadley.nz/data-import.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;R4DS, Ch. 8: Data Import, II&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S05E07&lt;/td&gt;
&lt;td&gt;Mar 09&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://r4ds.hadley.nz/workflow-scripts.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;R4DS, Ch. 9: Scripts &amp;amp; Projects&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S05E08&lt;/td&gt;
&lt;td&gt;Mar 23&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s05e08_ggplot-1/&#34;&gt;&lt;strong&gt;R4DS, Ch. 10: ggplot layers, part 1&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S05E09&lt;/td&gt;
&lt;td&gt;Mar 30&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s05e09/&#34;&gt;&lt;strong&gt;R4DS, Ch. 10: ggplot layers, part 2&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;summer--fall-22&#34;&gt;Summer &amp;amp; Fall &amp;lsquo;22&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;R4DS = &lt;a href=&#34;https://r4ds.had.co.nz/&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;The R for Data Science book (1st edition)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Session&lt;/th&gt;
&lt;th&gt;Date&lt;/th&gt;
&lt;th&gt;Presenter&lt;/th&gt;
&lt;th&gt;Topic&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;S04E01&lt;/td&gt;
&lt;td&gt;June 09&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s04e01_r4ds-ch1/&#34;&gt;&lt;strong&gt;R4DS, Ch. 1: Intro&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E02&lt;/td&gt;
&lt;td&gt;June 23&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://r4ds.had.co.nz/data-visualisation.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;R4DS, Ch. 3.1- 3.4: Data viz I&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E03&lt;/td&gt;
&lt;td&gt;June 30&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://r4ds.had.co.nz/data-visualisation.html#facets&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;R4DS, Ch. 3.5: Data viz II&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E04&lt;/td&gt;
&lt;td&gt;July 07&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://r4ds.had.co.nz/data-visualisation.html#geometric-objects&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;R4DS, Ch. 3.6: Data viz III&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E05&lt;/td&gt;
&lt;td&gt;July 14&lt;/td&gt;
&lt;td&gt;Mike S.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://r4ds.had.co.nz/data-visualisation.html#statistical-transformations&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;R4DS, Ch. 3.7: Data viz IV&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E06&lt;/td&gt;
&lt;td&gt;July 21&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://r4ds.had.co.nz/data-visualisation.html#position-adjustments&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;R4DS, Ch. 3.8-3.10: Data viz V&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E07&lt;/td&gt;
&lt;td&gt;July 28&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://r4ds.had.co.nz/r-markdown.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;R4DS, Ch. 27: R Markdown&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E08&lt;/td&gt;
&lt;td&gt;Sept 15&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://r4ds.had.co.nz/workflow-basics.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;R4DS, Ch. 4, 6 &amp;amp; 8: Workflow&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E09&lt;/td&gt;
&lt;td&gt;Sept 22&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s04e08_r4ds-ch5-1/&#34;&gt;&lt;strong&gt;R4DS, Ch. 5.1-5.2: Data transformation I - intro and filter()&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E10&lt;/td&gt;
&lt;td&gt;Oct 06&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/S04E10-11_r4ds-ch5-4/&#34;&gt;&lt;strong&gt;R4DS, Ch. 5.3: Data transformation II - arrange()&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E11&lt;/td&gt;
&lt;td&gt;Oct 20&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/S04E10-11_r4ds-ch5-4/&#34;&gt;&lt;strong&gt;R4DS, Ch. 5.4: Data transformation III - select()&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E12&lt;/td&gt;
&lt;td&gt;Oct 27&lt;/td&gt;
&lt;td&gt;Stephen&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/S04E12_r4ds-ch5-5&#34;&gt;&lt;strong&gt;R4DS, Ch. 5.5: Data transformation IV - mutate()&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E13&lt;/td&gt;
&lt;td&gt;Nov 03&lt;/td&gt;
&lt;td&gt;Mike S.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/S04E13&#34;&gt;&lt;strong&gt;R4DS, Ch. 5.6: Data transformation V - summarize() part 1&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E14&lt;/td&gt;
&lt;td&gt;Nov 10&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s04e14_r4ds-ch5-5-again/&#34;&gt;&lt;strong&gt;R4DS, Ch. 5.6: Data transformation V - summarize() part 2&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E15&lt;/td&gt;
&lt;td&gt;Nov 17&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://r4ds.had.co.nz/exploratory-data-analysis.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;R4DS, Ch. 7.1-7.3: Exploratory Data Analysis I&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E16&lt;/td&gt;
&lt;td&gt;Dec 01&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://r4ds.had.co.nz/exploratory-data-analysis.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;R4DS, Ch. 7.1-7.3: Exploratory Data Analysis II&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;S04E17&lt;/td&gt;
&lt;td&gt;Dec 08&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://r4ds.had.co.nz/tibbles.html&#34; target=&#34;_blank&#34; rel=&#34;noopener&#34;&gt;&lt;strong&gt;R4DS, Ch. 10: Tibbles&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;spring-22&#34;&gt;Spring &amp;lsquo;22&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Session&lt;/th&gt;
&lt;th&gt;Date&lt;/th&gt;
&lt;th&gt;Presenter&lt;/th&gt;
&lt;th&gt;Topic (+ link)&lt;/th&gt;
&lt;th&gt;Topic block&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S03E01&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Jan 13&lt;/td&gt;
&lt;td&gt;Mike S.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e01_ttests/&#34;&gt;&lt;strong&gt;T-tests&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Basic statistics in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S03E02&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Jan 20&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e02_anova/&#34;&gt;&lt;strong&gt;ANOVA&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Basic statistics in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S03E03&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Jan 27&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e03_pca/&#34;&gt;&lt;strong&gt;Principal Component Analysis&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Basic statistics in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S03E04&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Feb 03&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e04_anova2/&#34;&gt;&lt;strong&gt;ANOVA part II&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Basic statistics in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S03E05&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Feb 10&lt;/td&gt;
&lt;td&gt;Stephen&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e05_correlation/&#34;&gt;&lt;strong&gt;Correlation&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Basic statistics in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S03E06&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Feb 17&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e06_datastructures/&#34;&gt;&lt;strong&gt;Data structures and subsetting&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Basic statistics in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S03E07&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Feb 24&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e07_vectorization/&#34;&gt;&lt;strong&gt;Intro to &amp;ldquo;DRY&amp;rdquo; and iteration&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&amp;ldquo;Don&amp;rsquo;t repeat yourself&amp;rdquo; (DRY)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S03E08&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Mar 03&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e08_loops/&#34;&gt;&lt;strong&gt;Loops&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&amp;ldquo;Don&amp;rsquo;t repeat yourself&amp;rdquo; (DRY)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S03E09&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Mar 10&lt;/td&gt;
&lt;td&gt;Mike S.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e09_apply/&#34;&gt;&lt;strong&gt;Apply functions&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&amp;ldquo;Don&amp;rsquo;t repeat yourself&amp;rdquo; (DRY)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S03E10&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Mar 24&lt;/td&gt;
&lt;td&gt;Mike S.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e10_purrr/&#34;&gt;&lt;strong&gt;Purrr map functions&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&amp;ldquo;Don&amp;rsquo;t repeat yourself&amp;rdquo; (DRY)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S03E11&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Apr 14&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e11_functions/&#34;&gt;&lt;strong&gt;Writing functions part I&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&amp;ldquo;Don&amp;rsquo;t repeat yourself&amp;rdquo; (DRY)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S03E12&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Apr 21&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s03e12_functions_in_loops/&#34;&gt;&lt;strong&gt;Incorporating your own functions into loops&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&amp;ldquo;Don&amp;rsquo;t repeat yourself&amp;rdquo; (DRY)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;fall-21&#34;&gt;Fall &amp;lsquo;21&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Session&lt;/th&gt;
&lt;th&gt;Date&lt;/th&gt;
&lt;th&gt;Presenter&lt;/th&gt;
&lt;th&gt;Topic (+ link)&lt;/th&gt;
&lt;th&gt;Topic block&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S02E01&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Aug 26&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e01_r-intro-part1/&#34;&gt;&lt;strong&gt;R basics &amp;ndash; part I&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Back to basics in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S02E02&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sep 2&lt;/td&gt;
&lt;td&gt;Mike S.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e02_r-intro_part2/&#34;&gt;&lt;strong&gt;R basics &amp;ndash; part II&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Back to basics in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S02E03&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sep 9&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e03_rmarkdown/&#34;&gt;&lt;strong&gt;R Markdown&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Back to basics in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S02E04&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sep 16&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e04_tidyverse-intro-part1/&#34;&gt;&lt;strong&gt;Tidyverse intro &amp;ndash; part I&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Back to basics in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S02E05&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sep 23&lt;/td&gt;
&lt;td&gt;Stephen&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e05_tidyverse-intro-part2/&#34;&gt;&lt;strong&gt;Tidyverse intro &amp;ndash; part II&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Back to basics in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S02E06&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Sep 30&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e06_ggplot2/&#34;&gt;&lt;strong&gt;&lt;em&gt;ggplot&lt;/em&gt; intro &amp;ndash; part I&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Plotting in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S02E07&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Oct 07&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e07_ggplot2_part2/&#34;&gt;&lt;strong&gt;&lt;em&gt;ggplot&lt;/em&gt; intro &amp;ndash; part II&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Plotting in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S02E08&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Oct 21&lt;/td&gt;
&lt;td&gt;Mike S.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e08_multiple_plots/&#34;&gt;&lt;strong&gt;Faceting plots&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Plotting in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S02E09&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Oct 28&lt;/td&gt;
&lt;td&gt;Mike S.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e09_multiple_plots_part2/&#34;&gt;&lt;strong&gt;Faceting and combining plots&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Plotting in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S02E10&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Nov 04&lt;/td&gt;
&lt;td&gt;Daniel Quiroz Moreno (HCS)&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e10_ggpubr/&#34;&gt;&lt;strong&gt;Adding statistical results to plots &lt;br&gt; using &lt;em&gt;ggpubr&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Plotting in R&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S02E11&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Nov 18&lt;/td&gt;
&lt;td&gt;Julia Vrtilek (EEOB)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;Analysis of bat social vocalizations &lt;br&gt; with R at OSC&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Putting code to practice&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S02E12&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Dec 02&lt;/td&gt;
&lt;td&gt;Matthew Teegarden (FST)&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e11_shiny_intro/&#34;&gt;&lt;strong&gt;Shiny bright like a diamond: an intro &lt;br&gt; to building interactive applications in R&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Putting code to practice&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S02E13&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Dec 09&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/s02e12_plotly/&#34;&gt;&lt;strong&gt;Interactive plots with &lt;em&gt;Plotly&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;Plotting in R&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;h3 id=&#34;fall-20--spring-21&#34;&gt;Fall &amp;lsquo;20 &amp;amp; Spring &amp;lsquo;21&lt;/h3&gt;
&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Session nr.&lt;/th&gt;
&lt;th&gt;Date&lt;/th&gt;
&lt;th&gt;Presenter&lt;/th&gt;
&lt;th&gt;Topic (+ link)&lt;/th&gt;
&lt;th&gt;Other&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E01&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Nov 18, 2020&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/01_backyard-birds/&#34;&gt;&lt;strong&gt;RStudio Projects &amp;amp; getting started&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/slides/CC01/&#34;&gt;slides&lt;/a&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E02&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Dec 2, 2020&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/02_dplyr-core-verbs&#34;&gt;&lt;em&gt;&lt;strong&gt;dplyr&lt;/strong&gt;&lt;/em&gt; &lt;strong&gt;core verbs&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E03&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Dec 9, 2020&lt;/td&gt;
&lt;td&gt;Mike S.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/03_joining-datasets&#34;&gt;&lt;strong&gt;Joining datasets&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E04&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Dec 16, 2020&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/04_ggplot2&#34;&gt;&lt;em&gt;&lt;strong&gt;ggplot2 &amp;ndash; round 1&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E05&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Jan 15, 2021&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/05_ggplot-round-2&#34;&gt;&lt;em&gt;&lt;strong&gt;ggplot2 &amp;ndash; round 2&lt;/strong&gt;&lt;/em&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E06&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Jan 22, 2021&lt;/td&gt;
&lt;td&gt;Stephen&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/06_factors&#34;&gt;&lt;strong&gt;Factors&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E07&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Jan 29, 2021&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/07_rmarkdown/&#34;&gt;&lt;strong&gt;R Markdown&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E08&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Feb 5, 2021&lt;/td&gt;
&lt;td&gt;Mike S.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/08_pivoting/&#34;&gt;&lt;strong&gt;Pivoting data&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E09&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Feb 12, 2021&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/09_subsetting/&#34;&gt;&lt;strong&gt;Subsetting data&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E10&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Feb 19, 2021&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/10_faceting-animating/&#34;&gt;&lt;strong&gt;Faceting, animating, and combining plots&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E11&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Feb 26, 2021&lt;/td&gt;
&lt;td&gt;Stephen&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/11_ggplot-maps/&#34;&gt;&lt;strong&gt;Making maps with &lt;em&gt;ggmap&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E12&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Mar 5, 2021&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/12_loops/&#34;&gt;&lt;strong&gt;Vectorization and loops&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E13&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Mar 12, 2021&lt;/td&gt;
&lt;td&gt;Mike S.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/13_apply&#34;&gt;&lt;strong&gt;The apply family of functions&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E14&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Mar 19, 2021&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/14_functions/&#34;&gt;&lt;strong&gt;Writing your own functions&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E15&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Mar 26, 2021&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/15_plotly/&#34;&gt;&lt;strong&gt;Interactive plots with &lt;em&gt;Plotly&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E16&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Apr 02, 2021&lt;/td&gt;
&lt;td&gt;Stephen&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/16_lubridate/&#34;&gt;&lt;strong&gt;Working with dates with &lt;em&gt;lubridate&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E17&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Apr 09, 2021&lt;/td&gt;
&lt;td&gt;Jelmer&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/17_regex/&#34;&gt;&lt;strong&gt;Introduction to regular expressions&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E18&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Apr 16, 2021&lt;/td&gt;
&lt;td&gt;Mike S.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/18_regex2/&#34;&gt;&lt;strong&gt;Regular Expressions: Part II&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E19&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Apr 23, 2021&lt;/td&gt;
&lt;td&gt;Michael B.&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/19_wordclouds/&#34;&gt;&lt;strong&gt;Word Clouds via &lt;em&gt;tidytext&lt;/em&gt;&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;strong&gt;S01E20&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;Apr 30, 2021&lt;/td&gt;
&lt;td&gt;Jessica&lt;/td&gt;
&lt;td&gt;&lt;a href=&#34;https://biodash.github.io/codeclub/20_cleaning-up/&#34;&gt;&lt;strong&gt;Cleaning up variables names&lt;/strong&gt;&lt;/a&gt;&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;
&lt;p&gt;&lt;br/&gt; &lt;br/&gt; &lt;br/&gt; &lt;br/&gt;&lt;/p&gt;
&lt;hr&gt;
</description>
    </item>
    
    <item>
      <title>Suggest a Topic for Code Club!</title>
      <link>https://biodash.github.io/codeclub-suggest/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      <guid>https://biodash.github.io/codeclub-suggest/</guid>
      <description>&lt;hr&gt;
&lt;br&gt;
&lt;p&gt;Please use the form below to suggest a topic or concept to be covered at Code Club.
You are also welcome to leave a suggestion relating to the general format, organization,
or presentation of Code Club.&lt;/p&gt;
&lt;p&gt;If you suggest a topic, a broad range of suggestions are welcome &amp;ndash; it need not fit neatly as a single Code Club session.
So your suggestion can be as broad as &amp;ldquo;object-oriented programming&amp;rdquo; or as specific as a single
R function that you happen to struggle with or that you just really like.&lt;/p&gt;
&lt;iframe src=&#34;https://docs.google.com/forms/d/e/1FAIpQLSclFCVWI7mjHeJfoHfLKnV7k9fE0r76-bTwpt_3nEv4tjJyEA/viewform?embedded=true&#34; width=&#34;640&#34; height=&#34;983&#34; frameborder=&#34;0&#34; marginheight=&#34;0&#34; marginwidth=&#34;0&#34;&gt;Loading…&lt;/iframe&gt;
&lt;p&gt;&lt;br/&gt; &lt;br/&gt; &lt;br/&gt;&lt;/p&gt;
&lt;hr&gt;
</description>
    </item>
    
  </channel>
</rss>
