1. Using the built-in dataset mtcars in R, perform the following tasks. (Run ?mt
ID: 3062627 • Letter: 1
Question
1. Using the built-in dataset mtcars in R, perform the following tasks. (Run ?mtcars to get the data set description.) (A) Create a new data set called mycars that only includes mpg, hp, wt, and am. Replace the am column (transmission type) with a column called transmission with entries "automatic" or "manual". Define transmission as a factor with the appropriate labels Rename the wt column and call it weight. In other words, clean and relabel data. (Use the dataset mycars in the following questions.) (B) Create histograms of the variables mpg, hp, and weight. Using the par function, give a single plot that contains all of the histograms. Label the histograms appropriately (add clear x-and y-labels, and a title). Use the breaks= to control the number of bins in the histograms (C) Provide summary statistics for the variables in the dataset mycars. Provide also sum mary statistics by transmission typcExplanation / Answer
>library(datasets)
>head(mtcars)
>mycars<-mtcars[,c("mpg","hp","wt","am")]
>mycars<-plyr::rename(mycars,c(mpg="Miles/gallon",hp="Gross_horsepower",wt="weight",am="Transmission"))
>mycars$Transmission[mycars$Transmission==1]<-"automatic"
>mycars$Transmission[mycars$Transmission==0]<-"manual"
>hist(mycars$`Miles/gallon`)
>hist(mycars$Gross_horsepower)
>hist(mycars$weight)
>par(mfcol=c(3,3))
>hist(mycars$`Miles/gallon`,xlab="Miles/gallon",,breaks = 10,main = "Histogram of Miles/gallon")
>hist(mycars$Gross_horsepower,xlab = "Gross_horsepower",breaks = 5,main = "Histogram of Gross_horsepower")
>hist(mycars$weight,xlab = "weight",breaks = 2, main = "Histogram of Weight")
>summary(mycars)
>mycars_manual<-mycars[which(mycars$Transmission=="manual"),]
>summary(mycars_manual)
>mycars_automatic<-mycars[which(mycars$Transmission=="automatic"),]
>summary(mycars_automatic)
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.