# Average MPG for cars with 6 and 4 cylinders# Uncomment and fix the following code to make it functional# six.cyl.cars <- subset(car_df, cyl == 6)# four.cyl.cars <- subset(car_df, cyl == 4)# six.cyl.avg.mpg <- mean(six.cyl.cars$mpg)# four.cyl.avg.mpg <- mean(four.cyl.cars$mpg)# six.cyl.avg.mpg > four.cyl.avg.mpg# six.cyl.avg.mpg < four.cyl.avg.mpg# Save updated data frame# write.csv(car_df, "car_data.csv")
Data Visualization with GGPLOT2
# Install ggplot2 if not already installed# install.packages("ggplot2")library(ggplot2)ggplot(car_df, aes(model, mpg)) +geom_bar(stat ="identity") +labs(y ="MPG", x ="Model")