Requirements
This lab assignment has two parts, each asking you to define a function in R that solves
a specific business problem. Each part is worth 5 points with a total of 10 points. The detailed
requirements are listed below.
Part 1: Inventory replenishment
In your RStudio interface, open a new R Script window. (Check Lesson 1.2.4 for
instructions on running R scripts.) Define an R function named unit() that calculates the
number of weekly units that Mary Fresh needs for a particular product to replenish her inventory
with the following three arguments:
• sales: the annual sales revenue of the product (required)
• unit_cost: the per-unit cost of the product (required)
• profit: the profit margin (optional with the default value of 0.05)
The number of units is calculated by: 𝑢𝑛𝑖𝑡 = 𝑠𝑎𝑙𝑒𝑠 ∗ (1 − 𝑝𝑟𝑜𝑓𝑖𝑡)/(𝑢𝑛𝑖𝑡_𝑐𝑜𝑠𝑡 ∗ 52).
Please make sure your function rounds any decimal answers to the nearest whole number.
Execute your codes to define the function. Write an R statement in your script window to test it
using sales = 10000 and unit_cost = 15.5. Your function should return 12.
Save your script file as Lab6FirstNameLastName.R to your computer (or to your U:
drive if you are using the Foster Remote Lab).
Part 2: Ad revenue
In the same R Script window, define a new function named revenue() that calculates
the annual revenue that a YouTuber makes with the following five arguments:
• videos: the number of videos the YouTuber publishes in a year (required)
• views: the average number of views for each video (required)
2
• conversion: the conversion rate, i.e., the percentage of views that generate
impressions (optional with the default value of 1)
• CPM: YouTube’s CPM (optional with the default value of 8.50)
• commission: YouTube’s commission rate (optional with the default value of 0.45)
Where 𝑟𝑒𝑣𝑒𝑛𝑢𝑒 = 𝑣𝑖𝑑𝑒𝑜𝑠 ∗ 𝑣𝑖𝑒𝑤𝑠 ∗ 𝑐𝑜𝑛𝑣𝑒𝑟𝑠𝑖𝑜𝑛 ∗ (𝐶𝑃𝑀/1000) ∗ (1 − 𝑐𝑜𝑚𝑚𝑖𝑠𝑠𝑖𝑜𝑛).
Please round the return result to the nearest hundredth.
Execute your code to define the function. Write an R statement in your script window to
test it using videos = 48, views = 21300. Your function should return 4779.72. Save your work.
Your file should include both the functions and the test statements.
Requirements This lab assignment has two parts, each asking you to define a func
By admin