R
R
#----------
##1.a. Create a matrix A of integers order (4,5)
##1.g. Write a function which will take the row number r and column number c
and will return the minor of the matrix Mrc
#Exercise 2
#----------
##2.a. Load the datasets mtcars_1.csv and mtcars_2.csv
##2.c. Assume the first word of the name represents the company (e.g. Mazda)
and the second word represents the make (e.g. RX4). Create two columns for the
company and make
##2.d. For cars which do not have two words change the name of the make to
'make0'
#The previous command can be corrected to provide 'make0' instead of NA
##2.e. For each of the companies find the average mileage and horsepower
##2.f. Across all cars plot the mileage against the horsepower
##2.g. Plot the displacement vs. mpg split by number of gears and if the
displacement is automatic or manual
#1
typeof(USPersonalExpenditure)
#2
p <- USPersonalExpenditure[5,]
count<-length(p[])
g<- 1:4
pc<-1:4
count
for(i in 1:count-1){
g[i] <- p[i+1]-p[i]
pc[i] <- (g[i]/p[i])*100
}
g[]
pc[]
#3
mx<-rowSums(USPersonalExpenditure)
mx[]
sum_mx<-sum(mx[])
percent_share<-(mx/sum_mx)*100
max(percent_share)
#4
plot(colnames(USPersonalExpenditure),USPersonalExpenditure[1,1:5],xlab =
'Years',ylab = 'Expenditure')
#5