Week 6

Package dplyr

Monday, Feb 10

Learning objectives

  • Manipulate data frames with the core dplyr functions
  • Understand dplyr function rules
  • Utilize the pipe operator

Materials


Packages tidyr and purrr

Wednesday, Feb 12

Learning objectives

  • Understand tidy data
  • Reshape data
  • Address common untidy data problems
  • Iteration with [a-z]pply()
  • Iteration with purrr

Materials


Lab 6

Friday, Feb 14

GitHub

Learning objectives

  • Data wrangling with dplyr and tidyr
  • Effective visualization with ggplot2 and extensions

Materials


Exercise of the week

Let’s use object senators from Lab 5.

library(rjson)
library(tidyverse)
json_file <- "https://www.govtrack.us/api/v2/role?current=true&role_type=senator"
senators <- fromJSON(paste(readLines(json_file), collapse = ""))

Use one of the map_*() variants to get

  • the name of each senator as a character vector (preview given below),

    ## [1] "Sen. Lamar Alexander [R-TN]" "Sen. Susan Collins [R-ME]"  
    ## [3] "Sen. John Cornyn [R-TX]"     "Sen. Richard Durbin [D-IL]" 
    ## [5] "Sen. Michael Enzi [R-WY]"
    
  • the name of each senator as a list (preview given below),

    ## [[1]]
    ## [1] "Sen. Lamar Alexander [R-TN]"
    ## 
    ## [[2]]
    ## [1] "Sen. Susan Collins [R-ME]"
    ## 
    ## [[3]]
    ## [1] "Sen. John Cornyn [R-TX]"
    
  • the description and party of each senator as a data frame (preview given below)

    ## # A tibble: 4 x 2
    ##   description                  party     
    ##   <chr>                        <chr>     
    ## 1 Senior Senator for Tennessee Republican
    ## 2 Senior Senator for Maine     Republican
    ## 3 Senior Senator for Texas     Republican
    ## 4 Senior Senator for Illinois  Democrat
    
Previous
Next