Exercises to Accompany TeachingWithR Workshop

Exercises to Accompany TeachingWithR Workshop

Matthew Beckman & Justin Post June 25, 2021


Part 1. RStudio IDE Scavenger Hunt

[omitted for brevity…]


Part 2. Import Data (Code Recap)


## from instructions before workshop, if needed:
# devtools::install_github("mdbeckman/dcData")

# packages
library(tidyverse)  
library(dcData)     

# data intake
data("BabyNames", package = "dcData")

BabyNamesSupp <- 
  read_csv("https://jbpost2.github.io/TeachingWithR/datasets/BabyNamesSupp.csv")

# 2020 data intake was issued as a challenge task only
BabyNames2020 <-   
    read_csv("https://jbpost2.github.io/TeachingWithR/datasets/yob2020.txt", 
             col_names = FALSE)


# inspecting the data
head(BabyNamesSupp)
tail(BabyNamesSupp)

Part 3. R Markdown

Note: you might hang onto the RStudio default text provided in the new R Markdown file for the moment… it’s packed with tiny examples that will come in handy!


3.1 Goal

We’ll be investigating the popularity of names in the US each year. Choose a few (4-5) names to investigate to you–friends, family, TV character, colleagues in the workshop!


Solution (for example)

Matt has chosen the names of his family members: Matthew, Sarah, Eden, Jack, & Hazel.


3.2 Update yaml Header

---
title: "Add a title"
author: "Add your name"
date: "Pick a date"
output: html_document
---

Solution (for example)

Task 3.2.2: Your yaml header should appear at the beginning of the Rmd document, but here is some example text

---
title: "What's in a Name??"
author: "Matt Beckman & Justin Post"
date: "June 25, 2021"
output: html_document
---

3.3 Add Narrative & Code Chunk


Solution

Task 3.3.1:

Some sample narrative text follows; note that it is simply one long line of soft-wrapped text, and no formatting of any kind is imposed:

I’ve chosen to investigate the names of each person in my immediate family: Matthew, Sarah, Eden, Jack, and Hazel. They’re my favorite people, and also my favorite names! I’m a bit torn about how I’ll include my son Jack in the analysis. His legal name is “Jon” but he is nearly always called “Jack”–the spelling of “Jon” honors our scandinavian heritage on both sides of the family, and the nickname “Jack” specifically honors his great-grandfather.

Some famous persons by each name of the family include:

Task 3.3.2

# libraries
library(tidyverse)
library(dcData)

# data intake
data("BabyNames", package = "dcData")
BabyNamesSupp <- read_csv("https://jbpost2.github.io/TeachingWithR/datasets/BabyNamesSupp.csv",  
                          col_types = cols(sex = col_character()))  # fixes `sex`

Task 3.3.3

Here’s the code I used:

This document was last modified 2021-06-25 10:27:39.

3.4 Render Various Output Formats

R Markdown is a flexible syntax that can render the same .Rmd (text) file in different formats. If you know the syntax, you can update the output: directly in the yaml header. RStudio provides a shortcut as a (tiny) menu arrow next to the “Knit (yarn)” icon revealing a few common choices.


Part 4. Data wrangling

[coming up next…]