Add more polls and fix some typos

This commit is contained in:
Natalie Elphick 2024-01-19 11:44:09 -08:00
parent 799ac0bb45
commit 3d03689086
3 changed files with 150 additions and 41 deletions

View file

@ -2583,9 +2583,9 @@ Senior Statistician</p>
<p><strong>What is your level of experience with coding/data
analysis?</strong></p>
<ol type="1">
<li>I am fluent in another data analysis programming language (Python,
Matlab etc.)</li>
<li>I am use Excel to do linear regression</li>
<li>I know another data analysis programming language (Python, Matlab
etc.)</li>
<li>I can use Excel to do linear regression</li>
<li>I know some R</li>
<li>All of the above</li>
<li>None of the above</li>
@ -2772,7 +2772,7 @@ one style of names</li>
<ul>
<li>Integer
<ul>
<li>Whole numbers</li>
<li>Whole numbers (in R denote with L ex. 1L,2L)</li>
</ul></li>
<li>Numeric
<ul>
@ -2781,7 +2781,7 @@ one style of names</li>
<li>Logical
<ul>
<li>Boolean (TRUE, FALSE)</li>
<li>NA</li>
<li>NA (missing data)</li>
</ul></li>
<li>Character
<ul>
@ -2790,6 +2790,17 @@ one style of names</li>
</ul></li>
</ul>
</section>
<section id="poll-3" class="slide level2">
<h2>Poll 3</h2>
<p><strong>Which of these is not the correct data type for the
value?</strong></p>
<ol type="1">
<li>1.5 - Numeric</li>
<li>“Labrador Retriever” - Character</li>
<li>NA - Logical</li>
<li>1 - Integer</li>
</ol>
</section>
<section id="data-structures" class="slide level2">
<h2>Data Structures</h2>
<ul>
@ -2827,7 +2838,7 @@ types/structures</strong> (ex. nested lists)</li>
<section id="min-break" class="title-slide slide level1">
<h1>10 min break</h1>
<center>
<div class="countdown" id="timer_65f4df24" data-update-every="1" tabindex="0" style="right:0;bottom:0;margin:5%;padding:50px;font-size:5em;position: relative; width: min-content;">
<div class="countdown" id="timer_e9648370" data-update-every="1" tabindex="0" style="right:0;bottom:0;margin:5%;padding:50px;font-size:5em;position: relative; width: min-content;">
<div class="countdown-controls"><button class="countdown-bump-down"></button><button class="countdown-bump-up">+</button></div>
<code class="countdown-time"><span class="countdown-digits minutes">10</span><span class="countdown-digits colon">:</span><span class="countdown-digits seconds">00</span></code>
</div>
@ -2855,17 +2866,40 @@ mean( ), median( ), mode( ) )</li>
<span id="cb4-7"><a href="#cb4-7" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb4-8"><a href="#cb4-8" aria-hidden="true" tabindex="-1"></a>x <span class="sc">%in%</span> y <span class="co"># Is x in this vector y?</span></span></code></pre></div>
</section>
<section id="poll-4" class="slide level2">
<h2>Poll 4</h2>
<p><strong>What is the output of the following code?</strong></p>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="dv">4</span> <span class="sc">%in%</span> <span class="fu">as.character</span>(<span class="fu">c</span>(<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>,<span class="dv">4</span>))</span></code></pre></div>
<ol type="1">
<li>TRUE</li>
<li>FALSE</li>
<li>NA</li>
</ol>
</section>
<section id="logical-operators" class="slide level2">
<h2>Logical Operators</h2>
<ul>
<li>Logical operators can compare TRUE or FALSE values</li>
</ul>
<div class="sourceCode" id="cb5"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a>x <span class="ot">&lt;-</span> <span class="cn">TRUE</span></span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a>y <span class="ot">&lt;-</span> <span class="cn">FALSE</span></span>
<span id="cb5-3"><a href="#cb5-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb5-4"><a href="#cb5-4" aria-hidden="true" tabindex="-1"></a><span class="sc">!</span>x <span class="co"># Not x</span></span>
<span id="cb5-5"><a href="#cb5-5" aria-hidden="true" tabindex="-1"></a>x <span class="sc">|</span> y <span class="co"># x or y</span></span>
<span id="cb5-6"><a href="#cb5-6" aria-hidden="true" tabindex="-1"></a>x <span class="sc">&amp;</span> y <span class="co"># x and y</span></span></code></pre></div>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>x <span class="ot">&lt;-</span> <span class="cn">TRUE</span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>y <span class="ot">&lt;-</span> <span class="cn">FALSE</span></span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a><span class="sc">!</span>x <span class="co"># Not x</span></span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>x <span class="sc">|</span> y <span class="co"># x or y</span></span>
<span id="cb6-6"><a href="#cb6-6" aria-hidden="true" tabindex="-1"></a>x <span class="sc">&amp;</span> y <span class="co"># x and y</span></span></code></pre></div>
</section>
<section id="poll-5" class="slide level2">
<h2>Poll 5</h2>
<p><strong>What is the output of the following code?</strong></p>
<div class="sourceCode" id="cb7"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb7-1"><a href="#cb7-1" aria-hidden="true" tabindex="-1"></a>x <span class="ot">&lt;-</span> <span class="cn">TRUE</span></span>
<span id="cb7-2"><a href="#cb7-2" aria-hidden="true" tabindex="-1"></a>y <span class="ot">&lt;-</span> <span class="cn">FALSE</span></span>
<span id="cb7-3"><a href="#cb7-3" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb7-4"><a href="#cb7-4" aria-hidden="true" tabindex="-1"></a>x <span class="sc">&amp;</span> <span class="sc">!</span>y</span></code></pre></div>
<ol type="1">
<li>TRUE</li>
<li>FALSE</li>
<li>NA</li>
</ol>
</section>
<section id="conditional-execution" class="slide level2">
<h2>Conditional execution</h2>
@ -2873,11 +2907,11 @@ mean( ), median( ), mode( ) )</li>
<li>Relational and logical operations allow for conditional execution of
code</li>
</ul>
<div class="sourceCode" id="cb6"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> (<span class="st">&quot;Akita&quot;</span> <span class="sc">%in%</span> dog_breeds) {</span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">print</span>(<span class="st">&quot;dog_breeds already contains Akita&quot;</span>)</span>
<span id="cb6-3"><a href="#cb6-3" aria-hidden="true" tabindex="-1"></a>} <span class="cf">else</span> {</span>
<span id="cb6-4"><a href="#cb6-4" aria-hidden="true" tabindex="-1"></a> dog_breeds <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">&quot;Akita&quot;</span>, dog_breeds)</span>
<span id="cb6-5"><a href="#cb6-5" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="cf">if</span> (<span class="st">&quot;Akita&quot;</span> <span class="sc">%in%</span> dog_breeds) {</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> <span class="fu">print</span>(<span class="st">&quot;dog_breeds already contains Akita&quot;</span>)</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a>} <span class="cf">else</span> {</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> dog_breeds <span class="ot">&lt;-</span> <span class="fu">c</span>(<span class="st">&quot;Akita&quot;</span>, dog_breeds)</span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<pre><code>## [1] &quot;dog_breeds already contains Akita&quot;</code></pre>
</section></section>
<section>
@ -2902,29 +2936,46 @@ R</strong> functions</li>
<li>To define a function we use the function keyword, the output is
specified with the <strong>return</strong> keyword:</li>
</ul>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a>add_dog <span class="ot">&lt;-</span> <span class="cf">function</span>(dog_to_add,</span>
<span id="cb8-2"><a href="#cb8-2" aria-hidden="true" tabindex="-1"></a> input_vector) {</span>
<span id="cb8-3"><a href="#cb8-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (dog_to_add <span class="sc">%in%</span> input_vector) {</span>
<span id="cb8-4"><a href="#cb8-4" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb8-5"><a href="#cb8-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">message</span>(<span class="st">&quot;Already contains this dog&quot;</span>)</span>
<span id="cb8-6"><a href="#cb8-6" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb8-7"><a href="#cb8-7" aria-hidden="true" tabindex="-1"></a> } <span class="cf">else</span> {</span>
<span id="cb8-8"><a href="#cb8-8" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb8-9"><a href="#cb8-9" aria-hidden="true" tabindex="-1"></a> output <span class="ot">&lt;-</span> <span class="fu">c</span>(dog_to_add, input_vector)</span>
<span id="cb8-10"><a href="#cb8-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(output)</span>
<span id="cb8-11"><a href="#cb8-11" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb8-12"><a href="#cb8-12" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb8-13"><a href="#cb8-13" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<div class="sourceCode" id="cb10"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb10-1"><a href="#cb10-1" aria-hidden="true" tabindex="-1"></a>add_dog <span class="ot">&lt;-</span> <span class="cf">function</span>(dog_to_add,</span>
<span id="cb10-2"><a href="#cb10-2" aria-hidden="true" tabindex="-1"></a> input_vector) {</span>
<span id="cb10-3"><a href="#cb10-3" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (dog_to_add <span class="sc">%in%</span> input_vector) {</span>
<span id="cb10-4"><a href="#cb10-4" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb10-5"><a href="#cb10-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">message</span>(<span class="st">&quot;Already contains this dog&quot;</span>)</span>
<span id="cb10-6"><a href="#cb10-6" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb10-7"><a href="#cb10-7" aria-hidden="true" tabindex="-1"></a> } <span class="cf">else</span> {</span>
<span id="cb10-8"><a href="#cb10-8" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb10-9"><a href="#cb10-9" aria-hidden="true" tabindex="-1"></a> output <span class="ot">&lt;-</span> <span class="fu">c</span>(dog_to_add, input_vector)</span>
<span id="cb10-10"><a href="#cb10-10" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(output)</span>
<span id="cb10-11"><a href="#cb10-11" aria-hidden="true" tabindex="-1"></a> </span>
<span id="cb10-12"><a href="#cb10-12" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb10-13"><a href="#cb10-13" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
</section>
<section id="example" class="slide level2">
<h2>Example</h2>
<div class="sourceCode" id="cb9"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="fu">add_dog</span>(<span class="at">dog_to_add =</span> <span class="st">&quot;Akita&quot;</span>,</span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a> <span class="at">input_vector =</span> dog_breeds)</span></code></pre></div>
<pre><code>## Already contains this dog</code></pre>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">add_dog</span>(<span class="at">dog_to_add =</span> <span class="st">&quot;German Shepard&quot;</span>,</span>
<div class="sourceCode" id="cb11"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="fu">add_dog</span>(<span class="at">dog_to_add =</span> <span class="st">&quot;Akita&quot;</span>,</span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a> <span class="at">input_vector =</span> dog_breeds)</span></code></pre></div>
<pre><code>## Already contains this dog</code></pre>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="fu">add_dog</span>(<span class="at">dog_to_add =</span> <span class="st">&quot;German Shepard&quot;</span>,</span>
<span id="cb13-2"><a href="#cb13-2" aria-hidden="true" tabindex="-1"></a> <span class="at">input_vector =</span> dog_breeds)</span></code></pre></div>
<pre><code>## [1] &quot;German Shepard&quot; &quot;Labrador Retriever&quot; &quot;Akita&quot;
## [4] &quot;Bulldog&quot;</code></pre>
</section>
<section id="poll-6" class="slide level2">
<h2>Poll 6</h2>
<p><strong>What does this function do?</strong></p>
<div class="sourceCode" id="cb15"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a>mystery_function <span class="ot">&lt;-</span> <span class="cf">function</span>(x) {</span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">if</span> (x <span class="sc">&gt;</span> <span class="dv">0</span>) {</span>
<span id="cb15-3"><a href="#cb15-3" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(x)</span>
<span id="cb15-4"><a href="#cb15-4" aria-hidden="true" tabindex="-1"></a> } <span class="cf">else</span> {</span>
<span id="cb15-5"><a href="#cb15-5" aria-hidden="true" tabindex="-1"></a> <span class="fu">return</span>(<span class="sc">-</span>x)</span>
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a> }</span>
<span id="cb15-7"><a href="#cb15-7" aria-hidden="true" tabindex="-1"></a>}</span></code></pre></div>
<ol type="1">
<li>Returns the absolute value of x</li>
<li>Returns x</li>
<li>Returns the square root of x</li>
<li>Returns -x</li>
</ol>
</section></section>
<section>
<section id="packages" class="title-slide slide level1">

View file

@ -3862,7 +3862,7 @@ modified by adding layers</li>
<section id="min-break" class="title-slide slide level1">
<h1>10 min break</h1>
<center>
<div class="countdown" id="timer_9ee5e107" data-update-every="1" tabindex="0" style="right:0;bottom:0;margin:5%;padding:50px;font-size:5em;position: relative; width: min-content;">
<div class="countdown" id="timer_7be64788" data-update-every="1" tabindex="0" style="right:0;bottom:0;margin:5%;padding:50px;font-size:5em;position: relative; width: min-content;">
<div class="countdown-controls"><button class="countdown-bump-down"></button><button class="countdown-bump-up">+</button></div>
<code class="countdown-time"><span class="countdown-digits minutes">10</span><span class="countdown-digits colon">:</span><span class="countdown-digits seconds">00</span></code>
</div>

View file

@ -35,8 +35,8 @@ Senior Statistician
**What is your level of experience with coding/data analysis?**
1. I am fluent in another data analysis programming language (Python, Matlab etc.)
2. I am use Excel to do linear regression
1. I know another data analysis programming language (Python, Matlab etc.)
2. I can use Excel to do linear regression
3. I know some R
4. All of the above
5. None of the above
@ -119,6 +119,7 @@ feature rich graphical user interface (GUI)
- Let's create an `Rmd` file in `RStudio` to explore the basics of how they work:
- File -\> New File -\> R Markdown
## R Markdown Advanced Usage
- **Presentations:** Creating slides (like these) with [revealjs](https://github.com/rstudio/revealjs).
@ -175,16 +176,26 @@ DogBreeds <- c("Labrador Retriever", "Akita", "Bulldog")
## Data Types
- Integer
- Whole numbers
- Whole numbers (in R denote with L ex. 1L,2L)
- Numeric
- Decimal numbers
- Logical
- Boolean (TRUE, FALSE)
- NA
- NA (missing data)
- Character
- Letters and strings of letters
- "A", "Labrador Retriever"
## Poll 3
**Which of these is not the correct data type for the value?**
1. 1.5 - Numeric
2. "Labrador Retriever" - Character
3. NA - Logical
4. 1 - Integer
## Data Structures
- Vectors
- Atomic vectors - one dimensional lists that store values of
@ -242,6 +253,19 @@ x >= y # Greater than or equal to
x %in% y # Is x in this vector y?
```
## Poll 4
**What is the output of the following code?**
```{r, eval = FALSE}
4 %in% as.character(c(1,2,3,4))
```
1. TRUE
2. FALSE
3. NA
## Logical Operators
- Logical operators can compare TRUE or FALSE values
```{r, eval=FALSE}
@ -251,9 +275,22 @@ y <- FALSE
!x # Not x
x | y # x or y
x & y # x and y
```
## Poll 5
**What is the output of the following code?**
```{r, eval=FALSE}
x <- TRUE
y <- FALSE
x & !y
```
1. TRUE
2. FALSE
3. NA
## Conditional execution
- Relational and logical operations allow for conditional
@ -308,6 +345,27 @@ add_dog(dog_to_add = "German Shepard",
input_vector = dog_breeds)
```
## Poll 6
**What does this function do?**
```{r, eval = FALSE}
mystery_function <- function(x) {
if (x > 0) {
return(x)
} else {
return(-x)
}
}
```
1. Returns the absolute value of x
2. Returns x
3. Returns the square root of x
4. Returns -x
# Packages
## Packages