Created
August 16, 2018 18:08
-
-
Save jthomasmock/fb9f16abe58e73d98f75e012e17ab49e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#week 21 | |
library(tidyverse) | |
url <- "https://raw.githubusercontent.com/TheUpshot/chipotle/master/orders.tsv" | |
df <- read_tsv(url) | |
tidy_df <- df %>% | |
separate(choice_description, c("Filling 1", "Filling 2", "Filling 3", "Filling 4", "Filling 5", "Filling 6", | |
"Filling 7", "Filling 8", "Filling 9", "Filling 10"), | |
extra = "merge", | |
fill = "right", | |
sep = ",") %>% | |
mutate(`Meal item` = case_when(str_detect(tolower(item_name), "burrito|bowl|salad|taco") ~ item_name, | |
TRUE ~ NA_character_)) %>% | |
select(order_id:item_name, item_price, `Meal item`, everything()) %>% | |
gather(key = "ingredient_number", value = "ingredient", `Meal item`:`Filling 10`) %>% | |
mutate( | |
#ingredient_number = case_when(str_detect(tolower(item_name), "burrito|bowl|salad|taco") ~ ingredient_number, | |
# TRUE ~ str_extract(ingredient_number, "[:digit:]+")), | |
ingredient = str_remove_all(ingredient, "\\[|\\]"), | |
chips = case_when(str_detect(item_name, "Chips and") ~ item_name, | |
TRUE ~ "NOPE"), | |
ingredient = case_when(ingredient == "NULL" ~ chips, | |
TRUE ~ ingredient), | |
ingredient = case_when(ingredient == "NOPE" ~ item_name, | |
TRUE ~ ingredient)) %>% | |
select(-chips) %>% | |
na.omit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment