In: Statistics and Probability
R code:
## 2. __Basic dplyr exercises__
## Install the package `fueleconomy` and load the dataset
`vehicles`. Answer the following questions.
install.packages("fueleconomy")
library(fueleconomy)
library(dplyr)
library(tidyr)
data(vehicles)
e. Finally, for the years 1994, 1999, 2004, 2009, and 2014, find the average city mpg of midsize cars for each manufacturer for each year. Use tidyr to transform the resulting output so each manufacturer has one row, and five columns (a column for each year). I have included sample output for the first two rows.
Output should like :
# make 1994 1999 2004 2009 2014
# 1 Acura NA 16.50000 17.33333 17.00000 20.60000
# 2 Audi NA 15.25000 16.20000 15.83333 19.08333