title: “Untitled” output: html_document date: “2023-11-28” —
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
path_bike_orderlines <- "bike_orderlines.rds"
bike_orderlines_tbl <- readRDS(path_bike_orderlines)
selected_data <- bike_orderlines_tbl %>%
select(bikeshop_name, category_1, category_2, quantity)
customer_habits <- selected_data %>%
group_by(bikeshop_name, category_1, category_2) %>%
summarise(total_quantity = sum(quantity)) %>%
ungroup()
## `summarise()` has grouped output by 'bikeshop_name', 'category_1'. You can
## override using the `.groups` argument.
road_mountain_customers <- customer_habits %>%
filter(category_1 %in% c("Road", "Mountain") | category_2 %in% c("Road", "Mountain"))
total_sales <- road_mountain_customers %>%
group_by(bikeshop_name) %>%
summarise(total_quantity = sum(total_quantity))
percentage_sales <- total_sales %>%
mutate(percentage = (total_quantity / sum(total_quantity)) * 100)
print(percentage_sales)
## # A tibble: 30 × 3
## bikeshop_name total_quantity percentage
## <chr> <dbl> <dbl>
## 1 Albuquerque Cycles 286 1.42
## 2 Ann Arbor Speed 602 2.98
## 3 Austin Cruisers 246 1.22
## 4 Cincinnati Speed 391 1.94
## 5 Columbus Race Equipment 394 1.95
## 6 Dallas Cycles 234 1.16
## 7 Denver Bike Shop 2301 11.4
## 8 Detroit Cycles 504 2.50
## 9 Indianapolis Velocipedes 319 1.58
## 10 Ithaca Mountain Climbers 1264 6.27
## # ℹ 20 more rows
knitr::opts_chunk$set(echo = TRUE)
```