Skip to content

Commit

Permalink
things happened
Browse files Browse the repository at this point in the history
  • Loading branch information
dKvale committed Nov 28, 2023
1 parent 236c6a1 commit f596a37
Show file tree
Hide file tree
Showing 13 changed files with 267 additions and 279 deletions.
146 changes: 73 additions & 73 deletions content/page/exercise/Find_the_penguin.Rmd
Original file line number Diff line number Diff line change
@@ -1,73 +1,73 @@
---
title: 'Exercise: Identify penguins using `filter()` and `case_when()`'
author: "Abigail Stamm"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Exercise 1: filtering data

The goal of this exercise is to filter a dataset using repeated filter commands until you only have one row of data left.

Using the `penguins` dataset in the `palmerpenguins` package, isolate a penguin who meets one of the following sets of criteria. What is its study number?

1. I am a female Adelie penguin hatched on November 12th on Biscoe Island. I was part of the latest study.
1. I am a male Chinstrap penguin weighing over 4kg. My bill is over 5cm long, but my flippers are less than 20cm long.
1. I am a female Gentoo penguin weighing over 5kg, but my bill is shorter at under 4.5cm long.

For a greater challenge, try to isolate these penguins.

1. I have the lowest weight of the male penguins.
1. I am the heaviest female Adelie penguin.
1. I have the longest flippers of the Adelie penguins on Dream Island.


<details>
<summary>Code hint</summary>
Example:
`filter(data, x < 0)`
Remember to account for `NA` values.

<details>
<summary>Advanced code hint</summary>
Example:
`filter(body_mass_g > 4000)`

<details>
<summary>Precise code hint</summary>
Example:
`filter(penguins, body_mass_g == min(body_mass_g, na.rm = TRUE))`

</details>
</details>
</details>


## Exercise 2: using case_when

Select the same penguin that you selected above. Create a new variable using case_when that uses the criteria provided to identify your selected penguin and and only your selected penguin in your dataset.

<details>
<summary>Code hint</summary>
Example:
`case_when(x == y ~ TRUE, .default = FALSE)`

<details>
<summary>Advanced code hint</summary>
Example:
`case_when(body_mass_g > 4000 ~ TRUE, .default = FALSE)`

<details>
<summary>Precise code hint</summary>
Example:
`mutate(penguins, subject = case_when(body_mass_g > 4000 & bill_length_mm > 50 ~ TRUE, .default = FALSE))`

</details>
</details>
</details>



---
title: Guess who!
author: "Abigail Stamm"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

## Exercise 1: filtering data

The goal of this exercise is to filter a dataset using repeated filter commands until you only have one row of data left.

Using the `penguins` dataset in the `palmerpenguins` package, isolate a penguin who meets one of the following sets of criteria. What is its study number?

1. I am a female Adelie penguin hatched on November 12th on Biscoe Island. I was part of the latest study.
1. I am a male Chinstrap penguin weighing over 4kg. My bill is over 5cm long, but my flippers are less than 20cm long.
1. I am a female Gentoo penguin weighing over 5kg, but my bill is shorter at under 4.5cm long.

For a greater challenge, try to isolate these penguins.

1. I have the lowest weight of the male penguins.
1. I am the heaviest female Adelie penguin.
1. I have the longest flippers of the Adelie penguins on Dream Island.


<details>
<summary>**CODE HINT**</summary>
Example:
`filter(data, x < 0)`
Remember to account for `NA` values.

<details>
<summary>**ADVANCED *CODE HINT**</summary>
Example:
`filter(body_mass_g > 4000)`

<details>
<summary>**PRECISE CODE HINT**</summary>
Example:
`filter(penguins, body_mass_g == min(body_mass_g, na.rm = TRUE))`

</details>
</details>
</details>


## Exercise 2: using case_when

Select the same penguin that you selected above. Create a new variable using case_when that uses the criteria provided to identify your selected penguin and only your selected penguin in your dataset.

<details>
<summary>**CODE HINT**</summary>
Example:
`case_when(x == y ~ TRUE, .default = FALSE)`

<details>
<summary>**ADVANCED *CODE HINT**</summary>
Example:
`case_when(body_mass_g > 4000 ~ TRUE, .default = FALSE)`

<details>
<summary>**PRECISE CODE HINT**</summary>
Example:
`mutate(penguins, subject = case_when(body_mass_g > 4000 & bill_length_mm > 50 ~ TRUE, .default = FALSE))`

