library(“Hmisc”)

#1)Create two matrices and name them as Matrix 1 & 2 and display all the discounts in matrix 1 with the corresponding dimension names. s=c(600, 1200, 1800, 2100, 2400, 2700, 3000, 3300, 3600) Matrix1=matrix(s,nrow=3,ncol=3) Matrix1

#2)Three more customers got added to the premium customers in matrix 1. Update the matrix to reflect the discount cost of the bill. Append three more discount cost in the matrix 1. Matrix1=rbind(Matrix1,c(1900,2900,3900)) Matrix1

#3)Display the mean of the row 3 of matrix 1 after appending the discounts given to the new three premium customers. mean(Matrix1[3,c(1:3)])

F=as.Date(Sys.time())

#4)The discount is given only in the particular week of the month, say the last week of the September 2022, generate the sequence of dates for the last week and display the same. A= monthDays(F)
B=A A=A-6; print(“The Discount are available in(days of given month):”) for(i in A:B) { print(i) }

#5)The CEO of Retail chain of hypermarket intended to give this discount by selecting the customers every three months, as there was a huge response and impact in sales. Every three months starting from the September 2022 to December 2023, the last week of month is marked for the sales discount. Display the starting day of discount sales with ‘R’ dates like for example 23.09.2022, 25.12.2022, 25.03,2023, 24.06.2023, 23.09.2023. E=as.Date(“2022-09-19”) print(“The following Dates which are Starting our Discount are:”) print(paste(“The starting date of sale is”,E)) for(i in 1:4) { E=E+90 print(paste(“The starting date of sale is”,E)) }

#2

#Include a new team “Green” with the score (10,10,30,30,40). Sports=c(“Football”,‘Cricket’,‘Throwball’,‘Badminton’,“Track and Field”) Orange=c(50,25,19,30,23) Yellow=c(0,20,25,43,21) Blue=c(20,45,26,21,0) df=data.frame(Sports,Orange,Yellow,Blue)

#Display the scores of Football and Throw ball events. df$Green=c(10,10,30,30,40)

A=sum(df[‘Orange’]) B=sum(df[‘Yellow’]) C=sum(df[‘Blue’]) D=sum(df[‘Green’]) t=c(“TotalMarks”,A,B,C) df[nrow(df) + 1,] <- c(“TotalMarks”,A,B,C,D)

#Find the total points scored by each team and bind the total score with the data set. L=c(A,B,C,D) G=which.max(L)

#Display the name of the winning team. print(paste(“The winner is”,names(df)[G+1],“team”))

#Find the least points scored by Orange Team and Blue Team. a=min(df[c(1:5),2]) print(paste(“The least score by Orange is:”,a)) b=min(df[c(1:5),3]) print(paste(“The least score by Blue is:”,b))

#Display the favourable game of Yellow Team and Green Team. print(paste(“My favorable game of Yellow and green team is”,df[3,c(1,3,5)],” and “,df[5,c(1,3,5)]))

#Display the average score of each event with the corresponding sports name. Avg=rowSums(stu[c(1,2,3,4,5), c(2,3,4,5)])/4 Sports=c(df[1,1],df[2,1],df[3,1],df[4,1],df[5,1]) b=data.frame(Sports,Avg) b

#3

#Present the R command to find and print the data types for each of the column attributes Register Number, Name, Result Register_no=c(1,2,3,4) Name=c(‘A’,‘B’,‘C’,‘D’) Result=c(‘P’,‘P’,‘F’,‘A’) dg=data.frame(Register_no,Name,Result)

#Give the R command using appropriate method to find whether a column belongs to a particular data type or not. Check for all the columns class(dg[,1]) class(dg[,2]) class(df[,3])

#Give the R command for converting Register number attribute to character data type using appropriate method. str(dg) dg\(Register_no=as.character(dg\)Register_no) str(dg)

