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
bike_data <- read_excel("bike_orderlines.xlsx")
mountain_road_bikes <- bike_data[bike_data$category_1 %in% c("Mountain", "Road"), ]
bike_shop_sales <- aggregate(
  quantity ~ bikeshop_name + category_1, 
  data = mountain_road_bikes, 
  FUN = sum
)
top_shops_mountain <- bike_shop_sales[
  bike_shop_sales$category_1 == "Mountain", 
][order(bike_shop_sales$quantity[bike_shop_sales$category_1 == "Mountain"], decreasing = TRUE), ][1:3, ]
top_shops_road <- bike_shop_sales[
  bike_shop_sales$category_1 == "Road", 
][order(bike_shop_sales$quantity[bike_shop_sales$category_1 == "Road"], decreasing = TRUE), ][1:3, ]
top_shops_overall <- rbind(top_shops_mountain, top_shops_road)
print(top_shops_overall)
##                   bikeshop_name category_1 quantity
## 11            Kansas City 29ers   Mountain     2484
## 7              Denver Bike Shop   Mountain     1623
## 10     Ithaca Mountain Climbers   Mountain      953
## 41            Kansas City 29ers       Road      987
## 50 Oklahoma City Race Equipment       Road      822
## 52              Phoenix Bi-peds       Road      697