R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

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)

path1 <- "./bike_orderlines.rds"
bike_orderlines <- read_rds(path1)

bike_orderlines %>% select(model) %>% 
   mutate(model = case_when(
        model == "CAAD Disc Ultegra" ~ "CAAD12 Disc Ultegra",
        model == "Syapse Carbon Tiagra" ~ "Synapse Carbon Tiagra",
        model == "Supersix Evo Hi-Mod Utegra" ~ "Supersix Evo Hi-Mod Ultegra",
        TRUE ~ model
    ))
## # A tibble: 15,644 × 1
##    model                          
##    <chr>                          
##  1 Jekyll Carbon 2                
##  2 Trigger Carbon 2               
##  3 Beast of the East 1            
##  4 Trigger Carbon 2               
##  5 Supersix Evo Hi-Mod Team       
##  6 Jekyll Carbon 4                
##  7 Supersix Evo Black Inc.        
##  8 Supersix Evo Hi-Mod Dura Ace 2 
##  9 Synapse Disc 105               
## 10 Synapse Carbon Disc Ultegra D12
## # ℹ 15,634 more rows
bike_orderlines %>% 
  select(order_date, total_price) %>% 
  mutate(order_date = ymd(order_date)) %>% 
  mutate(month = order_date %>% floor_date("month") %>% month(label =   TRUE)) %>%
  group_by(month) %>% 
  summarize(sales = sum(total_price))
## # A tibble: 12 × 2
##    month   sales
##    <ord>   <dbl>
##  1 Jan   4089460
##  2 Feb   5343295
##  3 Mar   7282280
##  4 Apr   8386170
##  5 May   7935055
##  6 Jun   7813105
##  7 Jul   7602005
##  8 Aug   5346125
##  9 Sep   5556055
## 10 Oct   4394300
## 11 Nov   4169755
## 12 Dec   3114725
bike_orderlines %>%
  select(model, total_price)%>%
  mutate(Black = model %>% str_detect("Black Inc") %>% as_factor()) %>%
  group_by(Black)%>%
  summarise(Median_Orderline = median(total_price))%>%
  ungroup() %>%
  mutate(Median_Orderline = scales::dollar(Median_Orderline))
## # A tibble: 2 × 2
##   Black Median_Orderline
##   <fct> <chr>           
## 1 FALSE $2,880          
## 2 TRUE  $12,250
bike_orderlines %>%
  select(model, total_price)%>%
  mutate(Ultegra = model %>% str_detect("Ultegra") %>% as_factor()) %>%
  group_by(Ultegra)%>%
  summarise(Median_Orderline = median(total_price))%>%
  ungroup() %>%
  mutate(Median_Orderline = scales::dollar(Median_Orderline))
## # A tibble: 2 × 2
##   Ultegra Median_Orderline
##   <fct>   <chr>           
## 1 FALSE   $3,200          
## 2 TRUE    $3,200
bike_orderlines %>%
  select(model, total_price)%>%
  mutate(Disc = model %>% str_detect("Disc") %>% as_factor()) %>%
  group_by(Disc)%>%
  summarise(Median_Orderline = median(total_price))%>%
  ungroup() %>%
  mutate(Median_Orderline = scales::dollar(Median_Orderline))
## # A tibble: 2 × 2
##   Disc  Median_Orderline
##   <fct> <chr>           
## 1 FALSE $3,200          
## 2 TRUE  $2,660
bike_orderlines %>%
    distinct(category_1, category_2, model, price)%>%
    separate(col    = model,
             into   = str_c("model_", 1:9),
             sep    = " ",
             remove = FALSE,
             fill   = "right",
             extra  = "drop"
             ) %>%
    
    
    mutate(model_base = case_when(
        
        
        str_detect(str_to_lower(model_1), "scalpel") ~ str_c(model_1, model_2,  sep =" "),
        
        
        str_detect(str_to_lower(model_1), "beast") ~ str_c(model_1, model_2, model_3, model_4,  sep =" "),
        TRUE ~ model_1)) %>%

    select(-(model_1:model_9)) %>%
   
    group_by(category_1, category_2, model_base) %>%
    summarise(
        mean_price = mean(price),
        min_price  = min(price),
        max_price  = max(price)
    ) %>%
    ungroup() %>%
    mutate(
        mean_price = scales::dollar(mean_price, largest_with_cents = 1e+4),
        min_price  = scales::dollar(min_price, largest_with_cents = 1e+4),
        max_price  = scales::dollar(max_price, largest_with_cents = 1e+4)) %>%
    
    
    arrange(desc(mean_price))
## `summarise()` has grouped output by 'category_1', 'category_2'. You can
## override using the `.groups` argument.
## # A tibble: 23 × 6
##    category_1 category_2         model_base       mean_price min_price max_price
##    <chr>      <chr>              <chr>            <chr>      <chr>     <chr>    
##  1 Mountain   Cross Country Race Scalpel-Si Race  $9,060     $9,060    $9,060   
##  2 Mountain   Cross Country Race Scalpel-Si Hi-M… $7,460     $7,460    $7,460   
##  3 Mountain   Sport              Catalyst         $546       $415      $705     
##  4 Road       Elite Road         Supersix         $5,491     $1,840    $12,790  
##  5 Mountain   Cross Country Race Scalpel-Si Carb… $5,327     $4,260    $6,390   
##  6 Mountain   Over Mountain      Jekyll           $5,275     $3,200    $7,990   
##  7 Mountain   Over Mountain      Trigger          $5,275     $3,200    $8,200   
##  8 Mountain   Cross Country Race F-Si             $5,070     $1,840    $11,190  
##  9 Mountain   Trail              Habit            $5,052     $1,950    $12,250  
## 10 Mountain   Cross Country Race Scalpel 29       $4,795     $3,200    $6,390   
## # ℹ 13 more rows

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.