#Convert the following raw data to character data using the inbuilt method. #X= 20 68 69 20 77 65 6c 63 6f 6d 65
X=c(20,68,69 ,20 ,77 ,65 ,‘6c’ ,63 ,‘6f’ ,‘6d’ ,65) transform(X,as.numeric(X)) class(X) X

#Give the R command for creating integer value 2 and assign to a variable x, using in-built method and without using in-built method x=as.integer(4.6) x x=2L x

#4 #A

#Create the above Matrix and display the matrix
A=c(“Sachin”,“Virat”,“Rohit”,“Dhoni”) B=c(“Amithab”,“Amir”,“Akshya”,“Salman”) C=c(“Modi”,“Amit”,“Rahul”,“Neheru”) D=c(“Delhi”,“Chennai”,“kolkata”,“Mumbai”) Stars=matrix(c(A,B,C,D),nrow=4,ncol=4)

#Define the column names as Players, Actors, Politicians, Metro city
colnames(Stars)=c(“Players”,“actors”,“Politician”,“MetroCity”)

#Define the row names as Record1, Record2, Record3, Record4
rownames(Stars)=c(“Record1”,“Record2”,“Record3”,“Record4”)

#Display only the names of cricket players and Politicians
Stars[,c(1,3)]

#Display the records that contain Kolkata and Mumbai
Stars[c(3,4),]

#B

#Display the given string in date format
Date=as.Date(“2022-08-08”) Date

#Extract from the date object, the day number in that year, for example, 8/25/2022 is 237th day in this year.
doy = strftime(Date, format = “%j”) doy

#Extract from the date object, the month number in that year. For example, 08/25/2022 has the month number 08.
A=format(Date,“Month is %m”) A

#Convert the following dates which are in string format to date format #“12/11/2010”, “13/12/1990”,”30/1/2001” and “15/08/2022” and display the dates on the console.

Dates=c(as.Date(“2010-11-12”),as.Date(“1990-12-13”),as.Date(“2001-01-30”), as.Date(“2022-08-15”)) print(Dates)

#Extract two dates “30/01/2001” and “12/11/2010” from the above created object #and calculate the difference between the given dates in terms of days and months and display the results. p=c() y=1 for(i in 1:4) { if(Dates[[i]]==“2001-01-30”) { p[y]=i y=y+1 }

if(Dates[[i]]==“2010-11-12”) { p[y]=i y=y+1 } }

diff_dates = difftime(“2001-01-30”,“2010-11-12”, units = “days”) S=length(seq(from=as.Date(“2001-01-30”), to=as.Date(“2010-11-12”), by=‘month’)) - 1

#5

#Make five simple numeric vectors for the above data and join the vectors together to form a data frame. Virat=c(12,6,0,14,3) Susan=c(6,6,9,0,12) Anwar=c(1,4,3,2,0) Patel=c(9,6,4,2,8) Kapil=c(6,6,6,4,3)

data1 <- data.frame(x1 = numeric(),
x2 = numeric(), x3 = numeric(), x4 = numeric(), x5 = numeric(), stringsAsFactors = FALSE) data1

data1[1, ] = Virat data1[2,]=Susan data1[3,]= Anwar data1[4,]=Patel data1[5,]=Kapil rownames(data1)=c(“Virat”,“Susan”,“Anwar”,“Patel”,“Kapil”) data1

#Each row depicts the runs scored by the player in each round. Assign column names such as round 1, round 2,…..round 5 colnames(data1)=c(“Round1”,“Round2”,“Round3”,“Round4”,“Round5”) data1

#Display the data corresponding to round 5 data1[c(1:5),5]

#Calculate the highest score gained by the players in all rounds by adding a column named total. Total=c(sum(data1[1,c(1:4)]),sum(data1[2,c(1:4)]),sum(data1[3,c(1:4)]), sum(data1[4,c(1:4)]),sum(data1[4,c(1:4)])) data1$total=cbind(Total) data1

#Display the tuple of record for the user who secured the highest score) V=which.max(data1[,6])

print(paste(“The Tuple of record who scored the highest is:”)) print(data1[V,c(1:6)])

Sys.time()