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:

summary(cars)
##      speed           dist       
##  Min.   : 4.0   Min.   :  2.00  
##  1st Qu.:12.0   1st Qu.: 26.00  
##  Median :15.0   Median : 36.00  
##  Mean   :15.4   Mean   : 42.98  
##  3rd Qu.:19.0   3rd Qu.: 56.00  
##  Max.   :25.0   Max.   :120.00

Including Plots

You can also embed plots, for example:

library(tidyverse)
library(dplyr)
library(lubridate)
library(stringr)
library(readxl)
bike <- read_excel("bike.xlsx")
bike<-bike%>%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
    ))
#1 highest month sale

bike$month<-format(as.Date(bike$order_date,format="%Y %m %d"),"%m")
bikes<-bike%>%select(total_price,month)
bikemonth<-bikes%>%group_by(month)%>%summarise(total_price)%>%group_by(month)%>%summarise_at(vars(total_price),funs(sum(.,na.rm=TRUE)))
install.packages("formattable")
library(formattable)
bikemonth$total_price<-currency(bikemonth$total_price,"$",digits = 0)
monthhigh<-bikemonth%>%slice_max(total_price)
monthhigh
## # A tibble: 1 × 2
##   month total_price
##   <chr> <formttbl> 
## 1 04    $8,386,170
#2 median by bike attribute
bikex<-bike%>%select(total_price,model)
bikemedian<-bikex%>%group_by(model)%>%summarise(total_price)%>%group_by(model)%>%summarise_at(vars(total_price),funs(sum(.,na.rm=TRUE)))
bikemedian$total_price<-currency(bikemedian$total_price,"$",digits = 0)
bikemed<-bikemedian%>%filter(total_price==median(total_price))
bikemed
## # A tibble: 1 × 2
##   model               total_price
##   <chr>               <formttbl> 
## 1 CAAD12 Disc Ultegra $649,040
#3 name
bikez<-bike%>%select(price,model,category_1,category_2)
bikebase<-bikez%>%group_by(model)%>%summarise(price)%>%group_by(model)%>%summarise_at(vars(price),funs(sum(.,na.rm=TRUE)))
bikebase$brand<-sub( " .*","",bikebase$model)
bikebase$count<-bikez%>%group_by(model)%>%count(price)
bikebass<-bikebase$count
bikebass$brand<-sub( " .*","",bikebass$model)
bikebasemax<-bikebass%>%group_by(brand)%>%summarise_at(vars(price),funs(max(.,na.rm=TRUE)))
bikebasemax
## # A tibble: 17 × 2
##    brand      price
##    <chr>      <dbl>
##  1 Bad         3200
##  2 Beast       2770
##  3 CAAD12      5860
##  4 CAAD8       1410
##  5 Catalyst     705
##  6 F-Si       11190
##  7 Fat         3730
##  8 Habit      12250
##  9 Jekyll      7990
## 10 Scalpel     6390
## 11 Scalpel-Si 12790
## 12 Slice       7000
## 13 Supersix   12790
## 14 SuperX      3500
## 15 Synapse     9590
## 16 Trail       1520
## 17 Trigger     8200
bikebasemin<-bikebass%>%group_by(brand)%>%summarise_at(vars(price),funs(min(.,na.rm=TRUE)))
bikebasemin
## # A tibble: 17 × 2
##    brand      price
##    <chr>      <dbl>
##  1 Bad         2660
##  2 Beast       1620
##  3 CAAD12      1680
##  4 CAAD8        815
##  5 Catalyst     415
##  6 F-Si        1840
##  7 Fat         2130
##  8 Habit       1950
##  9 Jekyll      3200
## 10 Scalpel     3200
## 11 Scalpel-Si  3200
## 12 Slice       1950
## 13 Supersix    1840
## 14 SuperX      1750
## 15 Synapse      870
## 16 Trail        815
## 17 Trigger     3200
bikebaseaverage<-bikebass%>%group_by(brand)%>%summarise(Mean=mean(price))
bikebaseaverage%>%arrange(desc(Mean),brand)
## # A tibble: 17 × 2
##    brand       Mean
##    <chr>      <dbl>
##  1 Scalpel-Si 6927.
##  2 Supersix   5491 
##  3 Jekyll     5275 
##  4 Trigger    5275 
##  5 F-Si       5070 
##  6 Habit      5052.
##  7 Scalpel    4795 
##  8 Slice      3870 
##  9 Synapse    3514.
## 10 CAAD12     3121.
## 11 Bad        2930 
## 12 Fat        2930 
## 13 SuperX     2415 
## 14 Beast      2173.
## 15 Trail      1149 
## 16 CAAD8      1126.
## 17 Catalyst    546.

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