Lab 4: dplyr, Part 1
Filter, slice, arrange, select, mutate, and summarize flights.
Work in a Quarto document. Number the exercises. Do 4.1 through 4.3 first.
library(tidyverse)
library(nycflights13)
data("flights")
1. Filter and slice
- Flights in odd months, or on even days of even months.
- Flights to Houston (
IAHorHOU), on UA, AA, or DL, in July–September, that arrived more than 15 minutes late and did not leave late. - Rows 10, 100, 1000, 10000, and 100000.
- The last 10 of the first 30 Newark (
EWR) flights. set.seed(1). A random 1% sample, and a sample of 3367 rows. Are the last 10 rows the same? Why?- The 50 longest
air_times, then the 10 smallestarr_delays among those. Repeat afterfilter(air_time < 300). What doeswith_ties = FALSEchange?
2. Arrange, select, mutate
- Longest
distance, ties broken byair_time. - Keep every arrival column plus
year,month, andday. - Convert
dep_timeandsched_dep_timeto minutes past midnight. - Move columns ending in
"time"to just beforeflight. Then putschedcolumns before the actual times.
3. Summarize and group
- Standard deviation of
dep_delay. - Maximum
dep_delaybyoriginin one pipeline. - For each
day, the number and proportion of canceled flights (is.na(dep_delay) | is.na(arr_delay)). Plot the proportion against day, and against average departure delay.