-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Organizing and struturing practice session 2.
- Loading branch information
1 parent
2cb27fc
commit 5f5453c
Showing
4 changed files
with
82 additions
and
18 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
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,23 +1,85 @@ | ||
## Learning Objectives {.unnumbered} | ||
|
||
- practice tidyverse R skills | ||
- Practice cleaning and wrangling data | ||
- Practice using `dplyr` and `tidyr` functions | ||
- Learn how to use the `tibble::tibble()` function to create a data frame | ||
|
||
### Introduction | ||
## Introduction | ||
|
||
In this session of R practice, we will continue working with the dataset: [Tobias Schwoerer, Kevin Berry, and Jorene Joe. 2022. A household survey documenting experiences with coastal hazards in a western Alaska community (2021-2022). Arctic Data Center. doi:10.18739/A29Z90D3V.](https://doi.org/10.18739/A29Z90D3V) | ||
|
||
In this practice session, we will build upon the previous session by using `dplyr`, `tidyr`, and other packages form the tidyverse to create more summarizations of the survey answers. | ||
::: callout-tip | ||
## Big Idea | ||
|
||
### High level steps | ||
In this practice session, we will build upon the previous session by using `dplyr`, `tidyr`, and other packages form the tidyverse to summarize answers of the survey. | ||
::: | ||
|
||
- work in the same Rmd you did during R practice I | ||
- add necessary headers and text to describe what you are doing during this practice | ||
- using `group_by` and `summarize`, calculate how many responses there were to each unique answer for question 3 | ||
- create a `data.frame` containing the definitions to the answer codes in question 3 | ||
- use the metadata to get code-definition pairs | ||
- create your `data.frame` either by writing a new file and reading it in, or by exploring the function `tribble` (see the examples) | ||
- use a `left_join` to join your definitions table to the summarized answers | ||
## Exercise 2 | ||
|
||
#### Bonus {.unnumbered} | ||
::: callout-tip | ||
## Set up | ||
|
||
- Work in the same Qmd you did during R practice 1. | ||
- Add necessary headers and text to describe what you are doing during this practice. | ||
- Using Split-Apply-Combine strategy | ||
- Creating a Data Frame | ||
- Joining Data Frames | ||
|
||
- At the top of your document, one line below the three dashed line from the YAML, add a level 2 header called Setup followed by a new code chunk to load the necessary libraries. | ||
|
||
```{r} | ||
library(readr) | ||
library(dplyr) | ||
library(tidyr) | ||
library(tibble) | ||
``` | ||
|
||
|
||
::: | ||
|
||
### Using Split-Apply-Combine strategy | ||
|
||
::: callout-note | ||
## Step 1 | ||
|
||
Use `group_by` and `summarize` to calculate how many responses there were to each unique answer for question 3. | ||
::: | ||
|
||
|
||
::: {.callout-note appearance="minimal" collapse="true"} | ||
## Example Code | ||
|
||
|
||
```{r} | ||
#q3_summary <- | ||
``` | ||
|
||
::: | ||
|
||
### Creating a Data Frame | ||
|
||
::: callout-note | ||
## Step 2 | ||
Create a `data.frame` containing the definitions to the answer codes in Question 3. Use the [metadata](https://arcticdata.io/catalog/view/doi%3A10.18739%2FA29Z90D3V#urn%3Auuid%3Aab696e67-8ed0-4900-b568-4ee576bc87bd) to get code-definition pairs. | ||
|
||
One way of creating a new data frame is by using the `tribble()` or `tibble()` functions from the [`tibble` package](https://tibble.tidyverse.org/index.html). | ||
|
||
**Tip:** Search either in the help page or on the web for information about `tribble()` or `tibble()`. Then decide which on to use to create a new data frame. | ||
|
||
::: | ||
|
||
### Joining Data Frames | ||
|
||
::: callout-note | ||
## Step 3 | ||
Use a `left_join` to join your definitions table to the summarized answers | ||
::: | ||
|
||
## Bonus | ||
|
||
::: callout-note | ||
## Go Further | ||
Explore how you might summarize other questions in these survey results. | ||
::: |
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 |
---|---|---|
|
@@ -14,5 +14,4 @@ execute: | |
|
||
|
||
|
||
|
||
{{< include /sections/exercise-intro-programming-socialsci.qmd >}} |
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,7 +1,10 @@ | ||
|
||
--- | ||
title: "Practice Session II" | ||
title: "R Practice: Cleaning and Wrangling" | ||
title-block-banner: true | ||
execute: | ||
eval: false | ||
--- | ||
|
||
|
||
|
||
{{< include /sections/exercise-tidyverse-socialsci.qmd >}} |