-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
267 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.