RPubs will retire in June 2027. Your existing documents will stay accessible through December 31, 2031
and Connect Cloud is the recommended home for new publishing. Read the blog post
gravatar

marioramajanantya

Mario Rama Janantya

Recently Published

Final Exam Mario Rama_112031152
Excercise week 12
Mid Terms
Publish Document
Publish Document
Document
Mario Rama Janantya
Mario Rama Janantya
Mid_Term_112031152_Mario Rama Janantya3
# Load libraries library(tidyverse) library(lubridate) #Number 1 #path_bike_orderlines <- "bike_orderlines.xlsx" # change to your path #import dataset from the table bikeorderlines and fix the errors bike_orderlines <- read_excel("bike_orderlines.xlsx") bike_orderlines <- bike_orderlines %>% 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 )) glimpse(bike_orderlines) #Number 2 #Sales by month bike_orderlines %>% select(order_date, total_price) %>% mutate(order_date = ymd(order_date)) %>% mutate(month = month(order_date, abbr = FALSE, label = TRUE)) %>% group_by(month) %>% summarize(sales = sum(total_price)) %>% ungroup() %>% mutate(month = month %>% as_factor(), sales = sales %>% scales::dollar(), month = month %>% str_to_title()) #Number 3 #Median Orderline #Evaluate “Black Inc”. What does this tell us about the “Black Inc” feature? bike_orderlines %>% select(model, total_price) %>% mutate(black = model %>% str_to_lower() %>% str_detect("black inc")) %>% group_by(black) %>% summarize(median = median(total_price)) %>% ungroup() %>% mutate(median = median %>% scales::dollar()) %>% rename(`Black Inc` = black, `Median Orderline` = median) #Evaluate “Ultegra”. What does this tell us about the “Ultegra” feature? bike_orderlines %>% select(model, total_price) %>% mutate(ultegra = model %>% str_to_lower() %>% str_detect("ultegra")) %>% group_by(ultegra) %>% summarize(median = median(total_price)) %>% ungroup() %>% mutate(median = median %>% scales::dollar()) %>% rename(`Ultegra` = ultegra, `Median Orderline` = median) #Evaluate “Disc” option. What does this tell us about the “Disc” feature? bike_orderlines %>% select(model, total_price) %>% mutate(disc = model %>% str_to_lower() %>% str_detect("disc")) %>% group_by(disc) %>% summarize(median = median(total_price)) %>% ungroup() %>% mutate(median = median %>% scales::dollar()) %>% rename(`Disc` = disc, `Median Orderline` = median) #Number 4 ## ‘summarise()‘ has grouped output by ’category_1’, ’category_2’. You can ## override using the ‘.groups‘ argument bike_orderlines %>% select(model, category_1, category_2, price) %>% separate(model, into = str_c("model_", 1:7), sep = " ", remove = T, fill = "right", extra = "drop") %>% mutate(model_base = case_when( # fix - supersix evo str_detect(str_to_lower(model_1), "supersix") ~ str_c(model_1, model_2, sep = " "), # fix - beast of the east str_detect(str_to_lower(model_1), "beast") ~ str_c(model_1, model_2, model_3, model_4, sep = " "), # fix - fat CAAD str_detect(str_to_lower(model_1), "fat") ~ str_c(model_1, model_2, sep = " "), # fix - bad habit str_detect(str_to_lower(model_1), "bad") ~ str_c(model_1, model_2, sep = " "), # fix - scalpel 29 str_detect(str_to_lower(model_2), "29") ~ str_c(model_1, model_2, sep = " "), # catch-all TRUE ~ model_1) ) %>% mutate(model_1 = model_1 %>% str_trim()) %>% select(category_1, category_2, model_base, price) %>% group_by(category_1, category_2,model_base) %>% summarize(mean = round(mean(price),0) %>% scales::dollar(), min = min(price) %>% scales::dollar(), max = max(price) %>% scales::dollar()) %>% ungroup() %>% arrange(desc(mean)) %>% rename( `Category 1` = category_1, `Category 2` = category_2, `Model Base` = model_base, `Mean Price` = mean, `Min Price` = min, `Max Price` = max )
hw_05_112031152
Publish Document
hw_2_112031152
Netflix Data Test