versionprint(.packages())
Problem Set 3: Data Processing with R
Link to the description of the supermarket sales data available in the Supermarket Sales Data Overview.
Write an R script to complete the following tasks:
Read in the dataset
supermarket_sales.csv
usingread_csv()
. Note: What packages do you need to have installed before loading in the data using this command?Calculate the total value of the sale using the
unit_price
andquantity
columns. Name the new column (variable)subtotal
. Then verify that the value labeledtax_5_percent
is indeed 5% of thesubtotal
by creating a new variable calledtax_verify
. Assign the object to a new dataframe.Create a dataframe containing only the subset of sales from the product line
Food and beverages
.Create a dataframe containing only the columns
city, product_line, unit_price, quantity, total, rating
where the product line isFood and beverages
.Sort the dataframe by
quantity
in descending order.Load the
dplyr
package and use the appropriate commands to calculate the median sales by payment type.Suppose you are asked to develop a new performance indicator for the company. You wonder if the transaction
rating
perunit price
might provide insights into consumer preferences for different product lines. Calculate the rating per unit price for each transaction and call this new variablerup
. Explain what this performance indicator might tell decision-makers at the company.Calculate the mean
rup
andunit price
by product line.Print the contents of this dataframe into the console using the
print()
function. What conclusions do you draw from your analysis? Explain.Include the following lines of code to ensure that you have loaded all the necessary packages for this assignment:
- Generate a log file from your script to show that it ran successfully in R. Use the
sink()
command to capture both the code and its output. Here is a hint for the structure of your script:
sink("problem_set_3.log") # Start capturing output
source("problem_set_3.R", echo = TRUE) # Run your script and show commands + output
sink() # Stop capturing output
How to Submit
- Create a Webpage on Your Google Site:
- Title the new webpage Problem Set 3.
- This page should contain an R script log file that responds to all questions of the problem set.
- Submit the Link to Your Google Site Page:
- Copy the URL of your Google Site webpage for Problem Set 3.
- Submit this link via Canvas.