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(readxl)
bike_orderlines <- read_excel("bike_orderlines.xlsx")
customer_preferences <- bike_orderlines %>%
group_by(bikeshop_name, category_1) %>%
summarise(total_spent = sum(total_price, na.rm = TRUE)) %>%
ungroup()
## `summarise()` has grouped output by 'bikeshop_name'. You can override using the
## `.groups` argument.
road_customers <- customer_preferences %>%
filter(category_1 == "Road") %>%
arrange(desc(total_spent)) %>%
slice(1:3)
mountain_customers <- customer_preferences %>%
filter(category_1 == "Mountain") %>%
arrange(desc(total_spent)) %>%
slice(1:3)
print("Top 3 Road Bike Customers:")
## [1] "Top 3 Road Bike Customers:"
print(road_customers)
## # A tibble: 3 × 3
## bikeshop_name category_1 total_spent
## <chr> <chr> <dbl>
## 1 Oklahoma City Race Equipment Road 2581635
## 2 Kansas City 29ers Road 2319505
## 3 New Orleans Velocipedes Road 2142705
print("Top 3 Mountain Bike Customers:")
## [1] "Top 3 Mountain Bike Customers:"
print(mountain_customers)
## # A tibble: 3 × 3
## bikeshop_name category_1 total_spent
## <chr> <chr> <dbl>
## 1 Kansas City 29ers Mountain 9215950
## 2 Denver Bike Shop Mountain 6038105
## 3 Ithaca Mountain Climbers Mountain 4660325