</details>
</details>
</details>



48 changes: 20 additions & 28 deletions content/page/exercise/Find_the_penguin.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 'Exercise: Identify penguins using `filter()` and `case_when()`'
title: Guess who!
author: "Abigail Stamm"
output: html_document
---
Expand All @@ -8,40 +8,35 @@

<div id="exercise-1-filtering-data" class="section level2">
<h2>Exercise 1: filtering data</h2>
<p>The goal of this exercise is to filter a dataset using repeated
filter commands until you only have one row of data left.</p>
<p>Using the <code>penguins</code> dataset in the
<code>palmerpenguins</code> package, isolate a penguin who meets one of
the following sets of criteria. What is its study number?</p>
<p>The goal of this exercise is to filter a dataset using repeated filter commands until you only have one row of data left.</p>
<p>Using the <code>penguins</code> dataset in the <code>palmerpenguins</code> package, isolate a penguin who meets one of the following sets of criteria. What is its study number?</p>
<ol style="list-style-type: decimal">
<li>I am a female Adelie penguin hatched on November 12th on Biscoe
Island. I was part of the latest study.</li>
<li>I am a male Chinstrap penguin weighing over 4kg. My bill is over 5cm
long, but my flippers are less than 20cm long.</li>
<li>I am a female Gentoo penguin weighing over 5kg, but my bill is
shorter at under 4.5cm long.</li>
<li>I am a female Adelie penguin hatched on November 12th on Biscoe Island. I was part of the latest study.</li>
<li>I am a male Chinstrap penguin weighing over 4kg. My bill is over 5cm long, but my flippers are less than 20cm long.</li>
<li>I am a female Gentoo penguin weighing over 5kg, but my bill is shorter at under 4.5cm long.</li>
</ol>
<p>For a greater challenge, try to isolate these penguins.</p>
<ol style="list-style-type: decimal">
<li>I have the lowest weight of the male penguins.</li>
<li>I am the heaviest female Adelie penguin.</li>
<li>I have the longest flippers of the Adelie penguins on Dream
Island.</li>
<li>I have the longest flippers of the Adelie penguins on Dream Island.</li>
</ol>
<details>
<summary>
Code hint
<strong>CODE HINT</strong>
</summary>
<p>Example: <code>filter(data, x &lt; 0)</code><br />
<p>Example:
<code>filter(data, x &lt; 0)</code><br />
Remember to account for <code>NA</code> values.</p>
<details>
<summary>
Advanced code hint
**ADVANCED *CODE HINT**
</summary>
<p>Example: <code>filter(body_mass_g &gt; 4000)</code></p>
<p>Example:
<code>filter(body_mass_g &gt; 4000)</code></p>
<details>
<summary>
Precise code hint
<strong>PRECISE CODE HINT</strong>
</summary>
<p>Example:
<code>filter(penguins, body_mass_g == min(body_mass_g, na.rm = TRUE))</code></p>
Expand All @@ -51,29 +46,26 @@ <h2>Exercise 1: filtering data</h2>
</div>
<div id="exercise-2-using-case_when" class="section level2">
<h2>Exercise 2: using case_when</h2>
<p>Select the same penguin that you selected above. Create a new
variable using case_when that uses the criteria provided to identify
your selected penguin and and only your selected penguin in your
dataset.</p>
<p>Select the same penguin that you selected above. Create a new variable using case_when that uses the criteria provided to identify your selected penguin and only your selected penguin in your dataset.</p>
<details>
<summary>
Code hint
<strong>CODE HINT</strong>
</summary>
<p>Example: <code>case_when(x == y ~ TRUE, .default = FALSE)</code></p>
<p>Example:
<code>case_when(x == y ~ TRUE, .default = FALSE)</code></p>
<details>
<summary>
Advanced code hint
**ADVANCED *CODE HINT**
</summary>
<p>Example:
<code>case_when(body_mass_g &gt; 4000 ~ TRUE, .default = FALSE)</code></p>
<details>
<summary>
Precise code hint
<strong>PRECISE CODE HINT</strong>
</summary>
<p>Example:
<code>mutate(penguins, subject = case_when(body_mass_g &gt; 4000 &amp; bill_length_mm &gt; 50 ~ TRUE, .default = FALSE))</code></p>
</details>
</details>
</details>
</div>

