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)
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