Homework 4

Instructions

Answer each of the following questions. Be sure to display all your code in the rendered version (use echo: true throughout1).

Remember, the package nycflights13 contains data on flights originating in NYC during the year 2013. There are three airports servicing NYC: JFK, LGA (“LaGuardia”), and EWR (“Newark”). You can look at the slides or use ?nycflights13 in your console to review/learn more about the data. (Don’t include the ?nycflights13 command in your .qmd file though; it’s meant only for interactive use, like in the console, not in documents or scripts.)

Exercises

  1. Choose an airport outside New York, and use code to count how many flights went to that airport from NYC in 2013. How many of those flights started at JFK, LGA, and EWR respectively?

  2. The variable arr_delay contains arrival delays in minutes; negative values represent early arrivals. Make a ggplot histogram displaying arrival delays for 2013 flights from NYC to the airport you chose.

  1. Use left_join to add weather data at departure to the subsetted data. If time_hour didn’t exist in one or both of these datasets, which variables would you need to merge on? Calculate the mean temperature by month at departure (temp) across all flights.
  1. Investigate if there is a relationship between departure delay (dep_delay) and precipitation (precip) in the full dataset. Is the relationship different between JFK, LGA, and EWR? I suggest answering this question by making a plot and writing down a one-sentence interpretation2.

As always, submit both the .qmd and knitted .html to Canvas.

Before you submit:

Have you remembered to add embed-resources: true to your YAML?

Footnotes

  1. You can make this a global option for your whole document by putting it directly in the YAML of your qmd:

    ---
    title: "My Document"
    execute:
      echo: true
    ---
    ↩︎
  2. Hint: Read about geom_smooth() and consider how you might use it with the argument method = "lm" to plot a relationship between these two variables.↩︎