The MASS package contains the Cars93 dataset. (a) Load the MASS package and stor
ID: 3358360 • Letter: T
Question
The MASS package contains the Cars93 dataset.
(a) Load the MASS package and store a copy of Cars93 in your workspace. How many cars are in the
sample? How many variables are in the dataset?
(b) The midrange price variable Price can be extracted using the abbreviated command Cars93$Pri. If we try to extract the manufacturer variable using the Cars93$Man command, why does this return NULL? Use a correct command to find the number of manufacturers represented in the data.
(c) Produce frequency and relative frequency tables to determine what is the most typical number of cylinders among the cars in the data. What percentage of cars in the data have the most typical number of cylinders?
(d) Among the cars with 4 cylinders, what is the average (mean) highway mileage (miles per gallon)? How does this compare with the average highway mileage among cars with 6 cylinders?
Explanation / Answer
a)
library(MASS)
data=Cars93
write.csv(data,"cars93.csv")
ncol(data)#27 columns
nrow(data)#93 rows
#There are 27 columns i.e. 27 variables in the dataset.
#There are 93 rows i.e. 93 cars in the dataset.
b)
data$Pri #extracting the midrange price column.
data$Manu #Extracting the manufacturer column.
#data$Man This command doesn't work because there is a variable named Man.trans.avail.
#When we try to extract by data$Man, it has two options i.e. not unique.
#Number of Manufacturers
length(unique(data$Manu)) #32 manufacturers
c)cylinders.freq=table(data$Cylinders)
rel.freq=cylinders.freq/nrow(data)
cbind(cylinders.freq,rel.freq)
cylinders.freq rel.freq
3 3 0.03225806
4 49 0.52688172
5 2 0.02150538
6 31 0.33333333
8 7 0.07526882
rotary 1 0.01075269
Most typical number of cylinders used in this car is 4. Around 53% of the cars use 4 cylinders.
d)Among the cars with 4 cylinders average highway mileage is 31.45 miles per galon.
cylinder4=data[data$Cylinders==4,]
mean(cylinder4$MPG.highway)
Among the cars with 6 cylinders average highway mileage is 25.33 miles per galon.
cylinder6=data[data$Cylinders==6,]
mean(cylinder6$MPG.highway)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.