library(readxl)
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
file_path <- "bike_orderlines.xlsx"
bike_data <- read_excel(file_path)
filtered_data <- bike_data %>%
filter(category_1 %in% c("Mountain", "Road"))
customer_preferences <- filtered_data %>%
group_by(bikeshop_name, category_1) %>%
summarise(quantity = sum(quantity), .groups = "drop")
top_customers <- customer_preferences %>%
group_by(category_1) %>%
slice_max(quantity, n = 3)
print(top_customers)
## # A tibble: 6 × 3
## # Groups: category_1 [2]
## bikeshop_name category_1 quantity
## <chr> <chr> <dbl>
## 1 Kansas City 29ers Mountain 2484
## 2 Denver Bike Shop Mountain 1623
## 3 Ithaca Mountain Climbers Mountain 953
## 4 Kansas City 29ers Road 987
## 5 Oklahoma City Race Equipment Road 822
## 6 Phoenix Bi-peds Road 697