Learn R Programming

moderndive (version 0.4.0)

DD_vs_SB: Dunkin Donuts vs Starbucks

Description

Number of Dunkin Donuts & Starbucks, median income, and population in 1024 census tracts in eastern Massachusetts in 2016.

Usage

DD_vs_SB

Arguments

Format

A data frame of 1024 rows representing census tracts and 6 variables

county

County where census tract is located. Either Bristol, Essex, Middlesex, Norfolk, Plymouth, or Suffolk county

FIPS

Federal Information Processing Standards code identifying census tract

median_income

Median income of census tract

population

Population of census tract

shop_type

Coffee shop type: Dunkin Donuts or Starbucks

shops

Number of shops

Examples

Run this code
# NOT RUN {
# Compute correlation between a census tract's median income and number of cafes of
# each type after removing two cases where median_income is missing
library(dplyr)
DD_vs_SB %>% 
  mutate(shops_per_1000 = 1000 * shops/population) %>% 
  filter(!is.na(median_income)) %>% 
  group_by(shop_type) %>% 
  summarize(cor = cor(median_income, shops_per_1000))
# }

Run the code above in your browser using DataLab