# load necessary libraries
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.5.1 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(sf)
## Linking to GEOS 3.12.1, GDAL 3.8.4, PROJ 9.3.1; sf_use_s2() is TRUE
library(here)
## here() starts at C:/Users/wpgeorgia/Documents/GT MSUA/CP 8883/Intro to UA R Projects
library(tmap)
## Breaking News: tmap 3.x is retiring. Please test v4, e.g. with
## remotes::install_github('r-tmap/tmap')
library(jsonlite)
##
## Attaching package: 'jsonlite'
##
## The following object is masked from 'package:purrr':
##
## flatten
# load data file from Mini Assignment 1
yelp_gb_raw <- readRDS("yelp_gb.rds")
# Remove rows with duplicates in the 'alias' column since some gyms have multiple locations
# but their names in the 'name' column is the same (eg Planet Fitness)
# Data frame reduced from 274 businesses to just 59
yelp_gb_nodupes <- yelp_gb_raw %>%
distinct(alias, .keep_all = T)
# Flatten concatenated columns to split into multiple, separate columns
yelp_gb_flat <- yelp_gb_nodupes %>%
jsonlite::flatten()
# Edit list-columns to replace lists in columns with concatenated single data response
yelp_gb_concat <- yelp_gb_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=", ")))
# Address Categories column which contains varying data frames
concate_list <- function(x){
titles <- x[["title"]] %>% str_c(collapse = ", ")
return(titles)
}
yelp_gb_totallyflat <- yelp_gb_concat %>%
mutate(categories = categories %>% map_chr(concate_list))
# Per the results below, there are no missing missing values in the coordinates columns
yelp_gb_totallyflat %>%
map_dbl(., function(x) sum(is.na(x)))
## id alias
## 0 0
## name image_url
## 0 0
## is_closed url
## 0 0
## review_count categories
## 0 0
## rating transactions
## 0 0
## phone display_phone
## 0 0
## distance business_hours
## 0 0
## coordinates.latitude coordinates.longitude
## 0 0
## location.address1 location.address2
## 2 18
## location.address3 location.city
## 18 0
## location.zip_code location.country
## 0 0
## location.state location.display_address
## 0 0
## attributes.business_temp_closed attributes.waitlist_reservation
## 59 59
## attributes.menu_url
## 58
# Filter out any businesses not located in the city of Green Bay
yelp_gb_final <- yelp_gb_totallyflat %>%
filter(location.city == 'Green Bay')
# Comparing before and after tidying
glue::glue("nrow before: {nrow(yelp_gb_raw)} -> nrow after: {nrow(yelp_gb_final)}
ncol before: {ncol(yelp_gb_raw)} -> ncol after: {ncol(yelp_gb_final)} \n") %>%
print()
## nrow before: 274 -> nrow after: 48
## ncol before: 17 -> ncol after: 27
print(yelp_gb_final %>% head())
## id alias
## 1 CpyuQ1zNXQPPnf6vw-ebkA morning-sun-yoga-main-street-green-bay
## 2 mPdo9z6Q687PJBmjyYSKpw jenstar-movement-studio-green-bay
## 3 3LshRsErUFXzWwvkdCisSw grace-yoga-studio-green-bay
## 4 5jQz1lvN2EvF-tYWhZh70Q judith-rybicki-lmt-heal-wellness-green-bay
## 5 5DKy9mh5w2k8xk9_bF-vIQ east-side-y-green-bay
## 6 YVTElVk1blTIyJALt8BeWQ evolve-yoga-and-wellness-green-bay-2
## name
## 1 Morning Sun Yoga Main Street
## 2 Jenstar Movement Studio
## 3 Grace Yoga Studio
## 4 Judith Rybicki, LMT - Heal Wellness
## 5 East Side Y
## 6 Evolve Yoga And Wellness
## image_url
## 1 https://s3-media1.fl.yelpcdn.com/bphoto/-BDImP2HbtjQ-yEqZoT2Lw/o.jpg
## 2 https://s3-media3.fl.yelpcdn.com/bphoto/l0MEEtcYdgYJbsfKVcV6zA/o.jpg
## 3 https://s3-media1.fl.yelpcdn.com/bphoto/Qs2smntHoSHAjsCrGoKa7g/o.jpg
## 4
## 5 https://s3-media1.fl.yelpcdn.com/bphoto/1-ZJei4nsNQzKMuZmkcKJw/o.jpg
## 6 https://s3-media4.fl.yelpcdn.com/bphoto/ECv6FwzI91hxlFHWpkwPTA/o.jpg
## is_closed
## 1 FALSE
## 2 FALSE
## 3 FALSE
## 4 FALSE
## 5 FALSE
## 6 FALSE
## url
## 1 https://www.yelp.com/biz/morning-sun-yoga-main-street-green-bay?adjust_creative=72s2b4tegZYAV3R0gFzLUQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=72s2b4tegZYAV3R0gFzLUQ
## 2 https://www.yelp.com/biz/jenstar-movement-studio-green-bay?adjust_creative=72s2b4tegZYAV3R0gFzLUQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=72s2b4tegZYAV3R0gFzLUQ
## 3 https://www.yelp.com/biz/grace-yoga-studio-green-bay?adjust_creative=72s2b4tegZYAV3R0gFzLUQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=72s2b4tegZYAV3R0gFzLUQ
## 4 https://www.yelp.com/biz/judith-rybicki-lmt-heal-wellness-green-bay?adjust_creative=72s2b4tegZYAV3R0gFzLUQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=72s2b4tegZYAV3R0gFzLUQ
## 5 https://www.yelp.com/biz/east-side-y-green-bay?adjust_creative=72s2b4tegZYAV3R0gFzLUQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=72s2b4tegZYAV3R0gFzLUQ
## 6 https://www.yelp.com/biz/evolve-yoga-and-wellness-green-bay-2?adjust_creative=72s2b4tegZYAV3R0gFzLUQ&utm_campaign=yelp_api_v3&utm_medium=api_v3_business_search&utm_source=72s2b4tegZYAV3R0gFzLUQ
## review_count categories rating transactions
## 1 1 Yoga 5.0
## 2 8 Yoga, Dance Studios, Barre Classes 4.5
## 3 4 Yoga, Pilates 5.0
## 4 0 Acupuncture, Massage Therapy, Yoga 0.0
## 5 3 Gyms, Yoga 4.0
## 6 0 Yoga 0.0
## phone display_phone distance
## 1 1275.165
## 2 +19207841600 (920) 784-1600 1535.118
## 3 +19205624295 (920) 562-4295 1382.088
## 4 +17868779354 (786) 877-9354 1297.985
## 5 +19204369622 (920) 436-9622 10582.379
## 6 9056.632
## business_hours
## 1 NULL
## 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 NULL
## 4 NULL
## 5 FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, 0500, 0500, 0500, 0500, 0500, 0600, 0600, 2200, 2200, 2200, 2200, 2100, 1800, 1600, 0, 1, 2, 3, 4, 5, 6, REGULAR, TRUE
## 6 NULL
## coordinates.latitude coordinates.longitude location.address1
## 1 44.51106 -87.99831 1232 Main St
## 2 44.49817 -88.02186 1212 Marine St
## 3 44.52040 -88.01948 333 N Broadway
## 4 44.50273 -87.98410 1640 Main St
## 5 44.46962 -87.91898 1740 S Huron Rd
## 6 44.48009 -87.96094
## location.address2 location.address3 location.city location.zip_code
## 1 <NA> Green Bay 54302
## 2 Green Bay 54301
## 3 Green Bay 54303
## 4 Ste 240 <NA> Green Bay 54302
## 5 <NA> <NA> Green Bay 54311
## 6 <NA> Green Bay 54311
## location.country location.state location.display_address
## 1 US WI 1232 Main St, Green Bay, WI 54302
## 2 US WI 1212 Marine St, Green Bay, WI 54301
## 3 US WI 333 N Broadway, Green Bay, WI 54303
## 4 US WI 1640 Main St, Ste 240, Green Bay, WI 54302
## 5 US WI 1740 S Huron Rd, Green Bay, WI 54311
## 6 US WI Green Bay, WI 54311
## attributes.business_temp_closed attributes.waitlist_reservation
## 1 NA NA
## 2 NA NA
## 3 NA NA
## 4 NA NA
## 5 NA NA
## 6 NA NA
## attributes.menu_url
## 1 <NA>
## 2 <NA>
## 3 <NA>
## 4 <NA>
## 5 <NA>
## 6 <NA>
Conclusions Tidying the Green Bay data significantly reduced the number of data points in the data frame - from 274 down to just 48. Given that the city (along with the entire state of Wisconsin) is often stereotyped for consuming too many bratwursts and too much beer, the untidy data painted a rosier picture of Green Bay’s fitness activity. However, the data is now certainly more digestible, and several new observations are apparent.
First, based simply on the names of the businesses, the city isn’t home to many fitness franchises like 24 Hour Fitness, LA Fitness, or Equinox. There are a few big names like Planet Fitness, but by and large, Green Bay’s gyms and yoga studios seem to be homegrown small businesses.
Second, the Categories column reveals that many gyms are offering services beyond physical fitness. Childcare, massage therapy, tanning, and counseling are a few of the other categories included in the data frame. Because gym fees and memberships are luxuries for most, businesses likely have to offer more services in an attempt to prove their value to potential new customers while also retaining existing customers.
Finally, only 6 of the 48 gyms listed have more than 10 reviews on Yelp. It’s impossible to interpret that as an indicator of how many customers the gyms have, the health of the gym and fitness industry overall, or just how physically active Green Bay is. But the low number does pop, and it would be interesting to research further. Of course, it could be that Yelp just isn’t very popular way up north!