Question: Exercise 1 Fill in the blanks to create three new variables named regular _ price, loyalty _ price, and coupon _ price according to the

Exercise 1
Fill in the blanks to create three new variables named regular_price, loyalty_price, and coupon_price
according to the following logic:
regular_price =(sales_value + retail_disc + coupon_match_disc)/ quantity
loyalty_price =(sales_value + coupon_match_disc)/ quantity
coupon_price =(sales_value - coupon_disc)/ quantity
... and then perform the following analyses:
1. Identify the five households with the largest loyalty_price transactions. What is unique about the
transaction with the largest loyalty_price value?
2. Now filter for only those observations where quantity was greater than 0. Now which household(s)
have the largest loyalty_price transaction?
3. Using the first transaction in the result from #2, filter the products data based on the product_id
to find out which product the largest loyalty_price transaction is associated with.
# Q0: Create three new variables named `regular_price`,`loyalty_price`, and
# `coupon_price` according to the logic shown above
transactions <- transactions %>%
mutate(
regular_price =____________,
loyalty_price =____________,
coupon_price =____________
)%>%
select(regular_price, loyalty_price, coupon_price, product_id, everything())
# Q1. Identify the five households with the largest `loyalty_price` transactions. What
# is unique about the transaction with the largest `loyalty_price` value?
transactions %>%
slice_max(order_by = loyalty_price, n =__)
# Q2. Now filter for only those observations where quantity was greater than 0. Now which
# household(s) have the largest `loyalty_price` transaction?
transactions %>%
filter(quantity __0)%>%
slice_max(order_by =______, n =__)
2
# Q3. Using the first transaction in the result from #2, filter the `products` data based
# on the `product_id` to find out which product the largest `loyalty_price` transaction
# is associated with.
products %>%
filter(product_id ==_______)
Exercise 2
transactions includes 20,902 unique product IDs. How many of these products (not transactions!) had a
regular price of one dollar or less? How many of these products had a loyalty price of one dollar or less?
How about a coupon price of one dollar or less?
Hint: After filtering, select the product_id column and count unique products using the n_distinct()
function.
# how many products had a regular price of $1 or less
transactions %>%
filter(regular_price <=__)%>%
select(product_id)%>%
n_distinct()
# how many products had a loyalty price of $1 or less
transactions %>%
filter(_________)%>%
select(product_id)%>%
_________
# how many products had a coupon price of $1 or less
transactions %>%
filter(_________)%>%
_________%>%
_________
Exercise 3
What proportion of baskets are over $10 in sales value? What proportion of baskets are over $20 in sales
value?
Hint: You need to use group_by() and summarize(). Depending on your approach you may or may not
use mutate().
# test your ability to right this code from scratch rather than just
# filling in the blanks :)
_______
Exercise 4
Which stores had the largest total sales_value (hint: sum(sales_value, na.rm = TRUE)? Which stores
had the largest average loyalty discount as defined below?
Hint: You can calculate loyalty discount as a percentage of regular price using the following logic:

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!