F23_6359_HW1_Avanti_Sethi

rtf

School

University of Texas, Dallas *

*We aren’t endorsed by this school

Course

6359

Subject

Industrial Engineering

Date

Jan 9, 2024

Type

rtf

Pages

4

Uploaded by MateToadPerson1001

Report
# Clear the environment rm(list = ls()) # your info (NetID_LastName_FirstName); write to Console name1 <- "MJS230000_Seelam_Monish"; name1 # Assign dir1 to the folder on your computer where this excel file (HW1) is. dir1 <- getwd() dir1 # set the working directory to dir1 setwd(dir1) # Copy and paste this command into your R file. Keep it as a comment. # setwd("C:/Users/kusum/OneDrive/Documents/TA - 6359") # load readxl library, if needs to be installed, once the package is installed, make it a comment by adding # library(readxl) # read this excel file (sheet = Pioneer). Do not include the file path here, only the file name table <- read_excel("HW1-6359-F23.xlsx", sheet="Pioneer") # rename the Units column to Quantity names(table) [names(table) == "Units"] <- "Quantity" names(table) # Create a new vector Sales which is Quantity x Price table$Sales <- table$Quantity * table$Price # Create a new vector Commission which is 15% of the total sales table$Commission <- 0.15 * table$Sales # add the new vectors to the excel file. This will create two new columns. #install.packages('openxlsx') library(openxlsx) write.xlsx(table, "HW1-6359-F23.xlsx", sheetName = "Pioneer", append = TRUE) head(table) # Create output file name using name1. All your output will go to this file. csvfile <- paste(name1,"_HW1.csv",sep="") csvfile
# send the output to the csv file you just created sink(csvfile) # Use the cat function to write your name (First Last). This must be Row 1 of your CSV file. cat("NAME", sep = "," , "Monish Seelam", "\n") # Use cat function to write your netid. This must be Row 2 of csv file. cat("NETID" , sep = "," , "MJS230000", "\n") # write the length of the 1st column. This must be Row 3 of csv file. len1 <- length(table$`Date Sold`) cat("LENGTH" , sep = "," , len1, "\n") # Like above, calculate and print the following values along with the labels (as shown above for length) to the cvs file (in the order given below) # Average Sales avg_sales <- mean(table$Sales) cat("AVERAGE SALES" , sep = "," ,avg_sales, "\n") # Median Sales med_sales <- median(table$Sales) cat("MEDIAN SALES", sep = ",", med_sales, "\n") #Total quantity total_quantity <- sum(table$Quantity) cat("TOTAL QUANTITY", sep = ",", total_quantity, "\n" ) #Total commission total_commission <- sum(table$Commission) cat("TOTAL COMMISSION", sep = ",", total_commission, "\n") #Average commission avg_commission <- mean(table$Commission) cat("AVERAGE COMMISSION", sep = ",", avg_commission, "\n") # How many invoices (records) have 30 or more units? invoice_30_or_more <- sum(table$Quantity >= 30) cat("NUMBER OF INVOICES (RECORDS) THAT HAVE 30 OR MORE UNITS", sep = ",", invoice_30_or_more, "\n") # Total sales value of Skirts sold library(dplyr) skirts_data <- table[table$Product == "Skirt", ] total_sales_value_skirts <- sum(skirts_data$Sales)
cat("TOTAL SALES VALUE OF SKIRTS SOLD", sep = ",", total_sales_value_skirts, "\n") # Total quantity of T-shirts sold in Dallas tshirts_dallas_data <- table[table$Product == "T-Shirt" & table$City == "Dallas", ] total_quantity_tshirts_dallas <- sum(tshirts_dallas_data$Quantity) cat("TOTAL QUANTITY OF T-SHIRTS SOLD IN DALLAS", sep = ",", total_quantity_tshirts_dallas$TotalQuantity, "\n") # create a divider line. This must be Row 12 of csv file. Copy and Paste this Command cat("--------------------------------", "\n") cat("--------------------------------", "\n") # For the Sales data (assume the data to be a sample) # Find the following and write using cat function (as done above; see also the output) # Mean mean_sales <- mean(table$Sales) cat("MEAN SALES", sep = ",", mean_sales, "\n") # Median median_sales <- median(table$Sales) cat("MEDIAN SALES", sep = ",", median_sales, "\n") # Standard deviation std_dev_sales <- sd(table$Sales) cat("STANDARD DEVIATION OF SALES", sep = ",", std_dev_sales, "\n") # Skewness (Package moments should be installed) #install.packages('moments') library(moments) skewness_sales <- skewness(table$Sales, na.rm = TRUE) cat("SKEWNESS OF SALES", sep = ",", skewness_sales, "\n") # Lower cut-off using 2-sigma approach sigma <- 2 lower_cutoff <- mean_sales - (sigma * std_dev_sales) cat("LOWER CUTOFF (2 SIGMA APPROACH) FOR SALES", sep = ",", lower_cutoff, "\n") # Upper cut-off using 2-sigma approach upper_cutoff <- mean_sales + (sigma * std_dev_sales) cat("UPPER CUTOFF (2 SIGMA APPROACH) FOR SALES", sep = ",", upper_cutoff, "\n") # Plot a Histogram of the price price_data <- as.numeric(sub("\\$", "", table$Price))
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
hist(price_data, main = "Price Histogram", xlab = "Price", ylab = "Frequency", col = "lightblue") # Plot a BoxPlot of the Sales sales_data <- as.numeric(sub("\\$", "", table$Sales)) boxplot(sales_data, main = "Sales Boxplot", ylab = "Sales", col = "lightblue")