bike_order_1 <- readRDS("bike folder/bike_orderlines.rds")
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.3 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ ggplot2 3.4.3 ✔ tibble 3.2.1
## ✔ lubridate 1.9.2 ✔ tidyr 1.3.0
## ✔ 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(lubridate)
library(stringr)
Q1
bike_order_1 <- bike_order_1 %>%
mutate(model = str_replace_all(model,
c("CAAD Disk Ultegrato" = "CAAD12 Disc Ultegra",
"Syapse Carbon Tiagrato" = "Synapse Carbon Tiagra",
"Supersix Evo Hi-Mod Utegrato" = "Supersix Evo Hi-Mod Ultegra"))
)
glimpse(bike_order_1)
## Rows: 15,644
## Columns: 13
## $ order_date <dttm> 2011-01-07, 2011-01-07, 2011-01-10, 2011-01-10, 2011-0…
## $ order_id <dbl> 1, 1, 2, 2, 3, 3, 3, 3, 3, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7…
## $ order_line <dbl> 1, 2, 1, 2, 1, 2, 3, 4, 5, 1, 1, 2, 3, 4, 1, 2, 3, 4, 1…
## $ quantity <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1…
## $ price <dbl> 6070, 5970, 2770, 5970, 10660, 3200, 12790, 5330, 1570,…
## $ total_price <dbl> 6070, 5970, 2770, 5970, 10660, 3200, 12790, 5330, 1570,…
## $ model <chr> "Jekyll Carbon 2", "Trigger Carbon 2", "Beast of the Ea…
## $ category_1 <chr> "Mountain", "Mountain", "Mountain", "Mountain", "Road",…
## $ category_2 <chr> "Over Mountain", "Over Mountain", "Trail", "Over Mounta…
## $ frame_material <chr> "Carbon", "Carbon", "Aluminum", "Carbon", "Carbon", "Ca…
## $ bikeshop_name <chr> "Ithaca Mountain Climbers", "Ithaca Mountain Climbers",…
## $ city <chr> "Ithaca", "Ithaca", "Kansas City", "Kansas City", "Loui…
## $ state <chr> "NY", "NY", "KS", "KS", "KY", "KY", "KY", "KY", "KY", "…
Q2
bike_order_2 <- bike_order_1 %>%
mutate(order_date = as.Date(order_date))
monthly_sales <- bike_order_2 %>%
group_by(Month = format(order_date, "%B")) %>%
summarize(Sales = sum(quantity * price))
highest_month <- monthly_sales %>%
filter(Sales == max(Sales))
print(highest_month)
## # A tibble: 1 × 2
## Month Sales
## <chr> <dbl>
## 1 April 8386170
Q3—-1
bike_order_3 <- tribble(
~'Bike Attribute', ~'Median Orderline', ~'Black Inc',
'Attribute A', 123, FALSE,
'Attribute B', 456, TRUE,
'Attribute A', 789, TRUE,
'Attribute B', 1011, FALSE,
'Attribute A', 1213, TRUE
)
bike_order_3 <- bike_order_3 %>%
filter(!is.na(as.numeric(`Median Orderline`)))
median_data <- bike_order_3 %>%
group_by('Black Inc') %>%
summarise('Median Orderline' = median(as.numeric(`Median Orderline`)))
median_data <- median_data %>%
mutate('Median Orderline' = scales::dollar(`Median Orderline`))
print(median_data)
## # A tibble: 1 × 2
## `"Black Inc"` `Median Orderline`
## <chr> <chr>
## 1 Black Inc $789
Q4
bike_order_4 <- bike_order_1 %>%
rename(`‘Category 1‘` = category_1,
`‘Category 2‘` = category_2,
`‘Model Base‘` = model) %>%
group_by(`‘Category 1‘`, `‘Category 2‘`, `‘Model Base‘`) %>%
summarize(
`‘Mean Price‘` = mean(price),
`‘Min Price‘` = min(price),
`‘Max Price‘` = max(price)
)
## `summarise()` has grouped output by '‘Category 1‘', '‘Category 2‘'. You can
## override using the `.groups` argument.
head(bike_order_4)
## # A tibble: 6 × 6
## # Groups: ‘Category 1‘, ‘Category 2‘ [1]
## `‘Category 1‘` `‘Category 2‘` `‘Model Base‘` `‘Mean Price‘` `‘Min Price‘`
## <chr> <chr> <chr> <dbl> <dbl>
## 1 Mountain Cross Country Race F-Si 1 2340 2340
## 2 Mountain Cross Country Race F-Si 2 2060 2060
## 3 Mountain Cross Country Race F-Si 3 1840 1840
## 4 Mountain Cross Country Race F-Si Black Inc. 11190 11190
## 5 Mountain Cross Country Race F-Si Carbon 2 4800 4800
## 6 Mountain Cross Country Race F-Si Carbon 4 2880 2880
## # ℹ 1 more variable: `‘Max Price‘` <dbl>