Answered step by step
Verified Expert Solution
Link Copied!

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 nycflights13 as a tibble. It contains on-time
data for all flights that departed New York City via its three main airports throughout the whole year of
2013. The airport from which each flight departed is recorded in the origin column.
a) Load the tidyverse suite of packages, as well as the nycflights13 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 flights2 which removes any rows with missing
values (i.e. NA entries) for the dep_delay or arr_delay variables (Hint: see ?is.na 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 air_hour as the air_time variable re-expressed in hours, and the variable gain_per_hour
as the gain per air_hour. Write code using pipe operators and the functions mutate() and select()
which creates a new tibble called flights3 containing only the gain_per_hour and origin variables.
(Hint: you may exploit the fact that mutate() allows you to refer to variables you have just created).
d) The ggplot2 code below plots a kernel density estimate of the gain_per_hour for each origin airport.
However, it overplots all three estimated density curves on the one graph. Modify this code so that it
(i) partitions/facets the graph into a separate panel for each origin and (ii) produces histograms with
50 bins rather than density plots.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

Students also viewed these Databases questions

Question

Understanding Groups

Answered: 1 week ago