UA Mini 2 Difference in sensitivity to price between Pizza and Grocery stores
R Setup
1 Study Area: Springfield Oregon
I selected Springfield, Oregon as my study area.
spring <- tigris::places('OR', progress_bar = F) %>%
filter(NAME == "Springfield") %>%
st_transform(4326)
tract_oregon <- tidycensus::get_acs(geography = "tract", # or "block group", "county", "state" etc.
state = "OR",
variables = c(hhincome = 'B19019_001'),
year = 2021,
survey = "acs5",
geometry = TRUE,
output = "wide") %>%
st_transform(4326)
:) | | | 0% | |======= | 1% | |============= | 3% | |==================== | 4% | |=========================== | 6% | |================================= | 7% | |======================================== | 8% | |=============================================== | 10% | |===================================================== | 11% | |============================================================ | 13% | |=================================================================== | 14% | |========================================================================= | 16% | |================================================================================ | 17% | |====================================================================================== | 18% | |============================================================================================= | 20% | |==================================================================================================== | 21% | |=============================================================================================================== | 24% | |====================================================================================================================== | 25% | |============================================================================================================================= | 27% | |=================================================================================================================================== | 28% | |========================================================================================================================================== | 29% | |================================================================================================================================================= | 31% | |======================================================================================================================================================= | 32% | |============================================================================================================================================================== | 34% | |===================================================================================================================================================================== | 35% | |=========================================================================================================================================================================== | 36% | |================================================================================================================================================================================== | 38% | |======================================================================================================================================================================================== | 39% | |=============================================================================================================================================================================================== | 41% | |====================================================================================================================================================================================================== | 42% | |============================================================================================================================================================================================================ | 43% | |========================================================================================================================================================================================================================= | 46% | |================================================================================================================================================================================================================================ | 48% | |====================================================================================================================================================================================================================================== | 49% | |============================================================================================================================================================================================================================================= | 50% | |==================================================================================================================================================================================================================================================== | 52% | |========================================================================================================================================================================================================================================================== | 53% | |================================================================================================================================================================================================================================================================= | 55% | |======================================================================================================================================================================================================================================================================== | 56% | |============================================================================================================================================================================================================================================================================== | 58% | |===================================================================================================================================================================================================================================================================================== | 59% | |============================================================================================================================================================================================================================================================================================ | 60% | |================================================================================================================================================================================================================================================================================================== | 62% | |========================================================================================================================================================================================================================================================================================================= | 63% | |================================================================================================================================================================================================================================================================================================================ | 65% | |====================================================================================================================================================================================================================================================================================================================== | 66% | |=================================================================================================================================================================================================================================================================================================================================== | 69% | |========================================================================================================================================================================================================================================================================================================================================== | 70% | |================================================================================================================================================================================================================================================================================================================================================ | 72% | |======================================================================================================================================================================================================================================================================================================================================================= | 73% | |============================================================================================================================================================================================================================================================================================================================================================== | 74% | |==================================================================================================================================================================================================================================================================================================================================================================== | 76% | |=========================================================================================================================================================================================================================================================================================================================================================================== | 77% | |================================================================================================================================================================================================================================================================================================================================================================================= | 79% | |======================================================================================================================================================================================================================================================================================================================================================================================== | 80% | |=============================================================================================================================================================================================================================================================================================================================================================================================== | 81% | |===================================================================================================================================================================================================================================================================================================================================================================================================== | 83% | |============================================================================================================================================================================================================================================================================================================================================================================================================ | 84% | |=================================================================================================================================================================================================================================================================================================================================================================================================================== | 86% | |========================================================================================================================================================================================================================================================================================================================================================================================================================= | 87% | |================================================================================================================================================================================================================================================================================================================================================================================================================================ | 89% | |============================================================================================================================================================================================================================================================================================================================================================================================================================================= | 91% | |=================================================================================================================================================================================================================================================================================================================================================================================================================================================== | 93% | |========================================================================================================================================================================================================================================================================================================================================================================================================================================================== | 94% | |================================================================================================================================================================================================================================================================================================================================================================================================================================================================= | 95% | |======================================================================================================================================================================================================================================================================================================================================================================================================================================================================= | 97% | |============================================================================================================================================================================================================================================================================================================================================================================================================================================================================== | 98% | |===================================================================================================================================================================================================================================================================================================================================================================================================================================================================================== | 100% | |======================================================================================================================================================================================================================================================================================================================================================================================================================================================================================| 100%
# I removed the census tract with the largest area (GEOID: 41039000200) because it barely touches the boundary of the City of Springfield.
tract_spring <- tract_oregon[spring, ] %>%
filter(as.character(GEOID) != "41039000200")
tract_spring
:) Simple feature collection with 23 features and 4 fields
:) Geometry type: MULTIPOLYGON
:) Dimension: XY
:) Bounding box: xmin: -123 ymin: 44 xmax: -123 ymax: 44.1
:) Geodetic CRS: WGS 84
:) First 10 features:
:) GEOID NAME hhincomeE hhincomeM geometry
:) 1 41039003103 Census Tract 31.03, Lane County, Oregon 84231 16278 MULTIPOLYGON (((-123 44.1, ...
:) 2 41039002104 Census Tract 21.04, Lane County, Oregon 35171 8497 MULTIPOLYGON (((-123 44.1, ...
:) 3 41039003500 Census Tract 35, Lane County, Oregon 64224 13390 MULTIPOLYGON (((-123 44, -1...
:) 4 41039003700 Census Tract 37, Lane County, Oregon 24475 4179 MULTIPOLYGON (((-123 44.1, ...
:) 5 41039003104 Census Tract 31.04, Lane County, Oregon 43226 7973 MULTIPOLYGON (((-123 44.1, ...
:) 6 41039003600 Census Tract 36, Lane County, Oregon 65746 11302 MULTIPOLYGON (((-123 44, -1...
:) 7 41039003202 Census Tract 32.02, Lane County, Oregon 60921 14134 MULTIPOLYGON (((-123 44.1, ...
:) 8 41039003301 Census Tract 33.01, Lane County, Oregon 60471 8362 MULTIPOLYGON (((-123 44.1, ...
:) 9 41039003302 Census Tract 33.02, Lane County, Oregon 48074 9036 MULTIPOLYGON (((-123 44.1, ...
:) 10 41039003400 Census Tract 34, Lane County, Oregon 51799 4260 MULTIPOLYGON (((-123 44, -1...
The black line shows the boundary of Springfield, and the polygons colored in either yellow or brown-ish color are census tracts. Additionally, I provided a cloropleth of the 23 census tracts in terms of the estimated median household income. High income neighborhoods are located at the outskirt of the city, both on the east and west side of the city.
tmap_mode('view')
tm_shape(tract_spring) +
tm_polygons(col = "hhincomeE", alpha=0.5) +
tm_shape(spring) +
tm_borders(col="black", lwd=2) +
tm_layout(
legend.title.size = 4,
legend.text.size = 5,
legend.position = c("right","bottom"),
main.title = "City of Springfield and 23 Census Tracts", main.title.position = "left", main.title.size = 7
) +
tm_layout(frame = FALSE)
2 Retrieve and tidy the Yelp data
# retrieving from the rds file stored from mini 01
yelp <- readRDS("assets/yelp_all_spring_sf.rds")
print(glue::glue("nrow: {nrow(yelp)}, ncol: {ncol(yelp)}"))
:) nrow: 131, ncol: 22
:) Simple feature collection with 6 features and 21 fields
:) Geometry type: POINT
:) Dimension: XY
:) Bounding box: xmin: -123 ymin: 44.1 xmax: -123 ymax: 44.1
:) Geodetic CRS: WGS 84
:) # A tibble: 6 × 22
:) id alias name image_url is_closed url review_count categories rating coordinates$latitude transactions price location$address1 phone display_phone distance business_hours attributes$business_…¹ category_manual_input x_coord y_coord geometry
:) <chr> <chr> <chr> <chr> <lgl> <chr> <int> <list> <dbl> <dbl> <list> <chr> <chr> <chr> <chr> <dbl> <list> <int> <chr> <dbl> <dbl> <POINT [°]>
:) 1 RW7UfCVzCtjdR8VjARO8AQ pegasus-pizza-eugene-3 Pegasus Pizza https://s3-media1.fl.yelpcdn.com/bphoto/k-7mgGV78S1vfUlimAiIdg/o.jpg FALSE https://www.yelp.com/biz/pegasus-pizza-eugene-3?adjust_creative=gI-YTe1_pV4ImhxKx_yj… 83 <df> 3.3 44.1 <chr [2]> $ 4 Oakway Ctr +154… (541) 344-08… 1043. <df [1 × 3]> NA pizza -123. 44.1 (-123 44.1)
:) 2 -OSaiVv0i9donG_5-Ov-kw mod-pizza-eugene MOD Pizza https://s3-media2.fl.yelpcdn.com/bphoto/jwQAWViCUiO7lJuxRkPdRw/o.jpg FALSE https://www.yelp.com/biz/mod-pizza-eugene?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&utm… 193 <df> 3.5 44.1 <chr [2]> $ 203 Coburg Rd +145… (458) 205-89… 1027. <df [1 × 3]> NA pizza -123. 44.1 (-123 44.1)
:) 3 yHY_0PIIGfOGms5h-JpD5Q the-o-bar-and-grill-eugene-3 The O Bar & Grill https://s3-media2.fl.yelpcdn.com/bphoto/nmuKD7EbGWHuPKdbcJQSpA/o.jpg FALSE https://www.yelp.com/biz/the-o-bar-and-grill-eugene-3?adjust_creative=gI-YTe1_pV4Imh… 61 <df> 2.9 44.1 <chr [2]> $ 115 Commons Dr +154… (541) 349-07… 920. <df [1 × 3]> NA pizza -123. 44.1 (-123 44.1)
:) 4 dghvrys0A_V41ibPXj7yUA papas-pizza-parlor-eugene-7 Papa's Pizza Parlor - Coburg Rd Eugene https://s3-media1.fl.yelpcdn.com/bphoto/6n1wEgF7F9b6oLz6DOThRQ/o.jpg FALSE https://www.yelp.com/biz/papas-pizza-parlor-eugene-7?adjust_creative=gI-YTe1_pV4Imhx… 85 <df> 2.5 44.1 <chr [0]> $$ 1577 Coburg Rd +154… (541) 686-07… 1467. <df [1 × 3]> NA pizza -123. 44.1 (-123 44.1)
:) 5 YKh7HaUzjizeHrIebkFAAQ papa-murphys-eugene-2 Papa Murphy's https://s3-media1.fl.yelpcdn.com/bphoto/jL-QyMy_7RIeK0E05H6xnQ/o.jpg FALSE https://www.yelp.com/biz/papa-murphys-eugene-2?adjust_creative=gI-YTe1_pV4ImhxKx_yjL… 24 <df> 3.3 44.1 <chr [1]> $ 1508 Coburg Road +154… (541) 686-66… 1447. <df [0 × 0]> NA pizza -123. 44.1 (-123 44.1)
:) 6 i1uc9dtkqdbgjjakeTjOxw cork-and-kale-restaurant-eugene Cork & Kale Restaurant https://s3-media2.fl.yelpcdn.com/bphoto/UYHwvthpTSlSe3E3vsQANw/o.jpg FALSE https://www.yelp.com/biz/cork-and-kale-restaurant-eugene?adjust_creative=gI-YTe1_pV4… 8 <df> 3.1 44.1 <chr [0]> <NA> 2133 Centennial … +154… (541) 342-38… 1288. <df [1 × 3]> NA pizza -123. 44.1 (-123 44.1)
:) # ℹ abbreviated name: ¹attributes$business_temp_closed
:) # ℹ 11 more variables: coordinates$longitude <dbl>, location$address2 <chr>, $address3 <chr>, $city <chr>, $zip_code <chr>, $country <chr>, $state <chr>, $display_address <list>, attributes$menu_url <chr>, $waitlist_reservation <lgl>, $open24_hours <lgl>
2.1 delete duplicates
# I already deleted duplicated rows in mini 01 using tidyr::distinct()
print(sum(duplicated(yelp$id)))
:) [1] 0
# after deleting duplicates, it is better to use tibble without geometry for data wrangling work
yelp_dropsf <- yelp %>%
sf::st_drop_geometry()
yelp_dropsf
:) # A tibble: 131 × 21
:) id alias name image_url is_closed url review_count categories rating coordinates$latitude transactions price location$address1 phone display_phone distance business_hours attributes$business_…¹ category_manual_input x_coord y_coord
:) * <chr> <chr> <chr> <chr> <lgl> <chr> <int> <list> <dbl> <dbl> <list> <chr> <chr> <chr> <chr> <dbl> <list> <int> <chr> <dbl> <dbl>
:) 1 RW7UfCVzCtjdR8VjARO8AQ pegasus-pizza-eugene-3 Pegasus Pizza https://s3-media1.fl.yelpcdn.com/bphoto/k-7mgGV78S1vfUlimAiIdg/o.jpg FALSE https://www.yelp.com/biz/pegasus-pizza-eugene-3?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&utm_camp… 83 <df> 3.3 44.1 <chr [2]> $ 4 Oakway Ctr +154… (541) 344-08… 1043. <df [1 × 3]> NA pizza -123. 44.1
:) 2 -OSaiVv0i9donG_5-Ov-kw mod-pizza-eugene MOD Pizza https://s3-media2.fl.yelpcdn.com/bphoto/jwQAWViCUiO7lJuxRkPdRw/o.jpg FALSE https://www.yelp.com/biz/mod-pizza-eugene?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&utm_campaign=y… 193 <df> 3.5 44.1 <chr [2]> $ 203 Coburg Rd +145… (458) 205-89… 1027. <df [1 × 3]> NA pizza -123. 44.1
:) 3 yHY_0PIIGfOGms5h-JpD5Q the-o-bar-and-grill-eugene-3 The O Bar & Grill https://s3-media2.fl.yelpcdn.com/bphoto/nmuKD7EbGWHuPKdbcJQSpA/o.jpg FALSE https://www.yelp.com/biz/the-o-bar-and-grill-eugene-3?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&ut… 61 <df> 2.9 44.1 <chr [2]> $ 115 Commons Dr +154… (541) 349-07… 920. <df [1 × 3]> NA pizza -123. 44.1
:) 4 dghvrys0A_V41ibPXj7yUA papas-pizza-parlor-eugene-7 Papa's Pizza Parlor - Coburg Rd Eugene https://s3-media1.fl.yelpcdn.com/bphoto/6n1wEgF7F9b6oLz6DOThRQ/o.jpg FALSE https://www.yelp.com/biz/papas-pizza-parlor-eugene-7?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&utm… 85 <df> 2.5 44.1 <chr [0]> $$ 1577 Coburg Rd +154… (541) 686-07… 1467. <df [1 × 3]> NA pizza -123. 44.1
:) 5 YKh7HaUzjizeHrIebkFAAQ papa-murphys-eugene-2 Papa Murphy's https://s3-media1.fl.yelpcdn.com/bphoto/jL-QyMy_7RIeK0E05H6xnQ/o.jpg FALSE https://www.yelp.com/biz/papa-murphys-eugene-2?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&utm_campa… 24 <df> 3.3 44.1 <chr [1]> $ 1508 Coburg Road +154… (541) 686-66… 1447. <df [0 × 0]> NA pizza -123. 44.1
:) 6 i1uc9dtkqdbgjjakeTjOxw cork-and-kale-restaurant-eugene Cork & Kale Restaurant https://s3-media2.fl.yelpcdn.com/bphoto/UYHwvthpTSlSe3E3vsQANw/o.jpg FALSE https://www.yelp.com/biz/cork-and-kale-restaurant-eugene?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ… 8 <df> 3.1 44.1 <chr [0]> <NA> 2133 Centennial … +154… (541) 342-38… 1288. <df [1 × 3]> NA pizza -123. 44.1
:) 7 ArX9hk9qcL_OzVJsd4wP3g pieology-pizzeria-springfield-springfield Pieology Pizzeria, Springfield https://s3-media2.fl.yelpcdn.com/bphoto/tNoYjmdjwvsnj-dJ0s2ttw/o.jpg FALSE https://www.yelp.com/biz/pieology-pizzeria-springfield-springfield?adjust_creative=gI-YTe1_pV4I… 117 <df> 3.1 44.1 <chr [2]> $ 2860 Gateway Str… +154… (541) 357-43… 924. <df [1 × 3]> NA pizza -123. 44.1
:) 8 ufwvXcRZdR_0e69QGsUm8Q little-caesars-pizza-springfield-5 Little Caesars Pizza https://s3-media2.fl.yelpcdn.com/bphoto/zuOoNYrMok4sIeeocmphTw/o.jpg FALSE https://www.yelp.com/biz/little-caesars-pizza-springfield-5?adjust_creative=gI-YTe1_pV4ImhxKx_y… 20 <df> 1.7 44.1 <chr [1]> $ 183 Q St +154… (541) 741-36… 1220. <df [1 × 3]> NA pizza -123. 44.1
:) 9 _ORTNFlJjjm6Wy4TpS-7BA coburg-pizza-company-centennial-springfield-5 Coburg Pizza Company Centennial https://s3-media4.fl.yelpcdn.com/bphoto/BkjR8iTj-i_xP-C2pvffkQ/o.jpg FALSE https://www.yelp.com/biz/coburg-pizza-company-centennial-springfield-5?adjust_creative=gI-YTe1_… 224 <df> 4.2 44.1 <chr [0]> $$ 1710 Centennial … +154… (541) 484-66… 4645. <df [1 × 3]> NA pizza -123. 44.1
:) 10 SVulg_fxyYsyVBFzYvSeGQ bartolottis-pizza-bistro-springfield-2 Bartolotti's Pizza Bistro https://s3-media2.fl.yelpcdn.com/bphoto/NrHn5F5WqZYRGbbOMsjdUg/o.jpg FALSE https://www.yelp.com/biz/bartolottis-pizza-bistro-springfield-2?adjust_creative=gI-YTe1_pV4Imhx… 127 <df> 4.2 44.0 <chr [2]> $$ 330 Main St +154… (541) 505-88… 5171. <df [1 × 3]> NA pizza -123. 44.0
:) # ℹ 121 more rows
:) # ℹ abbreviated name: ¹attributes$business_temp_closed
:) # ℹ 11 more variables: coordinates$longitude <dbl>, location$address2 <chr>, $address3 <chr>, $city <chr>, $zip_code <chr>, $country <chr>, $state <chr>, $display_address <list>, attributes$menu_url <chr>, $waitlist_reservation <lgl>, $open24_hours <lgl>
2.2 flatten
Each of the the following columns consist of list or dataframe, making difficult to do data analysis right away
#categories list
#coordinates data.frame
#transactions list
#location data.frame
#business_hours list
#attributes data.frame
yelp_dropsf %>%
purrr::map(class)
:) $id
:) [1] "character"
:)
:) $alias
:) [1] "character"
:)
:) $name
:) [1] "character"
:)
:) $image_url
:) [1] "character"
:)
:) $is_closed
:) [1] "logical"
:)
:) $url
:) [1] "character"
:)
:) $review_count
:) [1] "integer"
:)
:) $categories
:) [1] "list"
:)
:) $rating
:) [1] "numeric"
:)
:) $coordinates
:) [1] "data.frame"
:)
:) $transactions
:) [1] "list"
:)
:) $price
:) [1] "character"
:)
:) $location
:) [1] "data.frame"
:)
:) $phone
:) [1] "character"
:)
:) $display_phone
:) [1] "character"
:)
:) $distance
:) [1] "numeric"
:)
:) $business_hours
:) [1] "list"
:)
:) $attributes
:) [1] "data.frame"
:)
:) $category_manual_input
:) [1] "character"
:)
:) $x_coord
:) [1] "numeric"
:)
:) $y_coord
:) [1] "numeric"
Let’s see how many columns could be flattened using the
jsonlite
package.
:) id alias name image_url is_closed url review_count categories rating transactions price phone display_phone distance
:) 1 RW7UfCVzCtjdR8VjARO8AQ pegasus-pizza-eugene-3 Pegasus Pizza https://s3-media1.fl.yelpcdn.com/bphoto/k-7mgGV78S1vfUlimAiIdg/o.jpg FALSE https://www.yelp.com/biz/pegasus-pizza-eugene-3?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=gI-YTe1_pV4ImhxKx_yjLQ 83 pizza, cocktailbars, Pizza, Cocktail Bars 3.3 pickup, delivery $ +15413440844 (541) 344-0844 1043
:) 2 -OSaiVv0i9donG_5-Ov-kw mod-pizza-eugene MOD Pizza https://s3-media2.fl.yelpcdn.com/bphoto/jwQAWViCUiO7lJuxRkPdRw/o.jpg FALSE https://www.yelp.com/biz/mod-pizza-eugene?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=gI-YTe1_pV4ImhxKx_yjLQ 193 hotdogs, pizza, Fast Food, Pizza 3.5 pickup, delivery $ +14582058910 (458) 205-8910 1027
:) business_hours category_manual_input x_coord y_coord coordinates.latitude coordinates.longitude location.address1 location.address2 location.address3 location.city location.zip_code location.country location.state location.display_address attributes.business_temp_closed
:) 1 FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 2000, 2000, 2000, 2000, 2100, 2100, 2000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE pizza -123 44.1 44.1 -123 4 Oakway Ctr Eugene 97401 US OR 4 Oakway Ctr, Eugene, OR 97401 NA
:) 2 FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 2200, 2200, 2200, 2300, 2300, 2300, 2200, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE pizza -123 44.1 44.1 -123 203 Coburg Rd <NA> <NA> Eugene 97401 US OR 203 Coburg Rd, Eugene, OR 97401 NA
:) attributes.menu_url attributes.waitlist_reservation attributes.open24_hours
:) 1 http://pegasuspizza.net/#menu NA NA
:) 2 http://modpizza.com/menu/?utm_campaign=yelplistingbusiness&utm_medium=referral&utm_source=yelp&utm_content=menu NA NA
:) [ reached 'max' / getOption("max.print") -- omitted 129 rows ]
Still, the following columns (location.display_address, transactions,
categories, business_hours) have list
structures.
:) categories transactions business_hours location.display_address
:) 1 pizza, cocktailbars, Pizza, Cocktail Bars pickup, delivery FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 2000, 2000, 2000, 2000, 2100, 2100, 2000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 4 Oakway Ctr, Eugene, OR 97401
:) 2 hotdogs, pizza, Fast Food, Pizza pickup, delivery FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 2200, 2200, 2200, 2300, 2300, 2300, 2200, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 203 Coburg Rd, Eugene, OR 97401
:) 3 pizza, sportsbars, burgers, Pizza, Sports Bars, Burgers pickup, delivery FALSE, TRUE, FALSE, FALSE, TRUE, TRUE, FALSE, 1500, 1100, 1100, 1100, 1100, 0900, 0900, 0000, 0100, 0000, 0000, 0100, 0100, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 115 Commons Dr, Eugene, OR 97401
:) 4 pizza, Pizza FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 1577 Coburg Rd, Eugene, OR 97401
:) 5 pizza, Pizza delivery NULL 1508 Coburg Road, Eugene, OR 97401
:) 6 newamerican, breakfast_brunch, pizza, New American, Breakfast & Brunch, Pizza FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 0600, 1700, 0600, 1700, 0600, 1700, 0600, 1700, 0600, 1700, 0600, 1700, 0600, 1700, 1000, 2200, 1000, 2200, 1000, 2200, 1000, 2200, 1000, 2200, 1000, 2200, 1000, 2200, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, REGULAR, FALSE 2133 Centennial Plz, Eugene, OR 97401
:) 7 pizza, hotdogs, Pizza, Fast Food delivery, pickup FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 2100, 2100, 2100, 2100, 2200, 2200, 2100, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 2860 Gateway Street Ste, #Mt202, Springfield, OR 97477
:) 8 pizza, chicken_wings, Pizza, Chicken Wings delivery FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 2200, 2200, 2200, 2200, 2300, 2300, 2200, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 183 Q St, Springfield, OR 97477
:) 9 pizza, chicken_wings, italian, Pizza, Chicken Wings, Italian FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 2000, 2000, 2000, 2000, 2100, 2100, 2000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 1710 Centennial Blvd, Springfield, OR 97477
:) 10 pizza, italian, pastashops, Pizza, Italian, Pasta Shops pickup, delivery FALSE, FALSE, FALSE, FALSE, FALSE, 1130, 1130, 1130, 1130, 1130, 2000, 2000, 2000, 2000, 2100, 0, 1, 2, 3, 4, REGULAR, TRUE 330 Main St, Ste B, Springfield, OR 97477
:) 11 pizza, Pizza pickup, delivery FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1200, 2230, 2230, 2230, 2230, 0000, 0000, 2100, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 1406 Mohawk Blvd, Springfield, OR 97477
:) 12 pizza, Pizza delivery FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 2030, 2000, 2000, 2000, 2100, 2100, 2000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 4006 Franklin Blvd, Eugene, OR 97403
:) 13 pizza, Pizza pickup, delivery FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1200, 2030, 2030, 2030, 2030, 2100, 2100, 2000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 115 S 5th St, Springfield, OR 97477
:) 14 pizza, Pizza delivery FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 2300, 2300, 2300, 2300, 2300, 2300, 2300, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 4011 Main St, Springfield, OR 97478
:) 15 pizza, Pizza delivery FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1200, 2100, 2100, 2100, 2100, 2000, 1900, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 1498 S A St, Springfield, OR 97477
:) 16 pizza, Pizza delivery FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 2100, 2100, 2100, 2100, 2100, 2100, 2100, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 35855 Plaza Loop Rd, Pleasant Hill, OR 97455
:) 17 pizza, Pizza delivery FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 2100, 2100, 2100, 2100, 2100, 2100, 2100, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 2053 Olympic St, Springfield, OR 97477
:) 18 pizza, hotdogs, Pizza, Fast Food pickup, delivery FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 2200, 2200, 2200, 2300, 2300, 2300, 2200, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE 1820 Olympic St, Springfield, OR 97477
:) [ reached 'max' / getOption("max.print") -- omitted 113 rows ]
See how elements in each column look like. transactions
and location.display_address
can be simplified by
concatenating them to strings.
:) [[1]]
:) alias title
:) 1 pizza Pizza
:) 2 cocktailbars Cocktail Bars
:) [[1]]
:) [1] "pickup" "delivery"
:) [[1]]
:) open hours_type is_open_now
:) 1 FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 2000, 2000, 2000, 2000, 2100, 2100, 2000, 0, 1, 2, 3, 4, 5, 6 REGULAR TRUE
:) [[1]]
:) [1] "4 Oakway Ctr" "Eugene, OR 97401"
# apply a string-concatenation to each element
yelp_dropsf$transactions %>%
purrr::map(function(x) str_c(x, collapse=", ")) %>%
head()
:) [[1]]
:) [1] "pickup, delivery"
:)
:) [[2]]
:) [1] "pickup, delivery"
:)
:) [[3]]
:) [1] "pickup, delivery"
:)
:) [[4]]
:) [1] ""
:)
:) [[5]]
:) [1] "delivery"
:)
:) [[6]]
:) [1] ""
# apply to each element
yelp_dropsf$location.display_address %>%
purrr::map(function(x) str_c(x, collapse=", ")) %>%
head()
:) [[1]]
:) [1] "4 Oakway Ctr, Eugene, OR 97401"
:)
:) [[2]]
:) [1] "203 Coburg Rd, Eugene, OR 97401"
:)
:) [[3]]
:) [1] "115 Commons Dr, Eugene, OR 97401"
:)
:) [[4]]
:) [1] "1577 Coburg Rd, Eugene, OR 97401"
:)
:) [[5]]
:) [1] "1508 Coburg Road, Eugene, OR 97401"
:)
:) [[6]]
:) [1] "2133 Centennial Plz, Eugene, OR 97401"
yelp_dropsf_concat <- yelp_dropsf %>%
mutate(transactions = transactions %>%
map_chr(., function(x) str_c(x, collapse=", ")),
location.display_address = location.display_address %>%
map_chr(., function(x) str_c(x, collapse=", "))) %>%
relocate(id, alias, transactions, location.display_address)
yelp_dropsf_concat
:) id alias transactions location.display_address name image_url is_closed url review_count categories rating price phone display_phone distance
:) 1 RW7UfCVzCtjdR8VjARO8AQ pegasus-pizza-eugene-3 pickup, delivery 4 Oakway Ctr, Eugene, OR 97401 Pegasus Pizza https://s3-media1.fl.yelpcdn.com/bphoto/k-7mgGV78S1vfUlimAiIdg/o.jpg FALSE https://www.yelp.com/biz/pegasus-pizza-eugene-3?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=gI-YTe1_pV4ImhxKx_yjLQ 83 pizza, cocktailbars, Pizza, Cocktail Bars 3.3 $ +15413440844 (541) 344-0844 1043
:) 2 -OSaiVv0i9donG_5-Ov-kw mod-pizza-eugene pickup, delivery 203 Coburg Rd, Eugene, OR 97401 MOD Pizza https://s3-media2.fl.yelpcdn.com/bphoto/jwQAWViCUiO7lJuxRkPdRw/o.jpg FALSE https://www.yelp.com/biz/mod-pizza-eugene?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=gI-YTe1_pV4ImhxKx_yjLQ 193 hotdogs, pizza, Fast Food, Pizza 3.5 $ +14582058910 (458) 205-8910 1027
:) business_hours category_manual_input x_coord y_coord coordinates.latitude coordinates.longitude location.address1 location.address2 location.address3 location.city location.zip_code location.country location.state attributes.business_temp_closed
:) 1 FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1100, 1100, 1100, 1100, 1100, 1100, 1100, 2000, 2000, 2000, 2000, 2100, 2100, 2000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE pizza -123 44.1 44.1 -123 4 Oakway Ctr Eugene 97401 US OR NA
:) 2 FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1030, 1030, 1030, 1030, 1030, 1030, 1030, 2200, 2200, 2200, 2300, 2300, 2300, 2200, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE pizza -123 44.1 44.1 -123 203 Coburg Rd <NA> <NA> Eugene 97401 US OR NA
:) attributes.menu_url attributes.waitlist_reservation attributes.open24_hours
:) 1 http://pegasuspizza.net/#menu NA NA
:) 2 http://modpizza.com/menu/?utm_campaign=yelplistingbusiness&utm_medium=referral&utm_source=yelp&utm_content=menu NA NA
:) [ reached 'max' / getOption("max.print") -- omitted 129 rows ]
In the business_hours
list column, there are many NAs so
I won’t use it as a variable.
:) [[1]]
:) [1] 3
:)
:) [[2]]
:) [1] 3
:)
:) [[3]]
:) [1] 3
:)
:) [[4]]
:) [1] 3
:)
:) [[5]]
:) [1] 0
:)
:) [[6]]
:) [1] 3
:)
:) [[7]]
:) [1] 3
:)
:) [[8]]
:) [1] 3
:)
:) [[9]]
:) [1] 3
:)
:) [[10]]
:) [1] 3
:)
:) [[11]]
:) [1] 3
:)
:) [[12]]
:) [1] 3
:)
:) [[13]]
:) [1] 3
:)
:) [[14]]
:) [1] 3
:)
:) [[15]]
:) [1] 3
:)
:) [[16]]
:) [1] 3
:)
:) [[17]]
:) [1] 3
:)
:) [[18]]
:) [1] 3
:)
:) [[19]]
:) [1] 0
:)
:) [[20]]
:) [1] 3
:)
:) [[21]]
:) [1] 0
:)
:) [[22]]
:) [1] 3
:)
:) [[23]]
:) [1] 0
:)
:) [[24]]
:) [1] 0
:)
:) [[25]]
:) [1] 3
:)
:) [[26]]
:) [1] 0
:)
:) [[27]]
:) [1] 0
:)
:) [[28]]
:) [1] 3
:)
:) [[29]]
:) [1] 3
:)
:) [[30]]
:) [1] 3
:)
:) [[31]]
:) [1] 3
:)
:) [[32]]
:) [1] 3
:)
:) [[33]]
:) [1] 3
:)
:) [[34]]
:) [1] 3
:)
:) [[35]]
:) [1] 3
:)
:) [[36]]
:) [1] 3
:)
:) [[37]]
:) [1] 3
:)
:) [[38]]
:) [1] 3
:)
:) [[39]]
:) [1] 3
:)
:) [[40]]
:) [1] 3
:)
:) [[41]]
:) [1] 3
:)
:) [[42]]
:) [1] 0
:)
:) [[43]]
:) [1] 3
:)
:) [[44]]
:) [1] 3
:)
:) [[45]]
:) [1] 3
:)
:) [[46]]
:) [1] 3
:)
:) [[47]]
:) [1] 3
:)
:) [[48]]
:) [1] 3
:)
:) [[49]]
:) [1] 3
:)
:) [[50]]
:) [1] 3
:)
:) [[51]]
:) [1] 3
:)
:) [[52]]
:) [1] 3
:)
:) [[53]]
:) [1] 3
:)
:) [[54]]
:) [1] 0
:)
:) [[55]]
:) [1] 3
:)
:) [[56]]
:) [1] 3
:)
:) [[57]]
:) [1] 3
:)
:) [[58]]
:) [1] 3
:)
:) [[59]]
:) [1] 3
:)
:) [[60]]
:) [1] 3
:)
:) [[61]]
:) [1] 3
:)
:) [[62]]
:) [1] 3
:)
:) [[63]]
:) [1] 3
:)
:) [[64]]
:) [1] 3
:)
:) [[65]]
:) [1] 3
:)
:) [[66]]
:) [1] 3
:)
:) [[67]]
:) [1] 3
:)
:) [[68]]
:) [1] 3
:)
:) [[69]]
:) [1] 3
:)
:) [[70]]
:) [1] 3
:)
:) [[71]]
:) [1] 3
:)
:) [[72]]
:) [1] 3
:)
:) [[73]]
:) [1] 0
:)
:) [[74]]
:) [1] 0
:)
:) [[75]]
:) [1] 0
:)
:) [ reached getOption("max.print") -- omitted 56 entries ]
:) id alias transactions location.display_address name image_url is_closed url review_count categories rating price phone display_phone distance
:) 1 RW7UfCVzCtjdR8VjARO8AQ pegasus-pizza-eugene-3 pickup, delivery 4 Oakway Ctr, Eugene, OR 97401 Pegasus Pizza https://s3-media1.fl.yelpcdn.com/bphoto/k-7mgGV78S1vfUlimAiIdg/o.jpg FALSE https://www.yelp.com/biz/pegasus-pizza-eugene-3?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=gI-YTe1_pV4ImhxKx_yjLQ 83 pizza, cocktailbars, Pizza, Cocktail Bars 3.3 $ +15413440844 (541) 344-0844 1043
:) 2 -OSaiVv0i9donG_5-Ov-kw mod-pizza-eugene pickup, delivery 203 Coburg Rd, Eugene, OR 97401 MOD Pizza https://s3-media2.fl.yelpcdn.com/bphoto/jwQAWViCUiO7lJuxRkPdRw/o.jpg FALSE https://www.yelp.com/biz/mod-pizza-eugene?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=gI-YTe1_pV4ImhxKx_yjLQ 193 hotdogs, pizza, Fast Food, Pizza 3.5 $ +14582058910 (458) 205-8910 1027
:) category_manual_input x_coord y_coord coordinates.latitude coordinates.longitude location.address1 location.address2 location.address3 location.city location.zip_code location.country location.state attributes.business_temp_closed attributes.menu_url attributes.waitlist_reservation attributes.open24_hours
:) 1 pizza -123 44.1 44.1 -123 4 Oakway Ctr Eugene 97401 US OR NA http://pegasuspizza.net/#menu NA NA
:) 2 pizza -123 44.1 44.1 -123 203 Coburg Rd <NA> <NA> Eugene 97401 US OR NA http://modpizza.com/menu/?utm_campaign=yelplistingbusiness&utm_medium=referral&utm_source=yelp&utm_content=menu NA NA
:) [ reached 'max' / getOption("max.print") -- omitted 129 rows ]
Now, the only list-column
that needs to be taken care of
is ‘categories’. Let’s see how it looks like. Each element contains both
alias and title. We only need one of them, which is title
.
Since the title
is just a list of categories to which a POI
is categorized, we can just concatenate it and still use it as a useful
information.
:) [[1]]
:) alias title
:) 1 pizza Pizza
:) 2 cocktailbars Cocktail Bars
:)
:) [[1]]
:) alias title
:) 1 hotdogs Fast Food
:) 2 pizza Pizza
:)
:) [[1]]
:) alias title
:) 1 pizza Pizza
:) 2 sportsbars Sports Bars
:) 3 burgers Burgers
:)
:) [[1]]
:) alias title
:) 1 pizza Pizza
:)
:) [[1]]
:) alias title
:) 1 pizza Pizza
# apply to each element
yelp_dropsf_concat$categories %>%
purrr::map(function(x) str_c(pull(x, title), collapse=", ")) %>%
head()
:) [[1]]
:) [1] "Pizza, Cocktail Bars"
:)
:) [[2]]
:) [1] "Fast Food, Pizza"
:)
:) [[3]]
:) [1] "Pizza, Sports Bars, Burgers"
:)
:) [[4]]
:) [1] "Pizza"
:)
:) [[5]]
:) [1] "Pizza"
:)
:) [[6]]
:) [1] "New American, Breakfast & Brunch, Pizza"
yelp_dropsf_concat <- yelp_dropsf_concat %>%
mutate(categories = categories %>%
map_chr(., function(x) str_c(pull(x, title), collapse=", "))) %>%
relocate(id, alias, transactions, location.display_address, categories)
yelp_dropsf_concat
:) id alias transactions location.display_address categories name image_url is_closed url review_count rating price phone display_phone distance category_manual_input
:) 1 RW7UfCVzCtjdR8VjARO8AQ pegasus-pizza-eugene-3 pickup, delivery 4 Oakway Ctr, Eugene, OR 97401 Pizza, Cocktail Bars Pegasus Pizza https://s3-media1.fl.yelpcdn.com/bphoto/k-7mgGV78S1vfUlimAiIdg/o.jpg FALSE https://www.yelp.com/biz/pegasus-pizza-eugene-3?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=gI-YTe1_pV4ImhxKx_yjLQ 83 3.3 $ +15413440844 (541) 344-0844 1043 pizza
:) 2 -OSaiVv0i9donG_5-Ov-kw mod-pizza-eugene pickup, delivery 203 Coburg Rd, Eugene, OR 97401 Fast Food, Pizza MOD Pizza https://s3-media2.fl.yelpcdn.com/bphoto/jwQAWViCUiO7lJuxRkPdRw/o.jpg FALSE https://www.yelp.com/biz/mod-pizza-eugene?adjust_creative=gI-YTe1_pV4ImhxKx_yjLQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=gI-YTe1_pV4ImhxKx_yjLQ 193 3.5 $ +14582058910 (458) 205-8910 1027 pizza
:) x_coord y_coord coordinates.latitude coordinates.longitude location.address1 location.address2 location.address3 location.city location.zip_code location.country location.state attributes.business_temp_closed attributes.menu_url attributes.waitlist_reservation attributes.open24_hours
:) 1 -123 44.1 44.1 -123 4 Oakway Ctr Eugene 97401 US OR NA http://pegasuspizza.net/#menu NA NA
:) 2 -123 44.1 44.1 -123 203 Coburg Rd <NA> <NA> Eugene 97401 US OR NA http://modpizza.com/menu/?utm_campaign=yelplistingbusiness&utm_medium=referral&utm_source=yelp&utm_content=menu NA NA
:) [ reached 'max' / getOption("max.print") -- omitted 129 rows ]
We are finished with wrangling column-wise.
:) data frame with 0 columns and 131 rows
2.3 drop NA rows
Since not all columns are in typical structures, it is better to
wrangle columns first and then take a look at rows. Based on the
following search for NA rows: - we don’t have to delete any rows because
all coordinates are valid (because I deleted all rows with NA
coordinates in mini 01). - NAs for location.address1
and
location.address2
, location.address3
are not a
big issue because we already have full addresses on the
`location.display_address
column. So, there is no need to
delete any rows. - We won’t delete any other rows because, despite some
NAs, we can still draw some interesting conclusions without bothering
all variables.
:) id alias transactions location.display_address categories name image_url is_closed url review_count rating price phone display_phone distance
:) 0 0 0 0 0 0 0 0 0 0 0 40 0 0 0
:) category_manual_input x_coord y_coord coordinates.latitude coordinates.longitude location.address1 location.address2 location.address3 location.city location.zip_code location.country location.state attributes.business_temp_closed attributes.menu_url attributes.waitlist_reservation
:) 0 0 0 0 0 1 32 38 0 0 0 0 130 91 128
:) attributes.open24_hours
:) 131
2.4 Put the tidy-ed data back to sf
:) Simple feature collection with 131 features and 31 fields
:) Geometry type: POINT
:) Dimension: XY
:) Bounding box: xmin: -123 ymin: 44 xmax: -123 ymax: 44.1
:) Geodetic CRS: WGS 84
:) # A tibble: 131 × 32
:) id geometry alias transactions location.display_add…¹ categories name image_url is_closed url review_count rating price phone display_phone distance category_manual_input x_coord y_coord coordinates.latitude coordinates.longitude location.address1 location.address2 location.address3 location.city location.zip_code location.country location.state attributes.business_…² attributes.menu_url attributes.waitlist_…³ attributes.open24_ho…⁴
:) <chr> <POINT [°]> <chr> <chr> <chr> <chr> <chr> <chr> <lgl> <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <int> <chr> <lgl> <lgl>
:) 1 RW7UfCVzCtjdR8VjARO8AQ (-123 44.1) pegasus-pizza-eugen… "pickup, de… 4 Oakway Ctr, Eugene,… Pizza, Co… Pega… https://… FALSE http… 83 3.3 $ +154… (541) 344-08… 1043. pizza -123. 44.1 44.1 -123. 4 Oakway Ctr "" "" Eugene 97401 US OR NA "http://pegasuspiz… NA NA
:) 2 -OSaiVv0i9donG_5-Ov-kw (-123 44.1) mod-pizza-eugene "pickup, de… 203 Coburg Rd, Eugene… Fast Food… MOD … https://… FALSE http… 193 3.5 $ +145… (458) 205-89… 1027. pizza -123. 44.1 44.1 -123. 203 Coburg Rd <NA> <NA> Eugene 97401 US OR NA "http://modpizza.c… NA NA
:) 3 yHY_0PIIGfOGms5h-JpD5Q (-123 44.1) the-o-bar-and-grill… "pickup, de… 115 Commons Dr, Eugen… Pizza, Sp… The … https://… FALSE http… 61 2.9 $ +154… (541) 349-07… 920. pizza -123. 44.1 44.1 -123. 115 Commons Dr "" "" Eugene 97401 US OR NA <NA> NA NA
:) 4 dghvrys0A_V41ibPXj7yUA (-123 44.1) papas-pizza-parlor-… "" 1577 Coburg Rd, Eugen… Pizza Papa… https://… FALSE http… 85 2.5 $$ +154… (541) 686-07… 1467. pizza -123. 44.1 44.1 -123. 1577 Coburg Rd "" "" Eugene 97401 US OR NA "https://www.papas… NA NA
:) 5 YKh7HaUzjizeHrIebkFAAQ (-123 44.1) papa-murphys-eugene… "delivery" 1508 Coburg Road, Eug… Pizza Papa… https://… FALSE http… 24 3.3 $ +154… (541) 686-66… 1447. pizza -123. 44.1 44.1 -123. 1508 Coburg Road <NA> <NA> Eugene 97401 US OR NA <NA> NA NA
:) 6 i1uc9dtkqdbgjjakeTjOxw (-123 44.1) cork-and-kale-resta… "" 2133 Centennial Plz, … New Ameri… Cork… https://… FALSE http… 8 3.1 <NA> +154… (541) 342-38… 1288. pizza -123. 44.1 44.1 -123. 2133 Centennial … <NA> "" Eugene 97401 US OR NA <NA> NA NA
:) 7 ArX9hk9qcL_OzVJsd4wP3g (-123 44.1) pieology-pizzeria-s… "delivery, … 2860 Gateway Street S… Pizza, Fa… Pieo… https://… FALSE http… 117 3.1 $ +154… (541) 357-43… 924. pizza -123. 44.1 44.1 -123. 2860 Gateway Str… "#Mt202" <NA> Springfield 97477 US OR NA "https://order.pie… NA NA
:) 8 ufwvXcRZdR_0e69QGsUm8Q (-123 44.1) little-caesars-pizz… "delivery" 183 Q St, Springfield… Pizza, Ch… Litt… https://… FALSE http… 20 1.7 $ +154… (541) 741-36… 1220. pizza -123. 44.1 44.1 -123. 183 Q St <NA> <NA> Springfield 97477 US OR NA "https://littlecae… NA NA
:) 9 _ORTNFlJjjm6Wy4TpS-7BA (-123 44.1) coburg-pizza-compan… "" 1710 Centennial Blvd,… Pizza, Ch… Cobu… https://… FALSE http… 224 4.2 $$ +154… (541) 484-66… 4645. pizza -123. 44.1 44.1 -123. 1710 Centennial … "" "" Springfield 97477 US OR NA "" NA NA
:) 10 SVulg_fxyYsyVBFzYvSeGQ (-123 44) bartolottis-pizza-b… "pickup, de… 330 Main St, Ste B, S… Pizza, It… Bart… https://… FALSE http… 127 4.2 $$ +154… (541) 505-88… 5171. pizza -123. 44.0 44.0 -123. 330 Main St "Ste B" <NA> Springfield 97477 US OR NA <NA> NA NA
:) # ℹ 121 more rows
:) # ℹ abbreviated names: ¹location.display_address, ²attributes.business_temp_closed, ³attributes.waitlist_reservation, ⁴attributes.open24_hours
3 Visual inspectation
Remove POIs outside the boundary of Springfield. We get 131->53 rows.
:) Simple feature collection with 53 features and 31 fields
:) Geometry type: POINT
:) Dimension: XY
:) Bounding box: xmin: -123 ymin: 44 xmax: -123 ymax: 44.1
:) Geodetic CRS: WGS 84
:) # A tibble: 53 × 32
:) id geometry alias transactions location.display_add…¹ categories name image_url is_closed url review_count rating price phone display_phone distance category_manual_input x_coord y_coord coordinates.latitude coordinates.longitude location.address1 location.address2 location.address3 location.city location.zip_code location.country location.state attributes.business_…² attributes.menu_url attributes.waitlist_…³ attributes.open24_ho…⁴
:) <chr> <POINT [°]> <chr> <chr> <chr> <chr> <chr> <chr> <lgl> <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <int> <chr> <lgl> <lgl>
:) 1 ArX9hk9qcL_OzVJsd4wP3g (-123 44.1) pieology-pizzeria-s… "delivery, … 2860 Gateway Street S… Pizza, Fa… Pieo… https://… FALSE http… 117 3.1 $ +154… (541) 357-43… 924. pizza -123. 44.1 44.1 -123. 2860 Gateway Str… "#Mt202" <NA> Springfield 97477 US OR NA "https://order.pie… NA NA
:) 2 ufwvXcRZdR_0e69QGsUm8Q (-123 44.1) little-caesars-pizz… "delivery" 183 Q St, Springfield… Pizza, Ch… Litt… https://… FALSE http… 20 1.7 $ +154… (541) 741-36… 1220. pizza -123. 44.1 44.1 -123. 183 Q St <NA> <NA> Springfield 97477 US OR NA "https://littlecae… NA NA
:) 3 _ORTNFlJjjm6Wy4TpS-7BA (-123 44.1) coburg-pizza-compan… "" 1710 Centennial Blvd,… Pizza, Ch… Cobu… https://… FALSE http… 224 4.2 $$ +154… (541) 484-66… 4645. pizza -123. 44.1 44.1 -123. 1710 Centennial … "" "" Springfield 97477 US OR NA "" NA NA
:) 4 SVulg_fxyYsyVBFzYvSeGQ (-123 44) bartolottis-pizza-b… "pickup, de… 330 Main St, Ste B, S… Pizza, It… Bart… https://… FALSE http… 127 4.2 $$ +154… (541) 505-88… 5171. pizza -123. 44.0 44.0 -123. 330 Main St "Ste B" <NA> Springfield 97477 US OR NA <NA> NA NA
:) 5 QIdf70NMFF27TxkPevj0vQ (-123 44.1) r-pizza-springfield "pickup, de… 1406 Mohawk Blvd, Spr… Pizza R Pi… https://… FALSE http… 64 4.5 <NA> +154… (541) 636-38… 4887. pizza -123. 44.1 44.1 -123. 1406 Mohawk Blvd <NA> "" Springfield 97477 US OR NA "https://www.rpizz… NA NA
:) 6 CyuS3d7vq3Q3vj2w5u9Oxg (-123 44) mezza-luna-pizzeria… "pickup, de… 115 S 5th St, Springf… Pizza Mezz… https://… FALSE http… 62 4.1 $ +154… (541) 653-86… 5022. pizza -123. 44.0 44.0 -123. 115 S 5th St "" "" Springfield 97477 US OR NA "http://www.mezzal… NA NA
:) 7 rptyhCBlnb-1zy-cSUaA4g (-123 44) papas-pizza-parlor-… "delivery" 4011 Main St, Springf… Pizza Papa… https://… FALSE http… 110 2.6 $$ +154… (541) 741-11… 2591. pizza -123. 44.0 44.0 -123. 4011 Main St "" "" Springfield 97478 US OR NA "https://www.papas… NA NA
:) 8 9vLvm7L9NaVV1-OF1D5a-Q (-123 44) joeys-pizza-springf… "delivery" 1498 S A St, Springfi… Pizza Joey… https://… FALSE http… 105 3.4 $$ +154… (541) 746-69… 3911. pizza -123. 44.0 44.0 -123. 1498 S A St "" "" Springfield 97477 US OR NA <NA> NA NA
:) 9 9Dx58Yf-7tG19e9kqeOqNw (-123 44.1) abbys-legendary-piz… "delivery" 2053 Olympic St, Spri… Pizza Abby… https://… FALSE http… 32 2.4 $$ +154… (541) 747-44… 4754. pizza -123. 44.1 44.1 -123. 2053 Olympic St "" "" Springfield 97477 US OR NA "http://www.abbys.… NA NA
:) 10 EF3EGnuqJ6lrMScCoEIVEw (-123 44.1) mod-pizza-springfie… "pickup, de… 1820 Olympic St, Spri… Pizza, Fa… MOD … https://… FALSE http… 14 3.5 <NA> +145… (458) 201-54… 4902. pizza -123. 44.1 44.1 -123. 1820 Olympic St <NA> <NA> Springfield 97477 US OR NA "https://modpizza.… NA NA
:) # ℹ 43 more rows
:) # ℹ abbreviated names: ¹location.display_address, ²attributes.business_temp_closed, ³attributes.waitlist_reservation, ⁴attributes.open24_hours
I visualized again.
tmap_mode('view')
tm_shape(tract_spring) +
tm_polygons(col = "hhincomeE", alpha=0.3) +
tm_shape(spring) +
tm_borders(col="black", lwd=1.5) +
tm_shape(yelp_wrangled_sf) +
tm_dots(col = "category_manual_input", palette = c("red", "green", "blue")) +
tm_layout(
legend.title.size = 4,
legend.text.size = 5,
legend.position = c("right","bottom"),
main.title = "City of Springfield and 23 Census Tracts", main.title.position = "left", main.title.size = 7
) +
tm_layout(frame = FALSE)
4 Distribution by categories
It seems that each element of the categories
column
contains more than just pizza, breweries, and grocery.
:) .
:) American, Breweries Breweries, New American Delis, Grocery Department Stores, Grocery Grocery Grocery, Butcher Grocery, Department Stores, Pharmacy Grocery, Discount Store Grocery, Wholesale Stores, Restaurant Supplies Mexican, Grocery
:) 1 1 1 1 21 1 2 2 1 1
:) Pizza Pizza, Chicken Wings Pizza, Chicken Wings, Fast Food Pizza, Chicken Wings, Italian Pizza, Chicken Wings, Sandwiches Pizza, Do-It-Yourself Food Pizza, Fast Food Pizza, Italian, Pasta Shops Sports Bars, American, Pizza Wholesale Stores, Grocery
:) 10 1 1 1 2 1 2 1 1 1
Since the three categories that we are interested in do not seem to be overlapped, we will group sub-categories sharing a certain keyword into just one major category.
# `case_when` function is a fine choice to do this re-categorization work.
yelp_wrangled_sf <- yelp_wrangled_sf %>%
mutate(categories = case_when(str_detect(categories, "Pizza") ~ "Pizza",
str_detect(categories, "Breweries") ~ "Breweries",
str_detect(categories, "Grocery") ~ "Grocery"))
yelp_wrangled_sf
:) Simple feature collection with 53 features and 31 fields
:) Geometry type: POINT
:) Dimension: XY
:) Bounding box: xmin: -123 ymin: 44 xmax: -123 ymax: 44.1
:) Geodetic CRS: WGS 84
:) # A tibble: 53 × 32
:) id geometry alias transactions location.display_add…¹ categories name image_url is_closed url review_count rating price phone display_phone distance category_manual_input x_coord y_coord coordinates.latitude coordinates.longitude location.address1 location.address2 location.address3 location.city location.zip_code location.country location.state attributes.business_…² attributes.menu_url attributes.waitlist_…³ attributes.open24_ho…⁴
:) * <chr> <POINT [°]> <chr> <chr> <chr> <chr> <chr> <chr> <lgl> <chr> <int> <dbl> <chr> <chr> <chr> <dbl> <chr> <dbl> <dbl> <dbl> <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <int> <chr> <lgl> <lgl>
:) 1 ArX9hk9qcL_OzVJsd4wP3g (-123 44.1) pieology-pizzeria-s… "delivery, … 2860 Gateway Street S… Pizza Pieo… https://… FALSE http… 117 3.1 $ +154… (541) 357-43… 924. pizza -123. 44.1 44.1 -123. 2860 Gateway Str… "#Mt202" <NA> Springfield 97477 US OR NA "https://order.pie… NA NA
:) 2 ufwvXcRZdR_0e69QGsUm8Q (-123 44.1) little-caesars-pizz… "delivery" 183 Q St, Springfield… Pizza Litt… https://… FALSE http… 20 1.7 $ +154… (541) 741-36… 1220. pizza -123. 44.1 44.1 -123. 183 Q St <NA> <NA> Springfield 97477 US OR NA "https://littlecae… NA NA
:) 3 _ORTNFlJjjm6Wy4TpS-7BA (-123 44.1) coburg-pizza-compan… "" 1710 Centennial Blvd,… Pizza Cobu… https://… FALSE http… 224 4.2 $$ +154… (541) 484-66… 4645. pizza -123. 44.1 44.1 -123. 1710 Centennial … "" "" Springfield 97477 US OR NA "" NA NA
:) 4 SVulg_fxyYsyVBFzYvSeGQ (-123 44) bartolottis-pizza-b… "pickup, de… 330 Main St, Ste B, S… Pizza Bart… https://… FALSE http… 127 4.2 $$ +154… (541) 505-88… 5171. pizza -123. 44.0 44.0 -123. 330 Main St "Ste B" <NA> Springfield 97477 US OR NA <NA> NA NA
:) 5 QIdf70NMFF27TxkPevj0vQ (-123 44.1) r-pizza-springfield "pickup, de… 1406 Mohawk Blvd, Spr… Pizza R Pi… https://… FALSE http… 64 4.5 <NA> +154… (541) 636-38… 4887. pizza -123. 44.1 44.1 -123. 1406 Mohawk Blvd <NA> "" Springfield 97477 US OR NA "https://www.rpizz… NA NA
:) 6 CyuS3d7vq3Q3vj2w5u9Oxg (-123 44) mezza-luna-pizzeria… "pickup, de… 115 S 5th St, Springf… Pizza Mezz… https://… FALSE http… 62 4.1 $ +154… (541) 653-86… 5022. pizza -123. 44.0 44.0 -123. 115 S 5th St "" "" Springfield 97477 US OR NA "http://www.mezzal… NA NA
:) 7 rptyhCBlnb-1zy-cSUaA4g (-123 44) papas-pizza-parlor-… "delivery" 4011 Main St, Springf… Pizza Papa… https://… FALSE http… 110 2.6 $$ +154… (541) 741-11… 2591. pizza -123. 44.0 44.0 -123. 4011 Main St "" "" Springfield 97478 US OR NA "https://www.papas… NA NA
:) 8 9vLvm7L9NaVV1-OF1D5a-Q (-123 44) joeys-pizza-springf… "delivery" 1498 S A St, Springfi… Pizza Joey… https://… FALSE http… 105 3.4 $$ +154… (541) 746-69… 3911. pizza -123. 44.0 44.0 -123. 1498 S A St "" "" Springfield 97477 US OR NA <NA> NA NA
:) 9 9Dx58Yf-7tG19e9kqeOqNw (-123 44.1) abbys-legendary-piz… "delivery" 2053 Olympic St, Spri… Pizza Abby… https://… FALSE http… 32 2.4 $$ +154… (541) 747-44… 4754. pizza -123. 44.1 44.1 -123. 2053 Olympic St "" "" Springfield 97477 US OR NA "http://www.abbys.… NA NA
:) 10 EF3EGnuqJ6lrMScCoEIVEw (-123 44.1) mod-pizza-springfie… "pickup, de… 1820 Olympic St, Spri… Pizza MOD … https://… FALSE http… 14 3.5 <NA> +145… (458) 201-54… 4902. pizza -123. 44.1 44.1 -123. 1820 Olympic St <NA> <NA> Springfield 97477 US OR NA "https://modpizza.… NA NA
:) # ℹ 43 more rows
:) # ℹ abbreviated names: ¹location.display_address, ²attributes.business_temp_closed, ³attributes.waitlist_reservation, ⁴attributes.open24_hours
We have 2 breweries, 31 grocery stores, and 20 pizza stores.
:) .
:) Breweries Grocery Pizza
:) 2 31 20
5 Analysis
Let’s select columns that we want to focus on.
:) [1] "id" "geometry" "alias" "transactions" "location.display_address" "categories" "name" "image_url" "is_closed" "url" "review_count" "rating" "price" "phone"
:) [15] "display_phone" "distance" "category_manual_input" "x_coord" "y_coord" "coordinates.latitude" "coordinates.longitude" "location.address1" "location.address2" "location.address3" "location.city" "location.zip_code" "location.country" "location.state"
:) [29] "attributes.business_temp_closed" "attributes.menu_url" "attributes.waitlist_reservation" "attributes.open24_hours"
yelp_wrangled_focus_sf <- yelp_wrangled_sf %>%
select(id, transactions, location.display_address, categories, name, review_count, rating, price, x_coord, y_coord)
yelp_wrangled_focus_sf
:) Simple feature collection with 53 features and 10 fields
:) Geometry type: POINT
:) Dimension: XY
:) Bounding box: xmin: -123 ymin: 44 xmax: -123 ymax: 44.1
:) Geodetic CRS: WGS 84
:) # A tibble: 53 × 11
:) id transactions location.display_address categories name review_count rating price x_coord y_coord geometry
:) <chr> <chr> <chr> <chr> <chr> <int> <dbl> <chr> <dbl> <dbl> <POINT [°]>
:) 1 ArX9hk9qcL_OzVJsd4wP3g "delivery, pickup" 2860 Gateway Street Ste, #Mt202, Springfield, OR 97477 Pizza Pieology Pizzeria, Springfield 117 3.1 $ -123. 44.1 (-123 44.1)
:) 2 ufwvXcRZdR_0e69QGsUm8Q "delivery" 183 Q St, Springfield, OR 97477 Pizza Little Caesars Pizza 20 1.7 $ -123. 44.1 (-123 44.1)
:) 3 _ORTNFlJjjm6Wy4TpS-7BA "" 1710 Centennial Blvd, Springfield, OR 97477 Pizza Coburg Pizza Company Centennial 224 4.2 $$ -123. 44.1 (-123 44.1)
:) 4 SVulg_fxyYsyVBFzYvSeGQ "pickup, delivery" 330 Main St, Ste B, Springfield, OR 97477 Pizza Bartolotti's Pizza Bistro 127 4.2 $$ -123. 44.0 (-123 44)
:) 5 QIdf70NMFF27TxkPevj0vQ "pickup, delivery" 1406 Mohawk Blvd, Springfield, OR 97477 Pizza R Pizza 64 4.5 <NA> -123. 44.1 (-123 44.1)
:) 6 CyuS3d7vq3Q3vj2w5u9Oxg "pickup, delivery" 115 S 5th St, Springfield, OR 97477 Pizza Mezza Luna Pizzeria 62 4.1 $ -123. 44.0 (-123 44)
:) 7 rptyhCBlnb-1zy-cSUaA4g "delivery" 4011 Main St, Springfield, OR 97478 Pizza Papa's Pizza Parlor 110 2.6 $$ -123. 44.0 (-123 44)
:) 8 9vLvm7L9NaVV1-OF1D5a-Q "delivery" 1498 S A St, Springfield, OR 97477 Pizza Joey's Pizza 105 3.4 $$ -123. 44.0 (-123 44)
:) 9 9Dx58Yf-7tG19e9kqeOqNw "delivery" 2053 Olympic St, Springfield, OR 97477 Pizza Abby's Legendary Pizza 32 2.4 $$ -123. 44.1 (-123 44.1)
:) 10 EF3EGnuqJ6lrMScCoEIVEw "pickup, delivery" 1820 Olympic St, Springfield, OR 97477 Pizza MOD Pizza 14 3.5 <NA> -123. 44.1 (-123 44.1)
:) # ℹ 43 more rows
The following is a set of boxplots showing ratings distribution by categories and price. The problem is that each observation represented by points are too spread over the place, so that it is hard to tell to which subcategory each point belong. I am going to make subcategories using another column explicitly to avoid this issue.
yelp_wrangled_focus_sf %>%
st_drop_geometry() %>%
filter(!is.na(price)) %>%
filter(categories != "Breweries") %>%
ggplot(aes(x=categories, y=rating, fill=price)) +
geom_boxplot() +
geom_jitter()
Make a subgroup for a better visualization.
yelp_wrangled_focus_sf %>%
st_drop_geometry() %>%
filter(!is.na(price)) %>%
filter(categories != "Breweries") %>%
mutate(subgroup = str_c(categories, "_", price))
:) # A tibble: 30 × 11
:) id transactions location.display_address categories name review_count rating price x_coord y_coord subgroup
:) <chr> <chr> <chr> <chr> <chr> <int> <dbl> <chr> <dbl> <dbl> <chr>
:) 1 ArX9hk9qcL_OzVJsd4wP3g "delivery, pickup" 2860 Gateway Street Ste, #Mt202, Springfield, OR 97477 Pizza Pieology Pizzeria, Springfield 117 3.1 $ -123. 44.1 Pizza_$
:) 2 ufwvXcRZdR_0e69QGsUm8Q "delivery" 183 Q St, Springfield, OR 97477 Pizza Little Caesars Pizza 20 1.7 $ -123. 44.1 Pizza_$
:) 3 _ORTNFlJjjm6Wy4TpS-7BA "" 1710 Centennial Blvd, Springfield, OR 97477 Pizza Coburg Pizza Company Centennial 224 4.2 $$ -123. 44.1 Pizza_$$
:) 4 SVulg_fxyYsyVBFzYvSeGQ "pickup, delivery" 330 Main St, Ste B, Springfield, OR 97477 Pizza Bartolotti's Pizza Bistro 127 4.2 $$ -123. 44.0 Pizza_$$
:) 5 CyuS3d7vq3Q3vj2w5u9Oxg "pickup, delivery" 115 S 5th St, Springfield, OR 97477 Pizza Mezza Luna Pizzeria 62 4.1 $ -123. 44.0 Pizza_$
:) 6 rptyhCBlnb-1zy-cSUaA4g "delivery" 4011 Main St, Springfield, OR 97478 Pizza Papa's Pizza Parlor 110 2.6 $$ -123. 44.0 Pizza_$$
:) 7 9vLvm7L9NaVV1-OF1D5a-Q "delivery" 1498 S A St, Springfield, OR 97477 Pizza Joey's Pizza 105 3.4 $$ -123. 44.0 Pizza_$$
:) 8 9Dx58Yf-7tG19e9kqeOqNw "delivery" 2053 Olympic St, Springfield, OR 97477 Pizza Abby's Legendary Pizza 32 2.4 $$ -123. 44.1 Pizza_$$
:) 9 2z6a8LKg912FBuO0YoNd-g "pickup, delivery" 140 S 32nd St, Springfield, OR 97478 Pizza Pizza Hut 29 1.7 $ -123. 44.0 Pizza_$
:) 10 tNoYAq0-8bPhoA0ezXS_zw "delivery" 5727 Main Street, Springfield, OR 97478 Pizza Papa Murphy's 14 2.3 $ -123. 44.0 Pizza_$
:) # ℹ 20 more rows
yelp_wrangled_focus_sf %>%
st_drop_geometry() %>%
filter(!is.na(price)) %>%
filter(categories != "Breweries") %>%
mutate(subgroup = str_c(categories, "_", price)) %>%
pull(subgroup) %>%
table()
:) .
:) Grocery_$ Grocery_$$ Grocery_$$$ Grocery_$$$$ Pizza_$ Pizza_$$
:) 12 6 1 1 5 5
The following is a set of boxplots showing the ratings distribution among each category-price group. Although we have a small sample, we can try drawing implications from this plot.
yelp_wrangled_focus_sf %>%
st_drop_geometry() %>%
filter(!is.na(price)) %>%
filter(categories != "Breweries") %>%
mutate(subgroup = str_c(categories, "_", price)) %>%
ggplot() +
geom_boxplot(aes(x=subgroup, y=rating, fill=subgroup)) +
geom_point(aes(x=subgroup, y=rating, fill=subgroup))
5.1 Interpretation
On average, grocery stores do not show a significant difference in ratings by price, while among pizza stores, those with higher prices tend to show higher ratings. Furthermore, people visiting grocery stores show greater variance in ratings when the stores have higher selling prices, and this tendency is more prominent among grocery customers compared to pizza customers.
The characteristics of each category are worth noting to account for this trend. First, at groceries, people usually purchase commodities that are also available at other grocery stores but with a slight difference in quality. Particularly, in groceries with high selling prices overall, some customers may be frustrated by the same milk brand, for example, selling at a higher price, while others may think that milk brand with better quality and reputation worths buying at a higher price and be pleased to come across that product on the day they visited. This explains the greater variance in ratings among high-price groceries.
Among pizza stores, however, the average in ratings, not the variance, differs by the price level. Although pizza is widely considered as a daily menu, it is also a type of food that many people tend to be picky on its style, ingredients, and quality strongly based on their preferences. So, some pizza stores are well-regarded than others, and people think high price pizzas pay off.