Exploratory Data Analysis

Logo

Data Science Institute
Vanderbilt University


Course Overview
Course Materials
Course Policies

View the Project on GitHub dsi-explore/eda-course-website

Week 12 Homework Assignment:

Using the workbook from the election_maps git repo from Week 12 day 1, write a paragraph explaining each block of r code.

For example, the following block:

{r mi_pa_nh_margin, cache=TRUE, dependson="omit_ak_hi"} state_votes %>% filter(state %in% c("MI", "NH", "PA", "WI")) %>% select(state, democrat, republican, margin) %>% arrange(abs(margin)) %>% mutate(margin = percent(margin, accuracy = 0.01))

Is described by the following paragraph:

The block heading names the code block “mi pa nh margin,” which makes it easier to reference. It depends on the “omit ak hi” code block, which omitted the Alaska and Hawaii cases. The state_votes dataframe is passed to the filter() verb, which selects MI, NH, PA, and WI cases. The filtered dataframe is passed to the select() verb, which keeps the state, democrat, republican, and margin variables. The filtered and selected dataframe is then arranged by the absolute value of the margin of victory by the arrange() verb, and then mutated to produce a variable of margin percentage to the 0.01 level of accuracy. The result is a dataframe that shows percentage margin of victory to the 0.01 level in Michigan, New Hampshire, Pennsylvania, and Wisconsin.