#Homework 4
install.packages("readxl")
##
## The downloaded binary packages are in
## /var/folders/sl/j6hs04wj2db1nl4scr0s7l6r0000gn/T//Rtmpy1G6gH/downloaded_packages
install.packages("tidyverse")
##
## The downloaded binary packages are in
## /var/folders/sl/j6hs04wj2db1nl4scr0s7l6r0000gn/T//Rtmpy1G6gH/downloaded_packages
library(tidyverse)
library(readxl)
library(writexl)
bikeshops_tbl <- read_excel("downloads/bikeshops.xlsx")
orderlines_tbl <- read_excel("downloads/orderlines.xlsx")
## New names:
## • `` -> `...1`
bike_orderlines_tbl <- read_csv("downloads/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.
summary_bike_orderlines_tbl <- bike_orderlines_tbl %>%
group_by(category_1, category_2, frame_material) %>%
summarise(Sales = sum(price, na.rm = TRUE))
## `summarise()` has grouped output by 'category_1', 'category_2'. You can
## override using the `.groups` argument.
library(scales)
summary_bike_orderlines_tbl <- summary_bike_orderlines_tbl %>%
mutate(Sales = dollar(Sales))
summary_bike_orderlines_tbl <- summary_bike_orderlines_tbl %>%
rename(
"Prime category" = category_1,
"Secondary category" = category_2,
"Frame Material" = frame_material)
summary_bike_orderlines_tbl
## # A tibble: 13 × 4
## # Groups: Prime category, Secondary category [9]
## `Prime category` `Secondary category` `Frame Material` Sales
## <chr> <chr> <chr> <chr>
## 1 Mountain Cross Country Race Aluminum $2,548,540
## 2 Mountain Cross Country Race Carbon $12,471,710
## 3 Mountain Fat Bike Aluminum $813,420
## 4 Mountain Over Mountain Carbon $5,850,440
## 5 Mountain Sport Aluminum $1,533,435
## 6 Mountain Trail Aluminum $3,543,650
## 7 Mountain Trail Carbon $3,817,830
## 8 Road Cyclocross Carbon $1,562,260
## 9 Road Elite Road Aluminum $4,358,415
## 10 Road Elite Road Carbon $7,561,900
## 11 Road Endurance Road Aluminum $1,281,520
## 12 Road Endurance Road Carbon $6,683,590
## 13 Road Triathalon Carbon $3,057,550
rmarkdown::render(“hw4.Rmd”)
```