tidycensus::census_api_key(Sys.getenv("census_api"))
## To install your API key for use in future sessions, run this function with `install = TRUE`.
load("Assignment2.RData")
yelp_sf1
## Simple feature collection with 494 features and 19 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -88.31897 ymin: 40.05884 xmax: -88.20487 ymax: 40.15636
## Geodetic CRS: WGS 84
## # A tibble: 494 × 20
## id alias name image_url is_closed url review_count categories rating
## * <chr> <chr> <chr> <chr> <lgl> <chr> <int> <list> <dbl>
## 1 F7JWSEL… circ… Circ… "https:/… FALSE http… 2 <df> 2.5
## 2 dY5bImd… circ… Circ… "https:/… FALSE http… 2 <df> 1
## 3 vyCTd76… cvs-… CVS … "https:/… FALSE http… 22 <df> 2
## 4 GKQWjnl… reyn… Reyn… "https:/… FALSE http… 24 <df> 2.9
## 5 EO6ZQJw… mobi… Mobil "" FALSE http… 1 <df> 1
## 6 4sKzg4-… cost… Cost… "https:/… FALSE http… 19 <df> 4
## 7 7JtxfWC… shel… Shell "" FALSE http… 1 <df> 1
## 8 CI85fp3… circ… Circ… "" FALSE http… 1 <df> 1
## 9 lVbQzYz… mach… Mach… "https:/… FALSE http… 3 <df> 2.3
## 10 Zyq6S_M… circ… Circ… "https:/… FALSE http… 3 <df> 2.3
## # ℹ 484 more rows
## # ℹ 11 more variables: coordinates <df[,2]>, transactions <list>, price <chr>,
## # location <df[,8]>, phone <chr>, display_phone <chr>, distance <dbl>,
## # business_hours <list>, attributes <df[,4]>, type <chr>,
## # geometry <POINT [°]>
yelp_sf2 <- yelp_sf1 %>%
distinct(id, .keep_all=TRUE)
nrow(yelp_sf2)
## [1] 157
yelp_data <- yelp_sf2 %>% bind_rows() %>% as_tibble()
yelp_flat <- yelp_data %>%
jsonlite::flatten()
yelp_flat %>% head()
## id alias
## 1 F7JWSELLVvDLBVBTVCmu0g circle-k-champaign
## 2 dY5bImdQbT_6V7_kPrn1HQ circle-k-champaign-10
## 3 vyCTd76g2aGqWvY1229ofw cvs-pharmacy-champaign-3
## 4 GKQWjnloUthLFGsSsrpZUw reynolds-towing-service-urbana-2
## 5 EO6ZQJwWdzTbcL3WMrWs0w mobil-champaign-3
## 6 4sKzg4-WSkucvHsjre4wcw costco-champaign
## name
## 1 Circle K
## 2 Circle K
## 3 CVS Pharmacy
## 4 Reynolds Towing Service
## 5 Mobil
## 6 Costco
## image_url
## 1 https://s3-media4.fl.yelpcdn.com/bphoto/lODk-3lvG9jUxOiSQeSibQ/o.jpg
## 2 https://s3-media3.fl.yelpcdn.com/bphoto/RyxizO-1U5-1c0kg87T-pg/o.jpg
## 3 https://s3-media1.fl.yelpcdn.com/bphoto/7vRKcO6fIxSxaq7WKvroUw/o.jpg
## 4 https://s3-media3.fl.yelpcdn.com/bphoto/-6MytL-R4CMb1EJC7F_H6g/o.jpg
## 5
## 6 https://s3-media2.fl.yelpcdn.com/bphoto/7bee76lvKxAW6fJVMbUdDw/o.jpg
## is_closed
## 1 FALSE
## 2 FALSE
## 3 FALSE
## 4 FALSE
## 5 FALSE
## 6 FALSE
## url
## 1 https://www.yelp.com/biz/circle-k-champaign?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 2 https://www.yelp.com/biz/circle-k-champaign-10?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 3 https://www.yelp.com/biz/cvs-pharmacy-champaign-3?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 4 https://www.yelp.com/biz/reynolds-towing-service-urbana-2?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 5 https://www.yelp.com/biz/mobil-champaign-3?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 6 https://www.yelp.com/biz/costco-champaign?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## review_count
## 1 2
## 2 2
## 3 22
## 4 24
## 5 1
## 6 19
## categories
## 1 servicestations, convenience, Gas Stations, Convenience Stores
## 2 convenience, servicestations, Convenience Stores, Gas Stations
## 3 drugstores, pharmacy, convenience, Drugstores, Pharmacy, Convenience Stores
## 4 roadsideassist, Roadside Assistance
## 5 servicestations, Gas Stations
## 6 wholesale_stores, servicestations, pharmacy, Wholesale Stores, Gas Stations, Pharmacy
## rating transactions price phone display_phone distance
## 1 2.5 $ +12173985868 (217) 398-5868 639.4925
## 2 1.0 <NA> +12173448722 (217) 344-8722 1085.0385
## 3 2.0 delivery $$ +12173558123 (217) 355-8123 705.5705
## 4 2.9 <NA> +12173370913 (217) 337-0913 3630.1919
## 5 1.0 NULL <NA> +12173551872 (217) 355-1872 310.2816
## 6 4.0 NULL $$ +12176006546 (217) 600-6546 1353.3842
## business_hours
## 1 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 2 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 3 FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 0700, 0700, 0700, 0700, 0700, 0700, 0700, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 4 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 5 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 6 FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1000, 1000, 1000, 1000, 1000, 0930, 1000, 2030, 2030, 2030, 2030, 2030, 1800, 1800, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## type geometry coordinates.latitude
## 1 gas station POINT (-88.24428 40.102) 40.10200
## 2 gas station POINT (-88.23914 40.10992) 40.10992
## 3 gas station POINT (-88.2441 40.1096) 40.10960
## 4 gas station POINT (-88.22967 40.13395) 40.13395
## 5 gas station POINT (-88.24397 40.13101) 40.13101
## 6 gas station POINT (-88.24506 40.1402) 40.14020
## coordinates.longitude location.address1 location.address2 location.address3
## 1 -88.24428 1301 S Neil St <NA> <NA>
## 2 -88.23914 59 E Green St <NA>
## 3 -88.24410 107 West Green St
## 4 -88.22967 1417 W Kenyon Rd
## 5 -88.24397 1503 N Neil St <NA>
## 6 -88.24506 2002 N Neil St <NA>
## location.city location.zip_code location.country location.state
## 1 Champaign 61820 US IL
## 2 Champaign 61820 US IL
## 3 Champaign 61820 US IL
## 4 Urbana 61801 US IL
## 5 Champaign 61820 US IL
## 6 Champaign 61820 US IL
## location.display_address attributes.business_temp_closed
## 1 1301 S Neil St, Champaign, IL 61820 NA
## 2 59 E Green St, Champaign, IL 61820 NA
## 3 107 West Green St, Champaign, IL 61820 NA
## 4 1417 W Kenyon Rd, Urbana, IL 61801 NA
## 5 1503 N Neil St, Champaign, IL 61820 NA
## 6 2002 N Neil St, Champaign, IL 61820 NA
## attributes.waitlist_reservation attributes.menu_url attributes.open24_hours
## 1 NA <NA> NA
## 2 NA <NA> NA
## 3 NA <NA> NA
## 4 NA <NA> NA
## 5 NA <NA> NA
## 6 NA <NA> NA
yelp_concat <- yelp_flat %>%
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=", ")))
yelp_concat %>% head()
## id alias
## 1 F7JWSELLVvDLBVBTVCmu0g circle-k-champaign
## 2 dY5bImdQbT_6V7_kPrn1HQ circle-k-champaign-10
## 3 vyCTd76g2aGqWvY1229ofw cvs-pharmacy-champaign-3
## 4 GKQWjnloUthLFGsSsrpZUw reynolds-towing-service-urbana-2
## 5 EO6ZQJwWdzTbcL3WMrWs0w mobil-champaign-3
## 6 4sKzg4-WSkucvHsjre4wcw costco-champaign
## name
## 1 Circle K
## 2 Circle K
## 3 CVS Pharmacy
## 4 Reynolds Towing Service
## 5 Mobil
## 6 Costco
## image_url
## 1 https://s3-media4.fl.yelpcdn.com/bphoto/lODk-3lvG9jUxOiSQeSibQ/o.jpg
## 2 https://s3-media3.fl.yelpcdn.com/bphoto/RyxizO-1U5-1c0kg87T-pg/o.jpg
## 3 https://s3-media1.fl.yelpcdn.com/bphoto/7vRKcO6fIxSxaq7WKvroUw/o.jpg
## 4 https://s3-media3.fl.yelpcdn.com/bphoto/-6MytL-R4CMb1EJC7F_H6g/o.jpg
## 5
## 6 https://s3-media2.fl.yelpcdn.com/bphoto/7bee76lvKxAW6fJVMbUdDw/o.jpg
## is_closed
## 1 FALSE
## 2 FALSE
## 3 FALSE
## 4 FALSE
## 5 FALSE
## 6 FALSE
## url
## 1 https://www.yelp.com/biz/circle-k-champaign?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 2 https://www.yelp.com/biz/circle-k-champaign-10?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 3 https://www.yelp.com/biz/cvs-pharmacy-champaign-3?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 4 https://www.yelp.com/biz/reynolds-towing-service-urbana-2?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 5 https://www.yelp.com/biz/mobil-champaign-3?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 6 https://www.yelp.com/biz/costco-champaign?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## review_count
## 1 2
## 2 2
## 3 22
## 4 24
## 5 1
## 6 19
## categories
## 1 servicestations, convenience, Gas Stations, Convenience Stores
## 2 convenience, servicestations, Convenience Stores, Gas Stations
## 3 drugstores, pharmacy, convenience, Drugstores, Pharmacy, Convenience Stores
## 4 roadsideassist, Roadside Assistance
## 5 servicestations, Gas Stations
## 6 wholesale_stores, servicestations, pharmacy, Wholesale Stores, Gas Stations, Pharmacy
## rating transactions price phone display_phone distance
## 1 2.5 $ +12173985868 (217) 398-5868 639.4925
## 2 1.0 <NA> +12173448722 (217) 344-8722 1085.0385
## 3 2.0 delivery $$ +12173558123 (217) 355-8123 705.5705
## 4 2.9 <NA> +12173370913 (217) 337-0913 3630.1919
## 5 1.0 <NA> +12173551872 (217) 355-1872 310.2816
## 6 4.0 $$ +12176006546 (217) 600-6546 1353.3842
## business_hours
## 1 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 2 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 3 FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 0700, 0700, 0700, 0700, 0700, 0700, 0700, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 4 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 5 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 6 FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1000, 1000, 1000, 1000, 1000, 0930, 1000, 2030, 2030, 2030, 2030, 2030, 1800, 1800, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## type geometry coordinates.latitude
## 1 gas station POINT (-88.24428 40.102) 40.10200
## 2 gas station POINT (-88.23914 40.10992) 40.10992
## 3 gas station POINT (-88.2441 40.1096) 40.10960
## 4 gas station POINT (-88.22967 40.13395) 40.13395
## 5 gas station POINT (-88.24397 40.13101) 40.13101
## 6 gas station POINT (-88.24506 40.1402) 40.14020
## coordinates.longitude location.address1 location.address2 location.address3
## 1 -88.24428 1301 S Neil St <NA> <NA>
## 2 -88.23914 59 E Green St <NA>
## 3 -88.24410 107 West Green St
## 4 -88.22967 1417 W Kenyon Rd
## 5 -88.24397 1503 N Neil St <NA>
## 6 -88.24506 2002 N Neil St <NA>
## location.city location.zip_code location.country location.state
## 1 Champaign 61820 US IL
## 2 Champaign 61820 US IL
## 3 Champaign 61820 US IL
## 4 Urbana 61801 US IL
## 5 Champaign 61820 US IL
## 6 Champaign 61820 US IL
## location.display_address attributes.business_temp_closed
## 1 1301 S Neil St, Champaign, IL 61820 NA
## 2 59 E Green St, Champaign, IL 61820 NA
## 3 107 West Green St, Champaign, IL 61820 NA
## 4 1417 W Kenyon Rd, Urbana, IL 61801 NA
## 5 1503 N Neil St, Champaign, IL 61820 NA
## 6 2002 N Neil St, Champaign, IL 61820 NA
## attributes.waitlist_reservation attributes.menu_url attributes.open24_hours
## 1 NA <NA> NA
## 2 NA <NA> NA
## 3 NA <NA> NA
## 4 NA <NA> NA
## 5 NA <NA> NA
## 6 NA <NA> NA
concate_list <- function(x){
titles <- x[["title"]] %>% str_c(collapse = ", ")
return(titles)
}
yelp_flat2 <- yelp_concat %>%
mutate(categories = categories %>% map_chr(concate_list))
yelp_flat2 %>% head()
## id alias
## 1 F7JWSELLVvDLBVBTVCmu0g circle-k-champaign
## 2 dY5bImdQbT_6V7_kPrn1HQ circle-k-champaign-10
## 3 vyCTd76g2aGqWvY1229ofw cvs-pharmacy-champaign-3
## 4 GKQWjnloUthLFGsSsrpZUw reynolds-towing-service-urbana-2
## 5 EO6ZQJwWdzTbcL3WMrWs0w mobil-champaign-3
## 6 4sKzg4-WSkucvHsjre4wcw costco-champaign
## name
## 1 Circle K
## 2 Circle K
## 3 CVS Pharmacy
## 4 Reynolds Towing Service
## 5 Mobil
## 6 Costco
## image_url
## 1 https://s3-media4.fl.yelpcdn.com/bphoto/lODk-3lvG9jUxOiSQeSibQ/o.jpg
## 2 https://s3-media3.fl.yelpcdn.com/bphoto/RyxizO-1U5-1c0kg87T-pg/o.jpg
## 3 https://s3-media1.fl.yelpcdn.com/bphoto/7vRKcO6fIxSxaq7WKvroUw/o.jpg
## 4 https://s3-media3.fl.yelpcdn.com/bphoto/-6MytL-R4CMb1EJC7F_H6g/o.jpg
## 5
## 6 https://s3-media2.fl.yelpcdn.com/bphoto/7bee76lvKxAW6fJVMbUdDw/o.jpg
## is_closed
## 1 FALSE
## 2 FALSE
## 3 FALSE
## 4 FALSE
## 5 FALSE
## 6 FALSE
## url
## 1 https://www.yelp.com/biz/circle-k-champaign?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 2 https://www.yelp.com/biz/circle-k-champaign-10?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 3 https://www.yelp.com/biz/cvs-pharmacy-champaign-3?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 4 https://www.yelp.com/biz/reynolds-towing-service-urbana-2?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 5 https://www.yelp.com/biz/mobil-champaign-3?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## 6 https://www.yelp.com/biz/costco-champaign?adjust_creative=4ZMcoYhbkuS8Q062Le5ERQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=4ZMcoYhbkuS8Q062Le5ERQ
## review_count categories rating transactions
## 1 2 Gas Stations, Convenience Stores 2.5
## 2 2 Convenience Stores, Gas Stations 1.0
## 3 22 Drugstores, Pharmacy, Convenience Stores 2.0 delivery
## 4 24 Roadside Assistance 2.9
## 5 1 Gas Stations 1.0
## 6 19 Wholesale Stores, Gas Stations, Pharmacy 4.0
## price phone display_phone distance
## 1 $ +12173985868 (217) 398-5868 639.4925
## 2 <NA> +12173448722 (217) 344-8722 1085.0385
## 3 $$ +12173558123 (217) 355-8123 705.5705
## 4 <NA> +12173370913 (217) 337-0913 3630.1919
## 5 <NA> +12173551872 (217) 355-1872 310.2816
## 6 $$ +12176006546 (217) 600-6546 1353.3842
## business_hours
## 1 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 2 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 3 FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 0700, 0700, 0700, 0700, 0700, 0700, 0700, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 4 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 5 TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, TRUE, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0000, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 6 FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 1000, 1000, 1000, 1000, 1000, 0930, 1000, 2030, 2030, 2030, 2030, 2030, 1800, 1800, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## type geometry coordinates.latitude
## 1 gas station POINT (-88.24428 40.102) 40.10200
## 2 gas station POINT (-88.23914 40.10992) 40.10992
## 3 gas station POINT (-88.2441 40.1096) 40.10960
## 4 gas station POINT (-88.22967 40.13395) 40.13395
## 5 gas station POINT (-88.24397 40.13101) 40.13101
## 6 gas station POINT (-88.24506 40.1402) 40.14020
## coordinates.longitude location.address1 location.address2 location.address3
## 1 -88.24428 1301 S Neil St <NA> <NA>
## 2 -88.23914 59 E Green St <NA>
## 3 -88.24410 107 West Green St
## 4 -88.22967 1417 W Kenyon Rd
## 5 -88.24397 1503 N Neil St <NA>
## 6 -88.24506 2002 N Neil St <NA>
## location.city location.zip_code location.country location.state
## 1 Champaign 61820 US IL
## 2 Champaign 61820 US IL
## 3 Champaign 61820 US IL
## 4 Urbana 61801 US IL
## 5 Champaign 61820 US IL
## 6 Champaign 61820 US IL
## location.display_address attributes.business_temp_closed
## 1 1301 S Neil St, Champaign, IL 61820 NA
## 2 59 E Green St, Champaign, IL 61820 NA
## 3 107 West Green St, Champaign, IL 61820 NA
## 4 1417 W Kenyon Rd, Urbana, IL 61801 NA
## 5 1503 N Neil St, Champaign, IL 61820 NA
## 6 2002 N Neil St, Champaign, IL 61820 NA
## attributes.waitlist_reservation attributes.menu_url attributes.open24_hours
## 1 NA <NA> NA
## 2 NA <NA> NA
## 3 NA <NA> NA
## 4 NA <NA> NA
## 5 NA <NA> NA
## 6 NA <NA> NA
yelp_flat3 <- yelp_flat2 %>%
unnest_wider(business_hours) %>%
select(-open)
yelp_flat3 %>% head()
## # A tibble: 6 × 32
## id alias name image_url is_closed url review_count categories rating
## <chr> <chr> <chr> <chr> <lgl> <chr> <int> <chr> <dbl>
## 1 F7JWSELL… circ… Circ… "https:/… FALSE http… 2 Gas Stati… 2.5
## 2 dY5bImdQ… circ… Circ… "https:/… FALSE http… 2 Convenien… 1
## 3 vyCTd76g… cvs-… CVS … "https:/… FALSE http… 22 Drugstore… 2
## 4 GKQWjnlo… reyn… Reyn… "https:/… FALSE http… 24 Roadside … 2.9
## 5 EO6ZQJwW… mobi… Mobil "" FALSE http… 1 Gas Stati… 1
## 6 4sKzg4-W… cost… Cost… "https:/… FALSE http… 19 Wholesale… 4
## # ℹ 23 more variables: transactions <chr>, price <chr>, phone <chr>,
## # display_phone <chr>, distance <dbl>, hours_type <chr>, is_open_now <lgl>,
## # type <chr>, geometry <POINT [°]>, coordinates.latitude <dbl>,
## # coordinates.longitude <dbl>, location.address1 <chr>,
## # location.address2 <chr>, location.address3 <chr>, location.city <chr>,
## # location.zip_code <chr>, location.country <chr>, location.state <chr>,
## # location.display_address <chr>, attributes.business_temp_closed <lgl>, …
yelp_flat4 <- yelp_flat3 %>%
mutate(x = .$coordinates.longitude,
y = .$coordinates.latitude) %>%
filter(!is.na(x) & !is.na(y)) %>%
st_as_sf(coords = c("x", "y"), crs = 4326)
yelp_clean <- yelp_flat4 %>%
filter(!is.na("x"),!is.na("x"))
champaign_boundary <- tigris::places('IL') %>%
filter(NAME == 'Champaign') %>%
st_transform(4326)
## Retrieving data for the year 2022
## | | | 0% | | | 1% | |= | 1% | |= | 2% | |== | 2% | |== | 3% | |=== | 4% | |=== | 5% | |==== | 5% | |==== | 6% | |===== | 7% | |===== | 8% | |====== | 8% | |====== | 9% | |======= | 10% | |======= | 11% | |======== | 11% | |======== | 12% | |========= | 12% | |========= | 13% | |========= | 14% | |========== | 14% | |========== | 15% | |=========== | 15% | |=========== | 16% | |============ | 17% | |============ | 18% | |============= | 18% | |================ | 22% | |================ | 23% | |================ | 24% | |================= | 24% | |================= | 25% | |================== | 25% | |================== | 26% | |=================== | 26% | |=================== | 27% | |=================== | 28% | |==================== | 28% | |==================== | 29% | |===================== | 30% | |========================== | 38% | |=========================== | 38% | |================================ | 45% | |================================ | 46% | |================================= | 47% | |=================================== | 50% | |=================================== | 51% | |==================================== | 51% | |==================================== | 52% | |===================================== | 52% | |===================================== | 53% | |====================================== | 54% | |====================================== | 55% | |======================================= | 55% | |======================================= | 56% | |======================================== | 57% | |========================================= | 58% | |========================================= | 59% | |========================================== | 59% | |========================================== | 60% | |========================================== | 61% | |=========================================== | 61% | |============================================== | 65% | |============================================== | 66% | |=============================================== | 67% | |=============================================== | 68% | |================================================ | 68% | |================================================ | 69% | |================================================= | 70% | |=================================================== | 72% | |=================================================== | 73% | |======================================================= | 79% | |======================================================== | 80% | |========================================================= | 81% | |========================================================= | 82% | |========================================================== | 83% | |=========================================================== | 84% | |=========================================================== | 85% | |============================================================ | 86% | |============================================================= | 87% | |============================================================= | 88% | |============================================================== | 89% | |=============================================================== | 89% | |=============================================================== | 90% | |=============================================================== | 91% | |================================================================ | 91% | |======================================================================| 99% | |======================================================================| 100%
within_matrix <- st_within(yelp_clean, champaign_boundary, sparse = FALSE)
within_vector <- apply(within_matrix, 1, any)
yelp_clean1 <- yelp_clean %>% filter(within_vector)
yelp_clean1
## Simple feature collection with 114 features and 31 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -88.31738 ymin: 40.07044 xmax: -88.22891 ymax: 40.15636
## Geodetic CRS: WGS 84
## # A tibble: 114 × 32
## id alias name image_url is_closed url review_count categories rating
## * <chr> <chr> <chr> <chr> <lgl> <chr> <int> <chr> <dbl>
## 1 F7JWSEL… circ… Circ… "https:/… FALSE http… 2 Gas Stati… 2.5
## 2 dY5bImd… circ… Circ… "https:/… FALSE http… 2 Convenien… 1
## 3 vyCTd76… cvs-… CVS … "https:/… FALSE http… 22 Drugstore… 2
## 4 EO6ZQJw… mobi… Mobil "" FALSE http… 1 Gas Stati… 1
## 5 4sKzg4-… cost… Cost… "https:/… FALSE http… 19 Wholesale… 4
## 6 7JtxfWC… shel… Shell "" FALSE http… 1 Gas Stati… 1
## 7 CI85fp3… circ… Circ… "" FALSE http… 1 Gas Stati… 1
## 8 lVbQzYz… mach… Mach… "https:/… FALSE http… 3 Gas Stati… 2.3
## 9 Zyq6S_M… circ… Circ… "https:/… FALSE http… 3 Convenien… 2.3
## 10 g47OIJS… andy… Andy… "https:/… FALSE http… 12 Towing, A… 3.7
## # ℹ 104 more rows
## # ℹ 23 more variables: transactions <chr>, price <chr>, phone <chr>,
## # display_phone <chr>, distance <dbl>, hours_type <chr>, is_open_now <lgl>,
## # type <chr>, geometry <POINT [°]>, coordinates.latitude <dbl>,
## # coordinates.longitude <dbl>, location.address1 <chr>,
## # location.address2 <chr>, location.address3 <chr>, location.city <chr>,
## # location.zip_code <chr>, location.country <chr>, location.state <chr>, …
tmap_mode("view")
## tmap mode set to interactive viewing
# Map
tm_shape(yelp_clean1) +
tm_dots(col = "type",
style="quantile",
shapes.labels="name",
popup.vars=c("Name"="name", "Reviews"="review_count", "Rating"="rating")
) +
tm_shape(champaign_boundary) + tm_borders(lwd=2)
After visualizing the cleaned data, I am not seeing a particularly different result than the uncleaned data before, although in the cleaning process, a huge number of rows are cleaned as duplicates, NA values or out of boundary values. This might because most of the data we cleaned are duplicate values, and are overlapped in the map we did last time, so there is not significant visual difference. We can see some trend in the spatial distribution of the cleaned data: the auto repair shops have a clustering pattern, while the gas stations are more evenly distributed. Both types tend to be along major highways, as these locations are probably easier for automobiles to access.