Question: Use R code answe just f , h , i , j Let's work on the mpg dataset in the package ggplot 2 . Use

Use R code answe just f, h, i, j Let's work on the mpg dataset in the package ggplot2. Use necessary code to read the description of the dataset, which contains 234 samples and 11 variables.
(a) Tum the variable cyl to an ordered factor variable with levels "4","5","6", and "8"
(b) Turn the variable trans to a factor variable, of which unique values are "auto" and "manu" (Hint: use the function substr ) to extract substrings in a character vector before converting to a factor vector)
(c) Tum the variable drv to an ordered factor variable with levels "f","r", and "4"
(d) Tum the variable fl to a factor variable, of which unique values are "gasoline", "diesel", and "other" (Hint, "other" should include "e" and "e" in the original variable: "e" for E85, which is an ethanol fuel blend of 85% ethanol fuel and 15% gasoline and "c" for compressed natural gas)
(e) Tum the variable class to an ordered factor variable with levels "2seater", "subcompact", "compact", "midsize", "suv", "minivan", and "pickup"
(f) Create a new variable of country to indicate the manufacturer base location (Hint: You can refer to the following tables)
\table[[Country,Manufacturer],[United States,Chevrolet, Dodge, Ford, Jeep, Lincoln, Mercury, Pontiac],[Japan,Honda, Nissan, Subaru, Toyota],[Germany,Audi, Volkswagen],[South Korea,Hyundai],[Great Britain,Land Rover]]
(g) Draw a bar plot of the variable country and arrange the country in decreasing order in terms of the number of samples. Which country has the most samples in this dataset? Which has the least?
(h) Summarize what a typical U.S. car looks like, in terms of engine displacement (i.e. disp1), number of cylinders (i.e. cy1), type of transmission (i.e. trans), drive type (i.e. drv), fuel type (i.e. fl), and type of car (i.e. class)?
(i) Make a boxplot of the combined miles per gatlon (i.e.(cty + hry)/2) of U.S. cars and Japan cars, respectively, and report their means, medians, standard deviations, and IQRs.
(i) Make a histogram of the engine displacement (L.e. dispI) of U.S. cars and Japan cars, respectively, and describe their shapes.
 Use R code answe just f, h, i, j Let's work

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!