For the workshop, we’ve prebuilt a data set that has information about menus from three restaurants in Duke’s Brodhead Center.

1. Using what we’ve you’ve seen in class, if brodheadCenter.csv is a csv file, how would you load the file into a new object called brodhead?
library(tidyverse)
## -- Attaching packages -------- tidyverse 1.2.1 --
## v ggplot2 3.2.1     v purrr   0.3.2
## v tibble  2.1.3     v dplyr   0.8.3
## v tidyr   1.0.0     v stringr 1.4.0
## v readr   1.3.1     v forcats 0.4.0
## -- Conflicts ----------- tidyverse_conflicts() --
## x dplyr::lag()    masks stats::lag()
brodhead <- read_csv("https://raw.githubusercontent.com/data-and-visualization/Intro2R/master/data/brodheadCenter.csv")
## Parsed with column specification:
## cols(
##   name = col_character(),
##   type = col_character(),
##   itemType = col_character(),
##   itemName = col_character(),
##   cost = col_double(),
##   rating = col_double()
## )
# or
# brodhead <- read_csv("data/brodheadCenter.csv")  # if you cloned the repository
1. What data structure is brodhead?
class(brodhead)
## [1] "spec_tbl_df" "tbl_df"      "tbl"         "data.frame"
1. Take a look at the structure of the brodhead object.
• How many observations (rows) are there?
• How many variables (columns) are there?
• How many of the variables are numeric data?
glimpse(brodhead)
## Observations: 59
## Variables: 7
## $name <chr> "Devils Krafthouse", "Devils Krafthouse", "Devils Kra... ##$ type     <chr> "bar and grill", "bar and grill", "bar and grill", "b...
## $menuType <chr> "appetizer", "appetizer", "appetizer", "appetizer", "... ##$ itemType <chr> "snack", "snack", "snack", "snack", "snack", "snack",...
## $itemName <chr> "sweet potato tots", "french fries", "quesadillas", "... ##$ cost     <dbl> 4, 4, 6, 8, 7, 8, 9, 4, 9, 9, 9, 8, 4, 7, 7, 7, 8, 8,...
## \$ rating   <dbl> 8, 10, 5, 6, 7, 8, 5, 6, 5, 5, 6, 6, 8, 6, 7, 5, 6, 5...

## PART TWO: Data Wrangling

All of the following questions are based on the sample of restaurants represented in the dataset which is accurate as of September 2, 2016.

1. Which restaurant has the lowest cost item and what is the item?
brodhead %>%
arrange(cost) %>%
select(name, type, itemName, cost)
1. Which restaurant has the most expensive item(s)? What are those item(s)?
brodhead %>%
arrange(desc(cost)) %>%
select(name, type, itemName, cost)
1. At the Brodheat Center, how many of the entrees (found in the menuType variable) cost eight dollars?
brodhead %>%
filter(cost == 8, menuType == "entree") %>%
select(name, menuType, itemName, cost)
1. The head of Duke dining is considering reducing prices at the Brodhead Center. Using what we’ve learned in class, write a line of code that will calculate a new variable (halfPrice) that contains items at half price.
brodhead %>%
mutate(halfPrice = cost / 2) %>%
select(name, itemName, cost, halfPrice)
1. How many entrees are in the dataset (menuType variable)? How many desserts
brodhead %>%
count(menuType)