Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The flights data set seen in class is available in the package nycflights 1 3 as a tibble. It contains on - time data for
The flights data set seen in class is available in the package nycflights as a tibble. It contains ontime
data for all flights that departed New York City via its three main airports throughout the whole year of
The airport from which each flight departed is recorded in the origin column.
a Load the tidyverse suite of packages, as well as the nycflights package and the flights data
therein.
b Cancelled flights are defined as those for which no departure or arrival took place. Write code using
pipe operators and filter to create a new data set flights which removes any rows with missing
values ie NA entries for the depdelay or arrdelay variables Hint: see isna and use the "and"
operator & and the negation operator
c Define the new variable gain as the difference between the departure delay and the arrival delay, the
new variable airhour as the airtime variable reexpressed in hours, and the variable gainperhour
as the gain per airhour. Write code using pipe operators and the functions mutate and select
which creates a new tibble called flights containing only the gainperhour and origin variables.
Hint: you may exploit the fact that mutate allows you to refer to variables you have just created
d The ggplot code below plots a kernel density estimate of the gainperhour for each origin airport.
However, it overplots all three estimated density curves on the one graph. Modify this code so that it
i partitionsfacets the graph into a separate panel for each origin and ii produces histograms with
bins rather than density plots.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started