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
library(tidyr)
library(readr)
unique_categories <- read_csv("bike folder/bike_orderlines.csv")
## Rows: 15644 Columns: 13
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (7): model, category_1, category_2, frame_material, bikeshop_name, city...
## dbl (5): order_id, order_line, quantity, price, total_price
## dttm (1): order_date
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
##Q1
unique_categories %>%
select(category_1) %>%
distinct()
## # A tibble: 2 × 1
## category_1
## <chr>
## 1 Mountain
## 2 Road
unique_categories %>%
select(category_2) %>%
distinct()
## # A tibble: 9 × 1
## category_2
## <chr>
## 1 Over Mountain
## 2 Trail
## 3 Elite Road
## 4 Endurance Road
## 5 Sport
## 6 Cross Country Race
## 7 Cyclocross
## 8 Triathalon
## 9 Fat Bike
unique_categories %>%
select(frame_material) %>%
distinct()
## # A tibble: 2 × 1
## frame_material
## <chr>
## 1 Carbon
## 2 Aluminum
##Q2
sales_by_category <- unique_categories
sales_by_category %>%
group_by(category_1) %>%
summarise(Sales = sum(total_price)) %>%
rename(`Primary Category` = category_1) %>%
arrange(desc(Sales))
## # A tibble: 2 × 2
## `Primary Category` Sales
## <chr> <dbl>
## 1 Mountain 39154735
## 2 Road 31877595
sales_by_category %>%
group_by(category_2) %>%
summarise(Sales = sum(total_price)) %>%
rename(`Secondary Category` = category_2) %>%
arrange(desc(Sales))
## # A tibble: 9 × 2
## `Secondary Category` Sales
## <chr> <dbl>
## 1 Cross Country Race 19224630
## 2 Elite Road 15334665
## 3 Endurance Road 10381060
## 4 Trail 9373460
## 5 Over Mountain 7571270
## 6 Triathalon 4053750
## 7 Cyclocross 2108120
## 8 Sport 1932755
## 9 Fat Bike 1052620
sales_by_category %>%
group_by(frame_material) %>%
summarise(Sales = sum(total_price)) %>%
rename("Frame Materia" = frame_material) %>%
arrange(desc(Sales))
## # A tibble: 2 × 2
## `Frame Materia` Sales
## <chr> <dbl>
## 1 Carbon 52940540
## 2 Aluminum 18091790
##Q3
ombinations_check <- sales_by_category %>%
group_by(category_1, category_2) %>%
summarise(Aluminum_Carbon = all(c("Aluminum", "Carbon") %in% frame_material)) %>%
rename(`Primary Category` = category_1, `Secondary Category` = category_2 )
## `summarise()` has grouped output by 'category_1'. You can override using the
## `.groups` argument.