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.
Place this order or similar order and get an amazing discount. USE Discount code βGET20β for 20% discount