forked from INFO-201/m9-dplyr
-
Notifications
You must be signed in to change notification settings - Fork 123
/
Copy pathexercise.R
47 lines (26 loc) · 1.5 KB
/
exercise.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Exercise 2: Data Frame Practice with `dplyr`.
# Use a different appraoch to accomplish the same tasks as exercise-1
# install and load dplyr
install.packages("dplyr")
library("dplyr")
# Require/library the fueleconomy package
library(fueleconomy)
# You should have have access to the `vehicles` data.frame
# Use `as.data.frame()` to make it into a normal data frame
# Select the different manufacturers (makes) of the cars in this data set.
# Use the `unique()` function to determine how many different car manufacturers
# are represented by the data set.
# Filter the data set for vehicles manufactured in 1997
# Arrange the 1997 cars by highway (`hwy`) gas milage
# Hint: use the `order()` function similar to how you would use the `max()` function.
# See also: https://www.r-bloggers.com/r-sorting-a-data-frame-by-the-contents-of-a-column/
# Mutate the 1997 cars data frame to add a column `average` that has the average gas milage between
# city and highway for each car
# Filter the whole vehicles data set for 2-Wheel Drive vehicles that get more than 20 miles/gallon in the city
# Save this new data frame in a variable.
# Of those vehicles, what is the vehicle ID of the vehicle with the worst hwy mpg?
# Hint: filter for the worst vecle, then select its ID.
# Write a function that takes a `year` and a `make` as parameters,
# and returns the vehicle that gets the most hwy miles/gallon of vehicles of that make in that year
# You'll need to filter more!
# What was the most efficient honda model of 1995?