8 changes: 4 additions & 4 deletions content/page/exercise/day1/inventory_duty.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ Click **Create project**.
Now that you have a new project setup (you should see your project name in the top right of RStudio), create a new R script and save it.

- To make a new R script:
- Go to `File` -> `New File` -> `R Script` or
- Go to `File` -> `New File` -> `R Script` -or-
- Click the top left icon with the green plus sign


You can now save the script by clicking `CTRL` + `S` or by clicking the floppy disk icon. Name your script something pithy like `ex_1_day_1.R` or `frankie.R`.
You can now save the script by clicking <kbd>CTRL</kbd> + <kbd>S</kbd> or by clicking the floppy disk icon. Name your script something pithy like `ex_1_day_1.R` or `frankie.R`.

You're ready to go!

Expand Down Expand Up @@ -167,7 +167,7 @@ cat(paste0(tab_html, collapse = "\n"))

<br>

Look at that. We have a **total** row - that sure could have thrown a wrench in our summaries. That row is also adding `NA`s to other columns which might make some of our analysis harder in the future. Let's get rid of this summary row and keep only the *real data*.
Look at that. We have a **total** row - that would a wrench in our summaries. That row is also adding `NA`s to other columns which might make some of our analysis harder in the future. Let's get rid of this summary row and keep only the *real data*.

> **NOTE:** Lots of functions you'll meet in R will have the additional argument `na.rm = TRUE`, which allows us to ignore NA values when calculating things like means, maxes, etc. Super handy!
Expand Down Expand Up @@ -261,7 +261,7 @@ cat(paste0(tab_html, collapse = "\n"))

That's just what I expected. We've been getting lots of orders for our **Gluten-free Applesauce** and **Walnut muffins**, and also for our **Triple-Chocolate Brownies**. Time for an urgent supply order so we don't run out!

The last thing to do is to write/save the filtered data so we can send it to the lead baking-bot.
The last thing to do is to write/save the filtered data.

```{r, eval=F}
write_csv(x = order_now, file = "order_now.csv")
Expand Down
8 changes: 4 additions & 4 deletions content/page/exercise/day1/inventory_duty.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,11 @@ <h1><span class="header-section-number">1</span> Before you start…</h1>
<ul>
<li>To make a new R script:
<ul>
<li>Go to <code>File</code> -&gt; <code>New File</code> -&gt; <code>R Script</code> or</li>
<li>Go to <code>File</code> -&gt; <code>New File</code> -&gt; <code>R Script</code> -or-</li>
<li>Click the top left icon with the green plus sign</li>
</ul></li>
</ul>
<p>You can now save the script by clicking <code>CTRL</code> + <code>S</code> or by clicking the floppy disk icon. Name your script something pithy like <code>ex_1_day_1.R</code> or <code>frankie.R</code>.</p>
<p>You can now save the script by clicking <kbd>CTRL</kbd> + <kbd>S</kbd> or by clicking the floppy disk icon. Name your script something pithy like <code>ex_1_day_1.R</code> or <code>frankie.R</code>.</p>
<p>You’re ready to go!</p>
</div>
<div id="inventory-duty" class="section level1" number="2">
Expand Down Expand Up @@ -217,7 +217,7 @@ <h3><i class="fas fa-cookie-bite" style="color: gray;"></i> Investigation underw
</div>
</div>
<p><br></p>
<p>Look at that. We have a <strong>total</strong> row - that sure could have thrown a wrench in our summaries. That row is also adding <code>NA</code>s to other columns which might make some of our analysis harder in the future. Let’s get rid of this summary row and keep only the <em>real data</em>.</p>
<p>Look at that. We have a <strong>total</strong> row - that would a wrench in our summaries. That row is also adding <code>NA</code>s to other columns which might make some of our analysis harder in the future. Let’s get rid of this summary row and keep only the <em>real data</em>.</p>
<blockquote>
<p><strong>NOTE:</strong> Lots of functions you’ll meet in R will have the additional argument <code>na.rm = TRUE</code>, which allows us to ignore NA values when calculating things like means, maxes, etc. Super handy!</p>
</blockquote>
Expand Down Expand Up @@ -323,7 +323,7 @@ <h3><i class="fas fa-cookie-bite" style="color: gray;"></i> Time to order?</h3>
</div>
<p><br></p>
<p>That’s just what I expected. We’ve been getting lots of orders for our <strong>Gluten-free Applesauce</strong> and <strong>Walnut muffins</strong>, and also for our <strong>Triple-Chocolate Brownies</strong>. Time for an urgent supply order so we don’t run out!</p>
<p>The last thing to do is to write/save the filtered data so we can send it to the lead baking-bot.</p>
<p>The last thing to do is to write/save the filtered data.</p>
<div class="sourceCode" id="cb4"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb4-1"><a href="#cb4-1" tabindex="-1"></a><span class="fu">write_csv</span>(<span class="at">x =</span> order_now, <span class="at">file =</span> <span class="st">&quot;order_now.csv&quot;</span>)</span></code></pre></div>
<p><br></p>
<p>Excellent! We’ll send this out so we get those ingredients right away. Even better, next inventory time we’ll have these scripted steps that we can use again and again and again…well you get the idea.</p>
Expand Down
22 changes: 13 additions & 9 deletions content/page/exercise/day1/inventory_duty_expanded.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Jump back into the project you created for the previous exercise and then create

# Auditor-in-training

The lead baking-bot is very impressed with our recent work. And now they've asked us perform a complete audit. This is our dream come true. No one has been so excited to do an audit as we are RIGHT NOW!
The lead baking-bot is very impressed with our recent work. And now they've asked us perform a complete audit. This is our absolute dream come true. No one has been so excited to do an audit as we are RIGHT NOW!

In the audit we need to:

Expand Down Expand Up @@ -108,6 +108,7 @@ filter(audit_df, is.na( _____ ) )
code_end',
show_code = 'code_start
filter(audit_df, is.na(CATEGORY))
code_end')
Expand Down Expand Up @@ -155,7 +156,7 @@ source("../../insert_tabs.R")
tabs <- c("Updating values", "Show hint", "Show code")
content <- c(Exercise = '<h4> Now we have the row and column location of the missing value and the types of acceptable values that it should be, overwrite the NA with the new value you picked. </h4>
content <- c(Exercise = '<b> Now we have the row and column location of the missing value and the types of acceptable values that it should be, overwrite the NA with the new value you picked. </b>
<br>',
Expand All @@ -179,13 +180,11 @@ cat(paste0(tab_html, collapse = "\n"))
```
</div>

