Analyse the MPG data set.

Take the dataset mpg available in R for this analysis. The dataset has records of several car models from 1999 to 2000.

Table 1
Manufacturer Model Displ Year Cylinder Transmission Drive City Highway Fl Class
audi a4 1.8 1999 4 auto(l5) f 18 29 p compact
audi a4 1.8 1999 4 manual(m5) f 21 29 p compact
audi a4 2.0 2008 4 manual(m6) f 20 31 p compact
audi a4 2.0 2008 4 auto(av) f 21 30 p compact
audi a4 2.8 1999 6 auto(l5) f 16 26 p compact
audi a4 2.8 1999 6 manual(m5) f 18 26 p compact

The data set has 11 variables and 234 records. We want to see which class of vehicles give maximum mileage in city. Let’s plot a graph.

MPG
Data: mpg • Chart ID: MPGgoogleVis-0.6.2
R version 3.3.3 (2017-03-06) • Google Terms of UseDocumentation and Data Policy

So, who’s the winner?

Clearly subcompact class with four cylinders and manual transmisson gives the highest mileage within city. Let us first see how many cars fall into this category, and dig out the name of the winner!

Table 2
Manufacturer Model Displ Year Cylinder Transmission Drive City Highway Fl Class
honda civic 1.6 1999 4 manual(m5) f 28 33 r subcompact
honda civic 1.6 1999 4 auto(l4) f 24 32 r subcompact
honda civic 1.6 1999 4 manual(m5) f 25 32 r subcompact
honda civic 1.6 1999 4 manual(m5) f 23 29 p subcompact
honda civic 1.6 1999 4 auto(l4) f 24 32 r subcompact
honda civic 1.8 2008 4 manual(m5) f 26 34 r subcompact
honda civic 1.8 2008 4 auto(l5) f 25 36 r subcompact
honda civic 1.8 2008 4 auto(l5) f 24 36 c subcompact
honda civic 2.0 2008 4 manual(m6) f 21 29 p subcompact
hyundai tiburon 2.0 1999 4 auto(l4) f 19 26 r subcompact
hyundai tiburon 2.0 1999 4 manual(m5) f 19 29 r subcompact
hyundai tiburon 2.0 2008 4 manual(m5) f 20 28 r subcompact
hyundai tiburon 2.0 2008 4 auto(l4) f 20 27 r subcompact
subaru impreza awd 2.2 1999 4 auto(l4) 4 21 26 r subcompact
subaru impreza awd 2.2 1999 4 manual(m5) 4 19 26 r subcompact
subaru impreza awd 2.5 1999 4 manual(m5) 4 19 26 r subcompact
subaru impreza awd 2.5 1999 4 auto(l4) 4 19 26 r subcompact
volkswagen new beetle 1.9 1999 4 manual(m5) f 35 44 d subcompact
volkswagen new beetle 1.9 1999 4 auto(l4) f 29 41 d subcompact
volkswagen new beetle 2.0 1999 4 manual(m5) f 21 29 r subcompact
volkswagen new beetle 2.0 1999 4 auto(l4) f 19 26 r subcompact

Table 2 gives us the list of all the cars that have four cylinders in the subcompact class. And out of these contestants.

…And the winner is

1999 Volkswagen New Beetle !!!

Enjoy :)