library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.1 ✔ stringr 1.5.1
## ✔ ggplot2 4.0.0 ✔ tibble 3.3.0
## ✔ lubridate 1.9.4 ✔ tidyr 1.3.1
## ✔ purrr 1.1.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(dplyr)
library(lubridate)
library(zoo)
##
## Attaching package: 'zoo'
##
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
library(forcats)
library(ggplot2)
epa2021 <- read.csv("epa2021.csv")
The dataset epa2021, is a set of information of statistics and details about cars of different brands, engine types, asipiration methods, and fuel consumptions, gathered by the EPA (Environmental Protection Agency) in 2021. The dataset displays a count of numerous cars and each of their statistics and how it could influence the environment through its emissions. Specific variables of the dataset will be examined to gather the information of each car’s fuel consumption and based information of a car such as its brand name and type of vehicle. Thus leading to the question, what is the range of miles per gallon (MPG) of all cars of different numbers of cylinders in its engine and which car has the best fuel efficiency?
Key variables: - division: The car company which the car has been designted as. - carline: The type of car. - no_cylinders: The number of cylinders a car’s engine contains. - engine_displacement: The car’s engine displacement in liters. - city_mpg: A car’s gas mileage in the city. - hwy_mpg: A car’s gas mileage on the highway. - comb_mpg: The average gas mileage of a car taking city and highway MPG’s divided by two.
str(epa2021)
## 'data.frame': 1108 obs. of 28 variables:
## $ model_yr : int 2021 2021 2021 2021 2021 2021 2021 2021 2021 2021 ...
## $ mfr_name : chr "Honda" "aston martin" "aston martin" "Volkswagen Group of" ...
## $ division : chr "Acura" "Aston Martin Lagonda Ltd" "Aston Martin Lagonda Ltd" "Audi" ...
## $ carline : chr "NSX" "Vantage Manual" "Vantage V8" "R8" ...
## $ mfr_code : chr "HNX" "ASX" "ASX" "VGA" ...
## $ model_type_index : int 39 5 4 5 7 6 8 73 352 350 ...
## $ engine_displacement : num 3.5 4 4 5.2 5.2 5.2 5.2 2 3 2 ...
## $ no_cylinders : int 6 8 8 10 10 10 10 4 6 4 ...
## $ transmission_speed : chr "Auto(AM-S9)" "Manual(M7)" "Auto(S8)" "Auto(AM-S7)" ...
## $ city_mpg : int 21 14 18 13 14 13 14 23 22 25 ...
## $ hwy_mpg : int 22 21 24 20 23 20 23 31 30 32 ...
## $ comb_mpg : int NA 17 20 16 17 16 17 26 25 28 ...
## $ guzzler : chr "N" "N" "N" "Y" ...
## $ air_aspir_method : chr "TC" "TC" "TC" NA ...
## $ air_aspir_method_desc: chr "Turbocharged" "Turbocharged" "Turbocharged" "Naturally Aspirated" ...
## $ transmission : chr "AMS" "M" "SA" "AMS" ...
## $ transmission_desc : chr "Automated Manual- Selectable (e.g. Automated Manual with paddles)" "Manual" "Semi-Automatic" "Automated Manual- Selectable (e.g. Automated Manual with paddles)" ...
## $ no_gears : int 9 7 8 7 7 7 7 7 8 8 ...
## $ trans_lockup : chr "Y" "N" "Y" "N" ...
## $ trans_creeper_gear : chr "N" "N" "N" "N" ...
## $ drive_sys : chr "A" "R" "R" "A" ...
## $ drive_desc : chr "All Wheel Drive" "2-Wheel Drive, Rear" "2-Wheel Drive, Rear" "All Wheel Drive" ...
## $ fuel_usage : chr "GPR" "GP" "GP" "GPR" ...
## $ fuel_usage_desc : chr "Gasoline (Premium Unleaded Required)" "Gasoline (Premium Unleaded Recommended)" "Gasoline (Premium Unleaded Recommended)" "Gasoline (Premium Unleaded Required)" ...
## $ class : chr "Two Seaters" "Two Seaters" "Two Seaters" "Two Seaters" ...
## $ car_truck : chr "car" "car" "car" "car" ...
## $ release_date : chr "2021-02-01T00:00:00Z" "2020-08-10T00:00:00Z" "2020-08-10T00:00:00Z" "2020-06-30T00:00:00Z" ...
## $ fuel_cell : chr "N" "N" "N" "N" ...
head(epa2021)
## model_yr mfr_name division carline mfr_code
## 1 2021 Honda Acura NSX HNX
## 2 2021 aston martin Aston Martin Lagonda Ltd Vantage Manual ASX
## 3 2021 aston martin Aston Martin Lagonda Ltd Vantage V8 ASX
## 4 2021 Volkswagen Group of Audi R8 VGA
## 5 2021 Volkswagen Group of Audi R8 2WD VGA
## 6 2021 Volkswagen Group of Audi R8 Spyder VGA
## model_type_index engine_displacement no_cylinders transmission_speed city_mpg
## 1 39 3.5 6 Auto(AM-S9) 21
## 2 5 4.0 8 Manual(M7) 14
## 3 4 4.0 8 Auto(S8) 18
## 4 5 5.2 10 Auto(AM-S7) 13
## 5 7 5.2 10 Auto(AM-S7) 14
## 6 6 5.2 10 Auto(AM-S7) 13
## hwy_mpg comb_mpg guzzler air_aspir_method air_aspir_method_desc transmission
## 1 22 NA N TC Turbocharged AMS
## 2 21 17 N TC Turbocharged M
## 3 24 20 N TC Turbocharged SA
## 4 20 16 Y <NA> Naturally Aspirated AMS
## 5 23 17 Y <NA> Naturally Aspirated AMS
## 6 20 16 Y <NA> Naturally Aspirated AMS
## transmission_desc no_gears
## 1 Automated Manual- Selectable (e.g. Automated Manual with paddles) 9
## 2 Manual 7
## 3 Semi-Automatic 8
## 4 Automated Manual- Selectable (e.g. Automated Manual with paddles) 7
## 5 Automated Manual- Selectable (e.g. Automated Manual with paddles) 7
## 6 Automated Manual- Selectable (e.g. Automated Manual with paddles) 7
## trans_lockup trans_creeper_gear drive_sys drive_desc fuel_usage
## 1 Y N A All Wheel Drive GPR
## 2 N N R 2-Wheel Drive, Rear GP
## 3 Y N R 2-Wheel Drive, Rear GP
## 4 N N A All Wheel Drive GPR
## 5 N N R 2-Wheel Drive, Rear GPR
## 6 N N A All Wheel Drive GPR
## fuel_usage_desc class car_truck
## 1 Gasoline (Premium Unleaded Required) Two Seaters car
## 2 Gasoline (Premium Unleaded Recommended) Two Seaters car
## 3 Gasoline (Premium Unleaded Recommended) Two Seaters car
## 4 Gasoline (Premium Unleaded Required) Two Seaters car
## 5 Gasoline (Premium Unleaded Required) Two Seaters car
## 6 Gasoline (Premium Unleaded Required) Two Seaters car
## release_date fuel_cell
## 1 2021-02-01T00:00:00Z N
## 2 2020-08-10T00:00:00Z N
## 3 2020-08-10T00:00:00Z N
## 4 2020-06-30T00:00:00Z N
## 5 2020-10-15T00:00:00Z N
## 6 2020-06-30T00:00:00Z N
colSums(is.na(epa2021))
## model_yr mfr_name division
## 0 0 0
## carline mfr_code model_type_index
## 0 0 0
## engine_displacement no_cylinders transmission_speed
## 0 0 0
## city_mpg hwy_mpg comb_mpg
## 0 0 1
## guzzler air_aspir_method air_aspir_method_desc
## 0 439 0
## transmission transmission_desc no_gears
## 0 0 0
## trans_lockup trans_creeper_gear drive_sys
## 0 0 0
## drive_desc fuel_usage fuel_usage_desc
## 0 0 0
## class car_truck release_date
## 0 507 0
## fuel_cell
## 856
Cleaning the dataset, some values containing NA does not mean nothing available, such as that NA engines indicate that an engine’s method of air aspiration is naturally aspirated. New columns are created to mitigate the older confusing columns containing unidentified NA’s.
imputed_epa2021 <- epa2021 |>
mutate(imputed_aspir_method = ifelse(is.na(air_aspir_method), "N-A", air_aspir_method)) |>
mutate(imputed_fuel_cell = ifelse(is.na(fuel_cell), "NA Sodium", fuel_cell)) |>
select(-c(air_aspir_method, car_truck, fuel_cell))
head(imputed_epa2021)
## model_yr mfr_name division carline mfr_code
## 1 2021 Honda Acura NSX HNX
## 2 2021 aston martin Aston Martin Lagonda Ltd Vantage Manual ASX
## 3 2021 aston martin Aston Martin Lagonda Ltd Vantage V8 ASX
## 4 2021 Volkswagen Group of Audi R8 VGA
## 5 2021 Volkswagen Group of Audi R8 2WD VGA
## 6 2021 Volkswagen Group of Audi R8 Spyder VGA
## model_type_index engine_displacement no_cylinders transmission_speed city_mpg
## 1 39 3.5 6 Auto(AM-S9) 21
## 2 5 4.0 8 Manual(M7) 14
## 3 4 4.0 8 Auto(S8) 18
## 4 5 5.2 10 Auto(AM-S7) 13
## 5 7 5.2 10 Auto(AM-S7) 14
## 6 6 5.2 10 Auto(AM-S7) 13
## hwy_mpg comb_mpg guzzler air_aspir_method_desc transmission
## 1 22 NA N Turbocharged AMS
## 2 21 17 N Turbocharged M
## 3 24 20 N Turbocharged SA
## 4 20 16 Y Naturally Aspirated AMS
## 5 23 17 Y Naturally Aspirated AMS
## 6 20 16 Y Naturally Aspirated AMS
## transmission_desc no_gears
## 1 Automated Manual- Selectable (e.g. Automated Manual with paddles) 9
## 2 Manual 7
## 3 Semi-Automatic 8
## 4 Automated Manual- Selectable (e.g. Automated Manual with paddles) 7
## 5 Automated Manual- Selectable (e.g. Automated Manual with paddles) 7
## 6 Automated Manual- Selectable (e.g. Automated Manual with paddles) 7
## trans_lockup trans_creeper_gear drive_sys drive_desc fuel_usage
## 1 Y N A All Wheel Drive GPR
## 2 N N R 2-Wheel Drive, Rear GP
## 3 Y N R 2-Wheel Drive, Rear GP
## 4 N N A All Wheel Drive GPR
## 5 N N R 2-Wheel Drive, Rear GPR
## 6 N N A All Wheel Drive GPR
## fuel_usage_desc class release_date
## 1 Gasoline (Premium Unleaded Required) Two Seaters 2021-02-01T00:00:00Z
## 2 Gasoline (Premium Unleaded Recommended) Two Seaters 2020-08-10T00:00:00Z
## 3 Gasoline (Premium Unleaded Recommended) Two Seaters 2020-08-10T00:00:00Z
## 4 Gasoline (Premium Unleaded Required) Two Seaters 2020-06-30T00:00:00Z
## 5 Gasoline (Premium Unleaded Required) Two Seaters 2020-10-15T00:00:00Z
## 6 Gasoline (Premium Unleaded Required) Two Seaters 2020-06-30T00:00:00Z
## imputed_aspir_method imputed_fuel_cell
## 1 TC N
## 2 TC N
## 3 TC N
## 4 N-A N
## 5 N-A N
## 6 N-A N
Creating a new dataset four_cylinder_cars by filtering, grouping, and selecting specific columns which contain information of cars with four cylinder engines. To gather all cars with four cylinder engines, I utilized the filter() function to only select rows containing the value of 4 in the no_cylinders column. Additionally, do gather all the basic information and statistics, I used to select() function to create a new dataset containing the car’s division, type, amount of cylinders, engine displacement, and MPG while organizing the dataset in alphabetical order by using the arrange() function to arrange by the division column. This chunk would later gather the maximum and minimum of all MPG’s, print the car with the best fuel efficiency, and summarize by providing a summary and bar chart of all combined MPG’s of all cars with four cylinder engines.
four_cylinder_cars <- imputed_epa2021 |>
filter(no_cylinders == 4) |>
group_by(division, carline) |>
filter(comb_mpg == max(comb_mpg, na.rm = TRUE)) |>
ungroup() |>
# arrange(desc(comb_mpg)) |>
arrange(division) |>
select(division, carline, no_cylinders, engine_displacement, city_mpg, hwy_mpg, comb_mpg)
four_cylinder_cars
## # A tibble: 395 × 7
## division carline no_cylinders engine_displacement city_mpg hwy_mpg comb_mpg
## <chr> <chr> <int> <dbl> <int> <int> <int>
## 1 ALFA ROMEO Giulia 4 2 24 33 27
## 2 ALFA ROMEO Giulia… 4 2 23 31 26
## 3 ALFA ROMEO Stelvio 4 2 22 29 25
## 4 ALFA ROMEO Stelvi… 4 2 22 28 24
## 5 Acura ILX 4 2.4 24 34 28
## 6 Acura TLX AWD 4 2 21 29 24
## 7 Acura TLX AW… 4 2 21 29 24
## 8 Acura TLX FWD 4 2 22 31 25
## 9 Acura TLX FW… 4 2 22 30 25
## 10 Acura RDX FWD 4 2 22 28 24
## # ℹ 385 more rows
cat("Maximum city MPG:", max(four_cylinder_cars$city_mpg))
## Maximum city MPG: 58
cat("\nMaxmimum highway MPG:", max(four_cylinder_cars$hwy_mpg))
##
## Maxmimum highway MPG: 60
cat("\nMaximum combined MPG:", max(four_cylinder_cars$comb_mpg))
##
## Maximum combined MPG: 59
cat("\nMinimum city MPG:", min(four_cylinder_cars$city_mpg))
##
## Minimum city MPG: 17
cat("\nMinimum highway MPG:", min(four_cylinder_cars$hwy_mpg))
##
## Minimum highway MPG: 18
cat("\nMinimum combined MPG:", min(four_cylinder_cars$comb_mpg), "\n")
##
## Minimum combined MPG: 18
summary(four_cylinder_cars$city_mpg)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 17.00 21.00 23.00 25.51 26.50 58.00
summary(four_cylinder_cars$hwy_mpg)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 18.00 28.00 31.00 31.67 34.00 60.00
summary(four_cylinder_cars$comb_mpg)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 18.00 24.00 26.00 27.86 29.50 59.00
four_cylinder_cars[148, ]
## # A tibble: 1 × 7
## division carline no_cylinders engine_displacement city_mpg hwy_mpg comb_mpg
## <chr> <chr> <int> <dbl> <int> <int> <int>
## 1 HYUNDAI MO… Ioniq … 4 1.6 58 60 59
barplot(main = "Combined Four Cylinder MPG Bar Chart", xlab = "MPG", ylab = "Amount of cars", table(four_cylinder_cars$comb_mpg))
Creating a new dataset six_cylinder_cars by filtering, grouping, and selecting specific columns which contain information of cars with six cylinder engines. To gather all cars with six cylinder engines, I utilized the filter() function to only select rows containing the value of 6 in the no_cylinders column. Additionally, do gather all the basic information and statistics, I used to select() function to create a new dataset containing the car’s division, type, amount of cylinders, engine displacement, and MPG while organizing the dataset in alphabetical order by using the arrange() function to arrange by the division column. This chunk would later gather the maximum and minimum of all MPG’s, print the car with the best fuel efficiency, and summarize by providing a summary and bar chart of all combined MPG’s of all cars with six cylinder engines.
six_cylinder_cars <- imputed_epa2021 |>
filter(no_cylinders == 6) |>
group_by(division, carline) |>
filter(comb_mpg == max(comb_mpg, na.rm = TRUE)) |>
ungroup() |>
# arrange(desc(comb_mpg)) |>
arrange(division) |>
select(division, carline, no_cylinders, engine_displacement, city_mpg, hwy_mpg, comb_mpg)
## Warning: There was 1 warning in `filter()`.
## ℹ In argument: `comb_mpg == max(comb_mpg, na.rm = TRUE)`.
## ℹ In group 3: `division = "Acura"` `carline = "NSX"`.
## Caused by warning in `max()`:
## ! no non-missing arguments to max; returning -Inf
six_cylinder_cars
## # A tibble: 309 × 7
## division carline no_cylinders engine_displacement city_mpg hwy_mpg comb_mpg
## <chr> <chr> <int> <dbl> <int> <int> <int>
## 1 ALFA ROMEO Giulia 6 2.9 17 25 20
## 2 ALFA ROMEO Stelvi… 6 2.9 17 23 19
## 3 Audi RS 5 6 2.9 18 25 20
## 4 Audi S5 6 3 20 28 23
## 5 Audi S5 Cab… 6 3 20 26 22
## 6 Audi S4 6 3 20 28 23
## 7 Audi A6 qua… 6 3 22 29 24
## 8 Audi A7 qua… 6 3 22 29 24
## 9 Audi RS 5 S… 6 2.9 18 25 21
## 10 Audi S5 Spo… 6 3 20 28 23
## # ℹ 299 more rows
cat("Maximum city MPG:", max(six_cylinder_cars$city_mpg))
## Maximum city MPG: 31
cat("\nMaxmimum highway MPG:", max(six_cylinder_cars$hwy_mpg))
##
## Maxmimum highway MPG: 34
cat("\nMaximum combined MPG:", max(six_cylinder_cars$comb_mpg))
##
## Maximum combined MPG: 30
cat("\nMinimum city MPG:", min(six_cylinder_cars$city_mpg))
##
## Minimum city MPG: 12
cat("\nMinimum highway MPG:", min(six_cylinder_cars$hwy_mpg))
##
## Minimum highway MPG: 16
cat("\nMinimum combined MPG:", min(six_cylinder_cars$comb_mpg), "\n")
##
## Minimum combined MPG: 14
summary(six_cylinder_cars$city_mpg)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 12.00 17.00 19.00 18.99 20.00 31.00
summary(six_cylinder_cars$hwy_mpg)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 16.00 24.00 26.00 25.57 27.00 34.00
summary(six_cylinder_cars$comb_mpg)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 14.00 20.00 21.00 21.45 23.00 30.00
six_cylinder_cars[194, ]
## # A tibble: 1 × 7
## division carline no_cylinders engine_displacement city_mpg hwy_mpg comb_mpg
## <chr> <chr> <int> <dbl> <int> <int> <int>
## 1 LEXUS RX 450h A… 6 3.5 31 28 30
barplot(main = "Combined Six Cylinder MPG Bar Chart", xlab = "MPG", ylab = "Amount of cars", table(six_cylinder_cars$comb_mpg))
Creating a new dataset eight_cylinder_cars by filtering, grouping, and selecting specific columns which contain information of cars with eight cylinder engines. To gather all cars with eight cylinder engines, I utilized the filter() function to only select rows containing the value of 8 in the no_cylinders column. Additionally, do gather all the basic information and statistics, I used to select() function to create a new dataset containing the car’s division, type, amount of cylinders, engine displacement, and MPG while organizing the dataset in alphabetical order by using the arrange() function to arrange by the division column. This chunk would later gather the maximum and minimum of all MPG’s, print the car with the best fuel efficiency, and summarize by providing a summary and bar chart of all combined MPG’s of all cars with eight cylinder engines.
eight_cylinder_cars <- imputed_epa2021 |>
filter(no_cylinders == 8) |>
group_by(division, carline) |>
filter(comb_mpg == max(comb_mpg, na.rm = TRUE)) |>
ungroup() |>
# arrange(desc(comb_mpg)) |>
arrange(division) |>
select(division, carline, no_cylinders, engine_displacement, city_mpg, hwy_mpg, comb_mpg)
eight_cylinder_cars
## # A tibble: 166 × 7
## division carline no_cylinders engine_displacement city_mpg hwy_mpg comb_mpg
## <chr> <chr> <int> <dbl> <int> <int> <int>
## 1 Aston Mar… Vantag… 8 4 14 21 17
## 2 Aston Mar… Vantag… 8 4 18 24 20
## 3 Aston Mar… DB11 V8 8 4 18 24 20
## 4 Aston Mar… DBX V8 8 4 14 18 15
## 5 Audi RS 7 8 4 15 22 17
## 6 Audi A8L 8 4 15 23 18
## 7 Audi S8 8 4 13 22 16
## 8 Audi RS 6 A… 8 4 15 22 17
## 9 Audi RS Q8 8 4 13 19 15
## 10 Audi SQ7 8 4 15 21 17
## # ℹ 156 more rows
cat("Maximum city MPG:", max(eight_cylinder_cars$city_mpg))
## Maximum city MPG: 18
cat("\nMaxmimum highway MPG:", max(eight_cylinder_cars$hwy_mpg))
##
## Maxmimum highway MPG: 27
cat("\nMaximum combined MPG:", max(eight_cylinder_cars$comb_mpg))
##
## Maximum combined MPG: 21
cat("\nMinimum city MPG:", min(eight_cylinder_cars$city_mpg))
##
## Minimum city MPG: 10
cat("\nMinimum highway MPG:", min(eight_cylinder_cars$hwy_mpg))
##
## Minimum highway MPG: 14
cat("\nMinimum combined MPG:", min(eight_cylinder_cars$comb_mpg), "\n")
##
## Minimum combined MPG: 12
summary(eight_cylinder_cars$city_mpg)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 10.00 14.00 15.00 14.98 16.00 18.00
summary(eight_cylinder_cars$hwy_mpg)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 14.00 19.00 21.00 21.14 23.00 27.00
summary(eight_cylinder_cars$comb_mpg)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 12.00 16.00 17.00 17.22 18.00 21.00
eight_cylinder_cars[c(123, 124), ]
## # A tibble: 2 × 7
## division carline no_cylinders engine_displacement city_mpg hwy_mpg comb_mpg
## <chr> <chr> <int> <dbl> <int> <int> <int>
## 1 Mercedes-B… AMG C … 8 4 17 26 21
## 2 Mercedes-B… AMG C … 8 4 17 26 21
barplot(main = "Combined Eight Cylinder MPG Bar Chart", xlab = "MPG", ylab = "Amount of cars", table(eight_cylinder_cars$comb_mpg))
Creating a new dataset v12_cars by filtering, grouping, and selecting specific columns which contain information of cars with twelve cylinder engines. To gather all cars with four cylinder engines, I utilized the filter() function to only select rows containing the value of 12 in the no_cylinders column. Additionally, do gather all the basic information and statistics, I used to select() function to create a new dataset containing the car’s division, type, amount of cylinders, engine displacement, and MPG while organizing the dataset in alphabetical order by using the arrange() function to arrange by the division column. This chunk would later gather the maximum and minimum of all MPG’s, print the car with the best fuel efficiency, and summarize by providing a summary and bar chart of all combined MPG’s of all cars with twelve cylinder engines.
v12_cars <- imputed_epa2021 |>
filter(no_cylinders == 12) |>
# arrange(desc(comb_mpg)) |>
arrange(division) |>
select(division, carline, no_cylinders, engine_displacement, city_mpg, hwy_mpg, comb_mpg)
v12_cars
## division carline no_cylinders
## 1 Aston Martin Lagonda Ltd DB11 V12 12
## 2 Aston Martin Lagonda Ltd DBS 12
## 3 BMW M760i xDrive 12
## 4 Bentley Continental GT Convertible 12
## 5 Bentley Continental GT 12
## 6 Bentley Flying Spur 12
## 7 Bentley Bentayga 12
## 8 Ferrari North America, Inc. 812 GTS 12
## 9 Ferrari North America, Inc. 812 Superfast 12
## 10 Lamborghini Aventador Coupe 12
## 11 Lamborghini Aventador Roadster 12
## 12 Lamborghini Aventador Sian Coupe 12
## 13 Lamborghini Aventador Sian Roadster 12
## 14 Rolls-Royce Motor Cars Limited Dawn 12
## 15 Rolls-Royce Motor Cars Limited Dawn Black Badge 12
## 16 Rolls-Royce Motor Cars Limited Wraith 12
## 17 Rolls-Royce Motor Cars Limited Wraith Black Badge 12
## 18 Rolls-Royce Motor Cars Limited Ghost 12
## 19 Rolls-Royce Motor Cars Limited Ghost EWB 12
## 20 Rolls-Royce Motor Cars Limited Phantom 12
## 21 Rolls-Royce Motor Cars Limited Phantom EWB 12
## 22 Rolls-Royce Motor Cars Limited Cullinan 12
## 23 Rolls-Royce Motor Cars Limited Cullinan Black Badge 12
## engine_displacement city_mpg hwy_mpg comb_mpg
## 1 5.2 15 22 18
## 2 5.2 14 22 17
## 3 6.6 13 20 16
## 4 6.0 12 19 15
## 5 6.0 12 20 15
## 6 6.0 12 19 15
## 7 6.0 12 18 14
## 8 6.5 12 15 13
## 9 6.5 12 16 13
## 10 6.5 8 15 10
## 11 6.5 9 15 10
## 12 6.5 8 14 10
## 13 6.5 8 14 10
## 14 6.6 12 18 14
## 15 6.6 12 18 14
## 16 6.6 12 18 14
## 17 6.6 12 18 14
## 18 6.7 12 19 14
## 19 6.7 12 19 14
## 20 6.7 12 20 14
## 21 6.7 12 20 14
## 22 6.7 12 20 14
## 23 6.7 12 20 14
cat("Maximum city MPG:", max(v12_cars$city_mpg))
## Maximum city MPG: 15
cat("\nMaxmimum highway MPG:", max(v12_cars$hwy_mpg))
##
## Maxmimum highway MPG: 22
cat("\nMaximum combined MPG:", max(v12_cars$comb_mpg))
##
## Maximum combined MPG: 18
cat("\nMinimum city MPG:", min(v12_cars$city_mpg))
##
## Minimum city MPG: 8
cat("\nMinimum highway MPG:", min(v12_cars$hwy_mpg))
##
## Minimum highway MPG: 14
cat("\nMinimum combined MPG:", min(v12_cars$comb_mpg), "\n")
##
## Minimum combined MPG: 10
summary(v12_cars$city_mpg)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 8.00 12.00 12.00 11.61 12.00 15.00
summary(v12_cars$hwy_mpg)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 14.00 17.00 19.00 18.22 20.00 22.00
summary(v12_cars$comb_mpg)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 10.00 13.50 14.00 13.74 14.50 18.00
v12_cars[1, ]
## division carline no_cylinders engine_displacement city_mpg
## 1 Aston Martin Lagonda Ltd DB11 V12 12 5.2 15
## hwy_mpg comb_mpg
## 1 22 18
barplot(main = "Combined Twelve Cylinder MPG Bar Chart", xlab = "MPG", ylab = "Amount of cars", table(v12_cars$comb_mpg))
Based on the findings of emissions and gas mileage between all engines with different cylinder amounts, each range of cylinders display varying ranges of city, highway, and combined gas mileage, as well as the cars with the best gas mileages. The four cylinder car with the best combined gas mileage is the Hyundai Ioniq Blue with 59 MPG, the Lexus RX 450h AWD for six cylinder car with 30 MPG, the Mercedes AMG C63 and C63S for eight cylinder cars with 21 MPG, and the Aston Martin DB11 V12 for the twelve cylinder cars with 18 MPG. The results of each varying range of MPG and cars with the best MPG for their cylinder count are relevant to my research question as they answer how each number of cylinders affect the gas efficiency and distance covered per gallon, while also highlighting which cars of each numbered cylinder category are the best at managing their fuel consumption. This could potentially lead to engineers building engines that are increasingly efficient over the years no matter the amount of cylinders that are cycling through fuel consumption.
Vehicle info from the EPA for 2021. Data Sets. (n.d.). https://www.openintro.org/data/index.php?data=epa2021