<br>

# Overstocking
# Overstocked: Too many goods

- Check for overstocking: **"No ingredient is more than 10 above the order threshold."**

I suppose we don't want too much stock laying around or it might spoil. Let's use filter to check each of the ingredient stock values and see if any are more than 10 above its order threshold. We've got this!
We don't want too much food laying around or it might spoil. Let's use filter to check each of the ingredient stock values and see if any are more than 10 above its order threshold. We've got this!

<div class="quiz">

Expand Down Expand Up @@ -225,7 +224,7 @@ cat(paste0(tab_html, collapse = "\n"))

<br>

Looks like we might need to make some emergency Oatmeal Raisin cookies to get our stock down a bit, but we don't think people will mind that much. Nice work!
Looks like we might need to make some emergency Oatmeal Raisin cookies to get our stock down a bit, but I don't think people will mind that much. Nice work!


# Summary statistics by group
Expand All @@ -243,15 +242,20 @@ dry <- filter(audit_df, DRY_OR_LIQUID_MEASUREMENT == "DRY")
```


Hmmm... something feels funny. Our original dataset had 36 observation, now we have one with 28 and another with 7. That only adds up to 35... seems we dropped an observation somewhere.
Hmmm... something feels funny. Our original dataset had 36 observation, now we have one with 28 and another with 7. That only adds up to 35... seems we lost an observation somewhere.

Maybe there's a typo in the column?

Maybe there's a typo in the column? Let's use `unique` to see if there are more than two values in the column DRY_OR_LIQUID_MEASUREMENT.

Let's use `unique` to see if there are more than two values in the column DRY_OR_LIQUID_MEASUREMENT.


```{r}
unique(audit_df$DRY_OR_LIQUID_MEASUREMENT)
```

<br>


Uh-oh, we have an NA value. Filter will only keep a row if it knows for sure that it meets the condition. So if there is a missing or NA value, we literally don't know the value, and R is unable to determine if it equals "DRY" or not.

Expand Down
Loading

0 comments on commit f596a37

Please sign in to comment.