Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use R knitr::opts_chunk$set (echoTRUE) Load packages library (ggplot2) library(d

ID: 3065582 • Letter: U

Question

Use R

knitr::opts_chunk$set (echoTRUE) Load packages library (ggplot2) library(dplyr) library (stringr) library (nycflights13) Questions 0. (0 marks) If you haven't already, install the nycflights13 package and read the help files on the flights and airlines tables. 1. (1 mark) Use dplyr functions to perform an inner join between the airlines table and the flights table on carrier and then select the variables carrier, name, month, day, dep_time and dep_delay.Save your dataframe in flights 2. (2 marks) Remove Inc., Co. and Corporation from the airline names in the name variable of flights. Then shorten the phrases "Airlines", "Air Lines, and "Airways" to just "Air". Print out the unique values of flights$name 3. (2 marks) Select the flights from January. Calculate the median departure delay for each airline on each day and save the results in a dataframe called fldelaysJan. Plot median delay versus day, with different facets for each airline. Use the name variable to specify airlines (instead of carrier ) so that the labels on your facets are informative. Do not free the scales on the facets. 4. (2 marks) The plot in part (4) is not very informative because one airline had a very long median flight delay on one day in January. Remove this one observation from fldelaysJan. Also remove the airline that had flights on only one day. Now redo the plot in (4). Again, do not free the scales on the facets. s a marks dentiy the four ailines wth the greatest median delays Plot these four as fecets on a single plot of median delay versus day, and plot the remaining airlines as facets on a separate plot of median delay versus day. Add informative titles to your two plots

Explanation / Answer

Solution1:

library(gglot2)
library(dplyr)
library(stringr)
library(nycflights13)
print(flights)
print(airlines)
View(airlines)
View(flights)
colnames(flights)
class(flights)
dim(flights)
colnames(airlines)
dim(airlines)

airlines$carrier <- toupper(airlines$carrier)

flights$carrier <- toupper(flights$carrier)


flights <- inner_join(airlines,flights[,c(10,2,3,4,6)],by="carrier")
dim(flights)

colnames(flights)

output:

336776 observations and 6

"carrier" "name" "month" "day" "dep_time"
"dep_delay".

Solution2:

stopwords = c("Co.","Corporation")

flights$name <- gsub(paste0(stopwords,collapse = "|"),"", flights$name)
unique(flights$name)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Chat Now And Get Quote