22 Chipotle Functions
Readings
Guided Instruction
You got your dream job working as a data analyst for one of your favorite restaurants, Chipotle!
- What is Chipotle
- Say what?!. Ask Brother Woodruff how he pronounces it :).
Chipotle is planning to run a large 1 or 2 day promotion. They would like the promotion to take place when the restaurant is busiest. They have gathered restaurant level data that you can use to answer the question: what is the busiest day in the restaurant?
We will answer this question over the course of a couple of assignments. For now, we will build a couple of functions that help us evaluate one restaurant site at a time.
The data contains a column popularity_by_day
. This column contains a lot of information we need to extract from a string. As an example, for the restaurant with placekey
equal to “zzw-222@5vg-nwf-mp9”, the value for popularity_by_day
is a string:
{“Monday”:94,“Tuesday”:76,“Wednesday”:89,“Thursday”:106,“Friday”:130,“Saturday”:128,“Sunday”:58}
- Using the string above as a test case, or example, implement your regex/string skills to split the string and ]convert it into a tibble with two columns: day of week and number of visits. You should get a tibble that looks like something like this:
day | visits |
---|---|
Monday | 94 |
Tuesday | 76 |
Wednesday | 89 |
Thursday | 106 |
Friday | 130 |
Saturday | 128 |
Sunday | 58 |
Use what you developed above to create 2 functions. Both functions should take as input a character string, like the one provided in bullet point 1, which contains a count of visits by day of the week. The 2 functions will differ in what they return:
- Function 1 should return a dataframe (or tibble to be more precise) that contains the name of each day of the week in one column and the number of visits at that store in the other column (i.e. just as is pictured in bullet point 1)
- Function 2 should build on Function 1 and take it a step further. Namely, it should return the most popular day of the week (in terms of visits) at that store (or a comma separated string if there are ties).
Verify your functions are working by checking their output on the following 3 strings:
Test Case 1
Feed the functions this string:
{“Monday”:94,“Tuesday”:76,“Wednesday”:89,“Thursday”:106,“Friday”:130,“Saturday”:128,“Sunday”:58}
Note: This string is contained in the popularity_by_day
column in the row for placekey
equal to “zzw-222@5vg-nwf-mp9”.
Function 1 output return a tibble like this:
day | visits |
---|---|
Monday | 94 |
Tuesday | 76 |
Wednesday | 89 |
Thursday | 106 |
Friday | 130 |
Saturday | 128 |
Sunday | 58 |
Function 2 should return “Friday”.
Test Case 2
Feed the functions this string:
{“Monday”:18,“Tuesday”:16,“Wednesday”:14,“Thursday”:27,“Friday”:26,“Saturday”:36,“Sunday”:20}
Note: This string is contained in the popularity_by_day
column in the row for placekey
equal to “22c-222@5z5-3rs-hwk”.
Function 1 output return a tibble like this:
day | visits |
---|---|
Monday | 18 |
Tuesday | 16 |
Wednesday | 14 |
Thursday | 27 |
Friday | 26 |
Saturday | 36 |
Sunday | 20 |
Function 2 should return “Saturday”.
Test Case 3
Feed the functions this string:
{“Monday”:0,“Tuesday”:0,“Wednesday”:1,“Thursday”:0,“Friday”:0,“Saturday”:1,“Sunday”:0}
Note: This string is contained in the popularity_by_day
column in the row for placekey
equal to “zzw-223@5r8-fqv-xkf”.
Function 1 output should a tibble like this:
day | visits |
---|---|
Monday | 0 |
Tuesday | 0 |
Wednesday | 1 |
Thursday | 0 |
Friday | 0 |
Saturday | 1 |
Sunday | 0 |
Function 2 should return “Wednesday, Saturday”.
We will worry about expanding the function to multiple sites or rows in the next task. For now the input is just one string.
- Render your
.qmd
and push your.rds
data file,.qmd
,.md
and.html
file into your GitHub repository.
Submit
In I-learn submit a link to the `.md` file on GitHub.