Introduction
This chapter will introduce you to data transformation using the dplyr package and a new dataset on flights that departed from New York City in 2013.
Prerequisites
# install.packages("nycflights13")
library(nycflights13)
library(tidyverse)
nycflights13
This dataset contains all 336,776 flights that departed from New York City in 2013. The data comes from the US Bureau of Transportation Statistics, and is documented in ?flights
. For short:
Data frame with columns year, month, day Date of departure.
dep_time, arr_time Actual departure and arrival times (format HHMM or HMM), local tz.
sched_dep_time, sched_arr_time Scheduled departure and arrival times (format HHMM or HMM), local tz.
flights
year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 1 | 517 | 515 | 2 | 830 | 819 | 11 | UA | 1545 | N14228 | EWR | IAH | 227 | 1400 | 5 | 15 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 533 | 529 | 4 | 850 | 830 | 20 | UA | 1714 | N24211 | LGA | IAH | 227 | 1416 | 5 | 29 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 542 | 540 | 2 | 923 | 850 | 33 | AA | 1141 | N619AA | JFK | MIA | 160 | 1089 | 5 | 40 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 544 | 545 | -1 | 1004 | 1022 | -18 | B6 | 725 | N804JB | JFK | BQN | 183 | 1576 | 5 | 45 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 554 | 600 | -6 | 812 | 837 | -25 | DL | 461 | N668DN | LGA | ATL | 116 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 554 | 558 | -4 | 740 | 728 | 12 | UA | 1696 | N39463 | EWR | ORD | 150 | 719 | 5 | 58 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 555 | 600 | -5 | 913 | 854 | 19 | B6 | 507 | N516JB | EWR | FLL | 158 | 1065 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 709 | 723 | -14 | EV | 5708 | N829AS | LGA | IAD | 53 | 229 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 838 | 846 | -8 | B6 | 79 | N593JB | JFK | MCO | 140 | 944 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 753 | 745 | 8 | AA | 301 | N3ALAA | LGA | ORD | 138 | 733 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 849 | 851 | -2 | B6 | 49 | N793JB | JFK | PBI | 149 | 1028 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 853 | 856 | -3 | B6 | 71 | N657JB | JFK | TPA | 158 | 1005 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 924 | 917 | 7 | UA | 194 | N29129 | JFK | LAX | 345 | 2475 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 923 | 937 | -14 | UA | 1124 | N53441 | EWR | SFO | 361 | 2565 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 941 | 910 | 31 | AA | 707 | N3DUAA | LGA | DFW | 257 | 1389 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 559 | 0 | 702 | 706 | -4 | B6 | 1806 | N708JB | JFK | BOS | 44 | 187 | 5 | 59 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 854 | 902 | -8 | UA | 1187 | N76515 | EWR | LAS | 337 | 2227 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 851 | 858 | -7 | B6 | 371 | N595JB | LGA | FLL | 152 | 1076 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 837 | 825 | 12 | MQ | 4650 | N542MQ | LGA | ATL | 134 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 601 | 600 | 1 | 844 | 850 | -6 | B6 | 343 | N644JB | EWR | PBI | 147 | 1023 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 610 | -8 | 812 | 820 | -8 | DL | 1919 | N971DL | LGA | MSP | 170 | 1020 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 605 | -3 | 821 | 805 | 16 | MQ | 4401 | N730MQ | LGA | DTW | 105 | 502 | 6 | 5 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 858 | 910 | -12 | AA | 1895 | N633AA | EWR | MIA | 152 | 1085 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 837 | 845 | -8 | DL | 1743 | N3739P | JFK | ATL | 128 | 760 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 607 | 607 | 0 | 858 | 915 | -17 | UA | 1077 | N53442 | EWR | MIA | 157 | 1085 | 6 | 7 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 608 | 600 | 8 | 807 | 735 | 32 | MQ | 3768 | N9EAMQ | EWR | ORD | 139 | 719 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 611 | 600 | 11 | 945 | 931 | 14 | UA | 303 | N532UA | JFK | SFO | 366 | 2586 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 613 | 610 | 3 | 925 | 921 | 4 | B6 | 135 | N635JB | JFK | RSW | 175 | 1074 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 1039 | 1100 | -21 | B6 | 709 | N794JB | JFK | SJU | 182 | 1598 | 6 | 15 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 833 | 842 | -9 | DL | 575 | N326NB | EWR | ATL | 120 | 746 | 6 | 15 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2013 | 9 | 30 | 2123 | 2125 | -2 | 2223 | 2247 | -24 | EV | 5489 | N712EV | LGA | CHO | 45 | 305 | 21 | 25 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2127 | 2129 | -2 | 2314 | 2323 | -9 | EV | 3833 | N16546 | EWR | CLT | 72 | 529 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2128 | 2130 | -2 | 2328 | 2359 | -31 | B6 | 97 | N807JB | JFK | DEN | 213 | 1626 | 21 | 30 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2129 | 2059 | 30 | 2230 | 2232 | -2 | EV | 5048 | N751EV | LGA | RIC | 45 | 292 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2131 | 2140 | -9 | 2225 | 2255 | -30 | MQ | 3621 | N807MQ | JFK | DCA | 36 | 213 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2140 | 2140 | 0 | 10 | 40 | -30 | AA | 185 | N335AA | JFK | LAX | 298 | 2475 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2142 | 2129 | 13 | 2250 | 2239 | 11 | EV | 4509 | N12957 | EWR | PWM | 47 | 284 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2145 | 2145 | 0 | 115 | 140 | -25 | B6 | 1103 | N633JB | JFK | SJU | 192 | 1598 | 21 | 45 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2147 | 2137 | 10 | 30 | 27 | 3 | B6 | 1371 | N627JB | LGA | FLL | 139 | 1076 | 21 | 37 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2149 | 2156 | -7 | 2245 | 2308 | -23 | UA | 523 | N813UA | EWR | BOS | 37 | 200 | 21 | 56 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2150 | 2159 | -9 | 2250 | 2306 | -16 | EV | 3842 | N10575 | EWR | MHT | 39 | 209 | 21 | 59 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2159 | 1845 | 194 | 2344 | 2030 | 194 | 9E | 3320 | N906XJ | JFK | BUF | 50 | 301 | 18 | 45 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | 2203 | 2205 | -2 | 2339 | 2331 | 8 | EV | 5311 | N722EV | LGA | BGR | 61 | 378 | 22 | 5 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2207 | 2140 | 27 | 2257 | 2250 | 7 | MQ | 3660 | N532MQ | LGA | BNA | 97 | 764 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2211 | 2059 | 72 | 2339 | 2242 | 57 | EV | 4672 | N12145 | EWR | STL | 120 | 872 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2231 | 2245 | -14 | 2335 | 2356 | -21 | B6 | 108 | N193JB | JFK | PWM | 48 | 273 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2233 | 2113 | 80 | 112 | 30 | 42 | UA | 471 | N578UA | EWR | SFO | 318 | 2565 | 21 | 13 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2235 | 2001 | 154 | 59 | 2249 | 130 | B6 | 1083 | N804JB | JFK | MCO | 123 | 944 | 20 | 1 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2237 | 2245 | -8 | 2345 | 2353 | -8 | B6 | 234 | N318JB | JFK | BTV | 43 | 266 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2245 | -5 | 2334 | 2351 | -17 | B6 | 1816 | N354JB | JFK | SYR | 41 | 209 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2250 | -10 | 2347 | 7 | -20 | B6 | 2002 | N281JB | JFK | BUF | 52 | 301 | 22 | 50 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2241 | 2246 | -5 | 2345 | 1 | -16 | B6 | 486 | N346JB | JFK | ROC | 47 | 264 | 22 | 46 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2307 | 2255 | 12 | 2359 | 2358 | 1 | B6 | 718 | N565JB | JFK | BOS | 33 | 187 | 22 | 55 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2349 | 2359 | -10 | 325 | 350 | -25 | B6 | 745 | N516JB | JFK | PSE | 196 | 1617 | 23 | 59 | 2013-09-30 23:00:00 |
2013 | 9 | 30 | NA | 1842 | NA | NA | 2019 | NA | EV | 5274 | N740EV | LGA | BNA | NA | 764 | 18 | 42 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | NA | 1455 | NA | NA | 1634 | NA | 9E | 3393 | NA | JFK | DCA | NA | 213 | 14 | 55 | 2013-09-30 14:00:00 |
2013 | 9 | 30 | NA | 2200 | NA | NA | 2312 | NA | 9E | 3525 | NA | LGA | SYR | NA | 198 | 22 | 0 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | NA | 1210 | NA | NA | 1330 | NA | MQ | 3461 | N535MQ | LGA | BNA | NA | 764 | 12 | 10 | 2013-09-30 12:00:00 |
2013 | 9 | 30 | NA | 1159 | NA | NA | 1344 | NA | MQ | 3572 | N511MQ | LGA | CLE | NA | 419 | 11 | 59 | 2013-09-30 11:00:00 |
2013 | 9 | 30 | NA | 840 | NA | NA | 1020 | NA | MQ | 3531 | N839MQ | LGA | RDU | NA | 431 | 8 | 40 | 2013-09-30 08:00:00 |
glimpse(flights)
Rows: 336,776
Columns: 19
$ year [3m[90m<int>[39m[23m 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2013, 2~
$ month [3m[90m<int>[39m[23m 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1~
$ day [3m[90m<int>[39m[23m 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1~
$ dep_time [3m[90m<int>[39m[23m 517, 533, 542, 544, 554, 554, 555, 557, 557, 558, 558, ~
$ sched_dep_time [3m[90m<int>[39m[23m 515, 529, 540, 545, 600, 558, 600, 600, 600, 600, 600, ~
$ dep_delay [3m[90m<dbl>[39m[23m 2, 4, 2, -1, -6, -4, -5, -3, -3, -2, -2, -2, -2, -2, -1~
$ arr_time [3m[90m<int>[39m[23m 830, 850, 923, 1004, 812, 740, 913, 709, 838, 753, 849,~
$ sched_arr_time [3m[90m<int>[39m[23m 819, 830, 850, 1022, 837, 728, 854, 723, 846, 745, 851,~
$ arr_delay [3m[90m<dbl>[39m[23m 11, 20, 33, -18, -25, 12, 19, -14, -8, 8, -2, -3, 7, -1~
$ carrier [3m[90m<chr>[39m[23m "UA", "UA", "AA", "B6", "DL", "UA", "B6", "EV", "B6", "~
$ flight [3m[90m<int>[39m[23m 1545, 1714, 1141, 725, 461, 1696, 507, 5708, 79, 301, 4~
$ tailnum [3m[90m<chr>[39m[23m "N14228", "N24211", "N619AA", "N804JB", "N668DN", "N394~
$ origin [3m[90m<chr>[39m[23m "EWR", "LGA", "JFK", "JFK", "LGA", "EWR", "EWR", "LGA",~
$ dest [3m[90m<chr>[39m[23m "IAH", "IAH", "MIA", "BQN", "ATL", "ORD", "FLL", "IAD",~
$ air_time [3m[90m<dbl>[39m[23m 227, 227, 160, 183, 116, 150, 158, 53, 140, 138, 149, 1~
$ distance [3m[90m<dbl>[39m[23m 1400, 1416, 1089, 1576, 762, 719, 1065, 229, 944, 733, ~
$ hour [3m[90m<dbl>[39m[23m 5, 5, 5, 5, 6, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 6, 6, 6~
$ minute [3m[90m<dbl>[39m[23m 15, 29, 40, 45, 0, 58, 0, 0, 0, 0, 0, 0, 0, 0, 0, 59, 0~
$ time_hour [3m[90m<dttm>[39m[23m 2013-01-01 05:00:00, 2013-01-01 05:00:00, 2013-01-01 0~
dplyr
basics
- The first argument is always a data frame.
- The subsequent arguments typically describe which columns to operate on, using the variable names (without quotes).
- The output is always a new data frame.
|>
: the pipe to combining multiple verbs (functions): the pipe takes the thing on its left and passes it along to the function on its right so that x |> f(y)
is equivalent to f(x, y)
, and x |> f(y) |> g(z)
is equivalent to g(f(x, y), z)
. The easiest way to pronounce the pipe is “then”.
dplyr
’s verbs are organized into four groups based on what they operate on: rows, columns, groups, or tables. In the following sections you’ll learn the most important verbs for rows, columns, and groups, then we’ll come back to the join verbs that work on tables in Chapter 19.
# |>: the pipe to combining multiple verbs (functions)
flights |>
filter(dest == "IAH") |>
group_by(year, month, day) |>
summarize(
arr_delay = mean(arr_delay, na.rm = TRUE)
)
[1m[22m`summarise()` has grouped output by 'year', 'month'. You can override using the
`.groups` argument.
year | month | day | arr_delay |
---|---|---|---|
<int> | <int> | <int> | <dbl> |
2013 | 1 | 1 | 17.850000 |
2013 | 1 | 2 | 7.000000 |
2013 | 1 | 3 | 18.315789 |
2013 | 1 | 4 | -3.200000 |
2013 | 1 | 5 | 20.230769 |
2013 | 1 | 6 | 9.277778 |
2013 | 1 | 7 | -7.736842 |
2013 | 1 | 8 | 7.789474 |
2013 | 1 | 9 | 18.055556 |
2013 | 1 | 10 | 6.684211 |
2013 | 1 | 11 | -22.526316 |
2013 | 1 | 12 | -19.923077 |
2013 | 1 | 13 | 14.833333 |
2013 | 1 | 14 | 17.421053 |
2013 | 1 | 15 | 26.105263 |
2013 | 1 | 16 | 40.105263 |
2013 | 1 | 17 | -7.894737 |
2013 | 1 | 18 | -5.210526 |
2013 | 1 | 19 | 2.153846 |
2013 | 1 | 20 | 10.352941 |
2013 | 1 | 21 | 19.789474 |
2013 | 1 | 22 | -5.055556 |
2013 | 1 | 23 | -6.947368 |
2013 | 1 | 24 | -15.894737 |
2013 | 1 | 25 | -10.368421 |
2013 | 1 | 26 | -8.384615 |
2013 | 1 | 27 | -16.055556 |
2013 | 1 | 28 | -15.157895 |
2013 | 1 | 29 | -20.842105 |
2013 | 1 | 30 | 20.842105 |
... | ... | ... | ... |
2013 | 12 | 2 | -6.5000000 |
2013 | 12 | 3 | -8.4545455 |
2013 | 12 | 4 | -3.1363636 |
2013 | 12 | 5 | 51.7142857 |
2013 | 12 | 6 | 14.8181818 |
2013 | 12 | 7 | 18.8666667 |
2013 | 12 | 8 | 29.4705882 |
2013 | 12 | 9 | 34.5454545 |
2013 | 12 | 10 | 60.3529412 |
2013 | 12 | 11 | 3.4090909 |
2013 | 12 | 12 | 5.3333333 |
2013 | 12 | 13 | -3.0000000 |
2013 | 12 | 14 | 54.6666667 |
2013 | 12 | 15 | 6.6470588 |
2013 | 12 | 16 | -8.1818182 |
2013 | 12 | 17 | 33.4500000 |
2013 | 12 | 18 | 8.4090909 |
2013 | 12 | 19 | -6.6190476 |
2013 | 12 | 20 | 20.1000000 |
2013 | 12 | 21 | 50.1250000 |
2013 | 12 | 22 | 28.3333333 |
2013 | 12 | 23 | 28.8181818 |
2013 | 12 | 24 | 2.3125000 |
2013 | 12 | 25 | 7.5833333 |
2013 | 12 | 26 | -0.4444444 |
2013 | 12 | 27 | 6.1666667 |
2013 | 12 | 28 | 9.5000000 |
2013 | 12 | 29 | 23.6111111 |
2013 | 12 | 30 | 23.6842105 |
2013 | 12 | 31 | -4.9333333 |
Rows
Some important verbs that operate on rows:
filter()
: allows you to keep rows based on the values of the columns without changing their orderarrange()
: changes the order of the rows based on the value of the columns (without changing which are present)
Both functions only affect the rows, and the columns are left unchanged.
distinct()
which finds rows with unique values but unlikearrange()
andfilter()
it can also optionally modify the columns.
filter()
flights |> filter(dep_delay > 1000)
year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 9 | 641 | 900 | 1301 | 1242 | 1530 | 1272 | HA | 51 | N384HA | JFK | HNL | 640 | 4983 | 9 | 0 | 2013-01-09 09:00:00 |
2013 | 1 | 10 | 1121 | 1635 | 1126 | 1239 | 1810 | 1109 | MQ | 3695 | N517MQ | EWR | ORD | 111 | 719 | 16 | 35 | 2013-01-10 16:00:00 |
2013 | 6 | 15 | 1432 | 1935 | 1137 | 1607 | 2120 | 1127 | MQ | 3535 | N504MQ | JFK | CMH | 74 | 483 | 19 | 35 | 2013-06-15 19:00:00 |
2013 | 7 | 22 | 845 | 1600 | 1005 | 1044 | 1815 | 989 | MQ | 3075 | N665MQ | JFK | CVG | 96 | 589 | 16 | 0 | 2013-07-22 16:00:00 |
2013 | 9 | 20 | 1139 | 1845 | 1014 | 1457 | 2210 | 1007 | AA | 177 | N338AA | JFK | SFO | 354 | 2586 | 18 | 45 | 2013-09-20 18:00:00 |
# Flights that departed on January 1
flights |> filter(month==1 & day==1)
year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 1 | 517 | 515 | 2 | 830 | 819 | 11 | UA | 1545 | N14228 | EWR | IAH | 227 | 1400 | 5 | 15 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 533 | 529 | 4 | 850 | 830 | 20 | UA | 1714 | N24211 | LGA | IAH | 227 | 1416 | 5 | 29 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 542 | 540 | 2 | 923 | 850 | 33 | AA | 1141 | N619AA | JFK | MIA | 160 | 1089 | 5 | 40 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 544 | 545 | -1 | 1004 | 1022 | -18 | B6 | 725 | N804JB | JFK | BQN | 183 | 1576 | 5 | 45 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 554 | 600 | -6 | 812 | 837 | -25 | DL | 461 | N668DN | LGA | ATL | 116 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 554 | 558 | -4 | 740 | 728 | 12 | UA | 1696 | N39463 | EWR | ORD | 150 | 719 | 5 | 58 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 555 | 600 | -5 | 913 | 854 | 19 | B6 | 507 | N516JB | EWR | FLL | 158 | 1065 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 709 | 723 | -14 | EV | 5708 | N829AS | LGA | IAD | 53 | 229 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 838 | 846 | -8 | B6 | 79 | N593JB | JFK | MCO | 140 | 944 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 753 | 745 | 8 | AA | 301 | N3ALAA | LGA | ORD | 138 | 733 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 849 | 851 | -2 | B6 | 49 | N793JB | JFK | PBI | 149 | 1028 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 853 | 856 | -3 | B6 | 71 | N657JB | JFK | TPA | 158 | 1005 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 924 | 917 | 7 | UA | 194 | N29129 | JFK | LAX | 345 | 2475 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 923 | 937 | -14 | UA | 1124 | N53441 | EWR | SFO | 361 | 2565 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 941 | 910 | 31 | AA | 707 | N3DUAA | LGA | DFW | 257 | 1389 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 559 | 0 | 702 | 706 | -4 | B6 | 1806 | N708JB | JFK | BOS | 44 | 187 | 5 | 59 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 854 | 902 | -8 | UA | 1187 | N76515 | EWR | LAS | 337 | 2227 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 851 | 858 | -7 | B6 | 371 | N595JB | LGA | FLL | 152 | 1076 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 837 | 825 | 12 | MQ | 4650 | N542MQ | LGA | ATL | 134 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 601 | 600 | 1 | 844 | 850 | -6 | B6 | 343 | N644JB | EWR | PBI | 147 | 1023 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 610 | -8 | 812 | 820 | -8 | DL | 1919 | N971DL | LGA | MSP | 170 | 1020 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 605 | -3 | 821 | 805 | 16 | MQ | 4401 | N730MQ | LGA | DTW | 105 | 502 | 6 | 5 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 858 | 910 | -12 | AA | 1895 | N633AA | EWR | MIA | 152 | 1085 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 837 | 845 | -8 | DL | 1743 | N3739P | JFK | ATL | 128 | 760 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 607 | 607 | 0 | 858 | 915 | -17 | UA | 1077 | N53442 | EWR | MIA | 157 | 1085 | 6 | 7 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 608 | 600 | 8 | 807 | 735 | 32 | MQ | 3768 | N9EAMQ | EWR | ORD | 139 | 719 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 611 | 600 | 11 | 945 | 931 | 14 | UA | 303 | N532UA | JFK | SFO | 366 | 2586 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 613 | 610 | 3 | 925 | 921 | 4 | B6 | 135 | N635JB | JFK | RSW | 175 | 1074 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 1039 | 1100 | -21 | B6 | 709 | N794JB | JFK | SJU | 182 | 1598 | 6 | 15 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 833 | 842 | -9 | DL | 575 | N326NB | EWR | ATL | 120 | 746 | 6 | 15 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2013 | 1 | 1 | 2140 | 2135 | 5 | 210 | 224 | -14 | B6 | 701 | N284JB | JFK | SJU | 189 | 1598 | 21 | 35 | 2013-01-01 21:00:00 |
2013 | 1 | 1 | 2157 | 2155 | 2 | 43 | 41 | 2 | B6 | 43 | N537JB | JFK | MCO | 140 | 944 | 21 | 55 | 2013-01-01 21:00:00 |
2013 | 1 | 1 | 2158 | 2200 | -2 | 2254 | 2307 | -13 | EV | 4103 | N14998 | EWR | BWI | 36 | 169 | 22 | 0 | 2013-01-01 22:00:00 |
2013 | 1 | 1 | 2205 | 1720 | 285 | 46 | 2040 | 246 | AA | 1999 | N5DNAA | EWR | MIA | 146 | 1085 | 17 | 20 | 2013-01-01 17:00:00 |
2013 | 1 | 1 | 2209 | 2145 | 24 | 58 | 37 | 21 | B6 | 35 | N608JB | JFK | PBI | 143 | 1028 | 21 | 45 | 2013-01-01 21:00:00 |
2013 | 1 | 1 | 2209 | 2155 | 14 | 2400 | 2337 | 23 | B6 | 1109 | N216JB | JFK | RDU | 86 | 427 | 21 | 55 | 2013-01-01 21:00:00 |
2013 | 1 | 1 | 2211 | 2145 | 26 | 2339 | 2311 | 28 | B6 | 104 | N228JB | JFK | BUF | 64 | 301 | 21 | 45 | 2013-01-01 21:00:00 |
2013 | 1 | 1 | 2217 | 2229 | -12 | 249 | 315 | -26 | B6 | 713 | N547JB | JFK | SJU | 191 | 1598 | 22 | 29 | 2013-01-01 22:00:00 |
2013 | 1 | 1 | 2217 | 2130 | 47 | 140 | 27 | 73 | B6 | 21 | N516JB | JFK | TPA | 163 | 1005 | 21 | 30 | 2013-01-01 21:00:00 |
2013 | 1 | 1 | 2221 | 2000 | 141 | 2331 | 2124 | 127 | EV | 4462 | N13566 | EWR | BUF | 56 | 282 | 20 | 0 | 2013-01-01 20:00:00 |
2013 | 1 | 1 | 2224 | 2200 | 24 | 2324 | 2316 | 8 | EV | 4206 | N16561 | EWR | PWM | 47 | 284 | 22 | 0 | 2013-01-01 22:00:00 |
2013 | 1 | 1 | 2229 | 2159 | 30 | 149 | 100 | 49 | B6 | 11 | N531JB | JFK | FLL | 153 | 1069 | 21 | 59 | 2013-01-01 21:00:00 |
2013 | 1 | 1 | 2240 | 2245 | -5 | 2340 | 2356 | -16 | B6 | 608 | N279JB | JFK | PWM | 44 | 273 | 22 | 45 | 2013-01-01 22:00:00 |
2013 | 1 | 1 | 2250 | 2255 | -5 | 2352 | 2359 | -7 | B6 | 1018 | N521JB | JFK | BOS | 37 | 187 | 22 | 55 | 2013-01-01 22:00:00 |
2013 | 1 | 1 | 2302 | 2200 | 62 | 2342 | 2253 | 49 | EV | 4276 | N13903 | EWR | BDL | 24 | 116 | 22 | 0 | 2013-01-01 22:00:00 |
2013 | 1 | 1 | 2306 | 2245 | 21 | 28 | 5 | 23 | B6 | 30 | N281JB | JFK | ROC | 59 | 264 | 22 | 45 | 2013-01-01 22:00:00 |
2013 | 1 | 1 | 2307 | 2245 | 22 | 32 | 2357 | 35 | B6 | 128 | N178JB | JFK | BTV | 59 | 266 | 22 | 45 | 2013-01-01 22:00:00 |
2013 | 1 | 1 | 2310 | 2255 | 15 | 24 | 15 | 9 | B6 | 112 | N646JB | JFK | BUF | 57 | 301 | 22 | 55 | 2013-01-01 22:00:00 |
2013 | 1 | 1 | 2312 | 2000 | 192 | 21 | 2110 | 191 | EV | 4312 | N13958 | EWR | DCA | 44 | 199 | 20 | 0 | 2013-01-01 20:00:00 |
2013 | 1 | 1 | 2323 | 2200 | 83 | 22 | 2313 | 69 | EV | 4257 | N13538 | EWR | BTV | 44 | 266 | 22 | 0 | 2013-01-01 22:00:00 |
2013 | 1 | 1 | 2326 | 2130 | 116 | 131 | 18 | 73 | B6 | 199 | N594JB | JFK | LAS | 290 | 2248 | 21 | 30 | 2013-01-01 21:00:00 |
2013 | 1 | 1 | 2327 | 2250 | 37 | 32 | 2359 | 33 | B6 | 22 | N639JB | JFK | SYR | 45 | 209 | 22 | 50 | 2013-01-01 22:00:00 |
2013 | 1 | 1 | 2343 | 1724 | 379 | 314 | 1938 | 456 | EV | 4321 | N21197 | EWR | MCI | 222 | 1092 | 17 | 24 | 2013-01-01 17:00:00 |
2013 | 1 | 1 | 2353 | 2359 | -6 | 425 | 445 | -20 | B6 | 739 | N591JB | JFK | PSE | 195 | 1617 | 23 | 59 | 2013-01-01 23:00:00 |
2013 | 1 | 1 | 2353 | 2359 | -6 | 418 | 442 | -24 | B6 | 707 | N794JB | JFK | SJU | 185 | 1598 | 23 | 59 | 2013-01-01 23:00:00 |
2013 | 1 | 1 | 2356 | 2359 | -3 | 425 | 437 | -12 | B6 | 727 | N588JB | JFK | BQN | 186 | 1576 | 23 | 59 | 2013-01-01 23:00:00 |
2013 | 1 | 1 | NA | 1630 | NA | NA | 1815 | NA | EV | 4308 | N18120 | EWR | RDU | NA | 416 | 16 | 30 | 2013-01-01 16:00:00 |
2013 | 1 | 1 | NA | 1935 | NA | NA | 2240 | NA | AA | 791 | N3EHAA | LGA | DFW | NA | 1389 | 19 | 35 | 2013-01-01 19:00:00 |
2013 | 1 | 1 | NA | 1500 | NA | NA | 1825 | NA | AA | 1925 | N3EVAA | LGA | MIA | NA | 1096 | 15 | 0 | 2013-01-01 15:00:00 |
2013 | 1 | 1 | NA | 600 | NA | NA | 901 | NA | B6 | 125 | N618JB | JFK | FLL | NA | 1069 | 6 | 0 | 2013-01-01 06:00:00 |
# A shorter way to select flights that departed in January or February
flights |>
filter(month %in% c(1, 2))
# the same as filter(month==1 | month==2)
# but not filter(month == 1 | 2) - error!
year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 1 | 517 | 515 | 2 | 830 | 819 | 11 | UA | 1545 | N14228 | EWR | IAH | 227 | 1400 | 5 | 15 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 533 | 529 | 4 | 850 | 830 | 20 | UA | 1714 | N24211 | LGA | IAH | 227 | 1416 | 5 | 29 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 542 | 540 | 2 | 923 | 850 | 33 | AA | 1141 | N619AA | JFK | MIA | 160 | 1089 | 5 | 40 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 544 | 545 | -1 | 1004 | 1022 | -18 | B6 | 725 | N804JB | JFK | BQN | 183 | 1576 | 5 | 45 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 554 | 600 | -6 | 812 | 837 | -25 | DL | 461 | N668DN | LGA | ATL | 116 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 554 | 558 | -4 | 740 | 728 | 12 | UA | 1696 | N39463 | EWR | ORD | 150 | 719 | 5 | 58 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 555 | 600 | -5 | 913 | 854 | 19 | B6 | 507 | N516JB | EWR | FLL | 158 | 1065 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 709 | 723 | -14 | EV | 5708 | N829AS | LGA | IAD | 53 | 229 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 838 | 846 | -8 | B6 | 79 | N593JB | JFK | MCO | 140 | 944 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 753 | 745 | 8 | AA | 301 | N3ALAA | LGA | ORD | 138 | 733 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 849 | 851 | -2 | B6 | 49 | N793JB | JFK | PBI | 149 | 1028 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 853 | 856 | -3 | B6 | 71 | N657JB | JFK | TPA | 158 | 1005 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 924 | 917 | 7 | UA | 194 | N29129 | JFK | LAX | 345 | 2475 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 923 | 937 | -14 | UA | 1124 | N53441 | EWR | SFO | 361 | 2565 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 941 | 910 | 31 | AA | 707 | N3DUAA | LGA | DFW | 257 | 1389 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 559 | 0 | 702 | 706 | -4 | B6 | 1806 | N708JB | JFK | BOS | 44 | 187 | 5 | 59 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 854 | 902 | -8 | UA | 1187 | N76515 | EWR | LAS | 337 | 2227 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 851 | 858 | -7 | B6 | 371 | N595JB | LGA | FLL | 152 | 1076 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 837 | 825 | 12 | MQ | 4650 | N542MQ | LGA | ATL | 134 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 601 | 600 | 1 | 844 | 850 | -6 | B6 | 343 | N644JB | EWR | PBI | 147 | 1023 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 610 | -8 | 812 | 820 | -8 | DL | 1919 | N971DL | LGA | MSP | 170 | 1020 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 605 | -3 | 821 | 805 | 16 | MQ | 4401 | N730MQ | LGA | DTW | 105 | 502 | 6 | 5 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 858 | 910 | -12 | AA | 1895 | N633AA | EWR | MIA | 152 | 1085 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 837 | 845 | -8 | DL | 1743 | N3739P | JFK | ATL | 128 | 760 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 607 | 607 | 0 | 858 | 915 | -17 | UA | 1077 | N53442 | EWR | MIA | 157 | 1085 | 6 | 7 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 608 | 600 | 8 | 807 | 735 | 32 | MQ | 3768 | N9EAMQ | EWR | ORD | 139 | 719 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 611 | 600 | 11 | 945 | 931 | 14 | UA | 303 | N532UA | JFK | SFO | 366 | 2586 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 613 | 610 | 3 | 925 | 921 | 4 | B6 | 135 | N635JB | JFK | RSW | 175 | 1074 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 1039 | 1100 | -21 | B6 | 709 | N794JB | JFK | SJU | 182 | 1598 | 6 | 15 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 833 | 842 | -9 | DL | 575 | N326NB | EWR | ATL | 120 | 746 | 6 | 15 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2013 | 2 | 28 | 2157 | 2007 | 110 | 2344 | 2206 | 98 | EV | 4572 | N29906 | EWR | GSP | 93 | 594 | 20 | 7 | 2013-02-28 20:00:00 |
2013 | 2 | 28 | 2158 | 1910 | 168 | 19 | 2215 | 124 | AA | 2075 | N4YSAA | EWR | DFW | 182 | 1372 | 19 | 10 | 2013-02-28 19:00:00 |
2013 | 2 | 28 | 2158 | 2145 | 13 | 49 | 34 | 15 | B6 | 35 | N708JB | JFK | PBI | 151 | 1028 | 21 | 45 | 2013-02-28 21:00:00 |
2013 | 2 | 28 | 2201 | 2155 | 6 | 59 | 41 | 18 | B6 | 43 | N579JB | JFK | MCO | 149 | 944 | 21 | 55 | 2013-02-28 21:00:00 |
2013 | 2 | 28 | 2205 | 2045 | 80 | 2304 | 2216 | 48 | 9E | 3395 | N916XJ | JFK | DCA | 38 | 213 | 20 | 45 | 2013-02-28 20:00:00 |
2013 | 2 | 28 | 2205 | 2159 | 6 | 106 | 56 | 10 | B6 | 11 | N554JB | JFK | FLL | 158 | 1069 | 21 | 59 | 2013-02-28 21:00:00 |
2013 | 2 | 28 | 2218 | 2150 | 28 | 115 | 42 | 33 | B6 | 325 | N504JB | JFK | TPA | 154 | 1005 | 21 | 50 | 2013-02-28 21:00:00 |
2013 | 2 | 28 | 2223 | 2023 | 120 | 252 | 114 | 98 | UA | 1071 | N37298 | EWR | BQN | 188 | 1585 | 20 | 23 | 2013-02-28 20:00:00 |
2013 | 2 | 28 | 2226 | 2029 | 117 | 115 | 2333 | 102 | UA | 771 | N560UA | JFK | LAX | 313 | 2475 | 20 | 29 | 2013-02-28 20:00:00 |
2013 | 2 | 28 | 2229 | 2230 | -1 | 258 | 312 | -14 | B6 | 713 | N523JB | JFK | SJU | 193 | 1598 | 22 | 30 | 2013-02-28 22:00:00 |
2013 | 2 | 28 | 2239 | 2245 | -6 | 2339 | 2354 | -15 | B6 | 608 | N197JB | JFK | PWM | 44 | 273 | 22 | 45 | 2013-02-28 22:00:00 |
2013 | 2 | 28 | 2242 | 2250 | -8 | 2350 | 5 | -15 | B6 | 30 | N351JB | JFK | ROC | 51 | 264 | 22 | 50 | 2013-02-28 22:00:00 |
2013 | 2 | 28 | 2245 | 2245 | 0 | 5 | 2356 | 9 | B6 | 128 | N184JB | JFK | BTV | 48 | 266 | 22 | 45 | 2013-02-28 22:00:00 |
2013 | 2 | 28 | 2254 | 2258 | -4 | 10 | 19 | -9 | B6 | 112 | N655JB | JFK | BUF | 53 | 301 | 22 | 58 | 2013-02-28 22:00:00 |
2013 | 2 | 28 | 2257 | 2140 | 77 | 2338 | 2241 | 57 | EV | 4276 | N12567 | EWR | BDL | 24 | 116 | 21 | 40 | 2013-02-28 21:00:00 |
2013 | 2 | 28 | 2257 | 2255 | 2 | 2400 | 2357 | 3 | B6 | 1018 | N807JB | JFK | BOS | 35 | 187 | 22 | 55 | 2013-02-28 22:00:00 |
2013 | 2 | 28 | 2323 | 2251 | 32 | 18 | 2357 | 21 | B6 | 22 | N279JB | JFK | SYR | 40 | 209 | 22 | 51 | 2013-02-28 22:00:00 |
2013 | 2 | 28 | 2342 | 2352 | -10 | 413 | 437 | -24 | B6 | 739 | N656JB | JFK | PSE | 193 | 1617 | 23 | 52 | 2013-02-28 23:00:00 |
2013 | 2 | 28 | 2356 | 2358 | -2 | 423 | 438 | -15 | B6 | 707 | N646JB | JFK | SJU | 192 | 1598 | 23 | 58 | 2013-02-28 23:00:00 |
2013 | 2 | 28 | 2359 | 2359 | 0 | 443 | 438 | 5 | B6 | 727 | N641JB | JFK | BQN | 192 | 1576 | 23 | 59 | 2013-02-28 23:00:00 |
2013 | 2 | 28 | NA | 600 | NA | NA | 722 | NA | EV | 5739 | N833AS | LGA | IAD | NA | 229 | 6 | 0 | 2013-02-28 06:00:00 |
2013 | 2 | 28 | NA | 1820 | NA | NA | 2003 | NA | EV | 5409 | N740EV | LGA | MSN | NA | 812 | 18 | 20 | 2013-02-28 18:00:00 |
2013 | 2 | 28 | NA | 1154 | NA | NA | 1447 | NA | B6 | 27 | N274JB | JFK | TPA | NA | 1005 | 11 | 54 | 2013-02-28 11:00:00 |
2013 | 2 | 28 | NA | 900 | NA | NA | 1020 | NA | US | 2120 | NA | LGA | BOS | NA | 184 | 9 | 0 | 2013-02-28 09:00:00 |
2013 | 2 | 28 | NA | 605 | NA | NA | 805 | NA | MQ | 4401 | N730MQ | LGA | DTW | NA | 502 | 6 | 5 | 2013-02-28 06:00:00 |
2013 | 2 | 28 | NA | 850 | NA | NA | 1035 | NA | MQ | 4558 | N737MQ | LGA | CLE | NA | 419 | 8 | 50 | 2013-02-28 08:00:00 |
2013 | 2 | 28 | NA | 905 | NA | NA | 1115 | NA | MQ | 4478 | N722MQ | LGA | DTW | NA | 502 | 9 | 5 | 2013-02-28 09:00:00 |
2013 | 2 | 28 | NA | 1115 | NA | NA | 1310 | NA | MQ | 4485 | N725MQ | LGA | CMH | NA | 479 | 11 | 15 | 2013-02-28 11:00:00 |
2013 | 2 | 28 | NA | 830 | NA | NA | 1205 | NA | UA | 1480 | NA | EWR | SFO | NA | 2565 | 8 | 30 | 2013-02-28 08:00:00 |
2013 | 2 | 28 | NA | 840 | NA | NA | 1147 | NA | UA | 443 | NA | JFK | LAX | NA | 2475 | 8 | 40 | 2013-02-28 08:00:00 |
arrange()
flights |> arrange(year, month, day, dep_time)
year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 1 | 517 | 515 | 2 | 830 | 819 | 11 | UA | 1545 | N14228 | EWR | IAH | 227 | 1400 | 5 | 15 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 533 | 529 | 4 | 850 | 830 | 20 | UA | 1714 | N24211 | LGA | IAH | 227 | 1416 | 5 | 29 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 542 | 540 | 2 | 923 | 850 | 33 | AA | 1141 | N619AA | JFK | MIA | 160 | 1089 | 5 | 40 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 544 | 545 | -1 | 1004 | 1022 | -18 | B6 | 725 | N804JB | JFK | BQN | 183 | 1576 | 5 | 45 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 554 | 600 | -6 | 812 | 837 | -25 | DL | 461 | N668DN | LGA | ATL | 116 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 554 | 558 | -4 | 740 | 728 | 12 | UA | 1696 | N39463 | EWR | ORD | 150 | 719 | 5 | 58 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 555 | 600 | -5 | 913 | 854 | 19 | B6 | 507 | N516JB | EWR | FLL | 158 | 1065 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 709 | 723 | -14 | EV | 5708 | N829AS | LGA | IAD | 53 | 229 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 838 | 846 | -8 | B6 | 79 | N593JB | JFK | MCO | 140 | 944 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 753 | 745 | 8 | AA | 301 | N3ALAA | LGA | ORD | 138 | 733 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 849 | 851 | -2 | B6 | 49 | N793JB | JFK | PBI | 149 | 1028 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 853 | 856 | -3 | B6 | 71 | N657JB | JFK | TPA | 158 | 1005 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 924 | 917 | 7 | UA | 194 | N29129 | JFK | LAX | 345 | 2475 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 923 | 937 | -14 | UA | 1124 | N53441 | EWR | SFO | 361 | 2565 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 941 | 910 | 31 | AA | 707 | N3DUAA | LGA | DFW | 257 | 1389 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 559 | 0 | 702 | 706 | -4 | B6 | 1806 | N708JB | JFK | BOS | 44 | 187 | 5 | 59 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 854 | 902 | -8 | UA | 1187 | N76515 | EWR | LAS | 337 | 2227 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 851 | 858 | -7 | B6 | 371 | N595JB | LGA | FLL | 152 | 1076 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 837 | 825 | 12 | MQ | 4650 | N542MQ | LGA | ATL | 134 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 601 | 600 | 1 | 844 | 850 | -6 | B6 | 343 | N644JB | EWR | PBI | 147 | 1023 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 610 | -8 | 812 | 820 | -8 | DL | 1919 | N971DL | LGA | MSP | 170 | 1020 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 605 | -3 | 821 | 805 | 16 | MQ | 4401 | N730MQ | LGA | DTW | 105 | 502 | 6 | 5 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 858 | 910 | -12 | AA | 1895 | N633AA | EWR | MIA | 152 | 1085 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 837 | 845 | -8 | DL | 1743 | N3739P | JFK | ATL | 128 | 760 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 607 | 607 | 0 | 858 | 915 | -17 | UA | 1077 | N53442 | EWR | MIA | 157 | 1085 | 6 | 7 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 608 | 600 | 8 | 807 | 735 | 32 | MQ | 3768 | N9EAMQ | EWR | ORD | 139 | 719 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 611 | 600 | 11 | 945 | 931 | 14 | UA | 303 | N532UA | JFK | SFO | 366 | 2586 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 613 | 610 | 3 | 925 | 921 | 4 | B6 | 135 | N635JB | JFK | RSW | 175 | 1074 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 1039 | 1100 | -21 | B6 | 709 | N794JB | JFK | SJU | 182 | 1598 | 6 | 15 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 833 | 842 | -9 | DL | 575 | N326NB | EWR | ATL | 120 | 746 | 6 | 15 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2013 | 12 | 31 | 2155 | 2039 | 76 | 253 | 2355 | NA | B6 | 1205 | N627JB | JFK | PDX | NA | 2454 | 20 | 39 | 2013-12-31 20:00:00 |
2013 | 12 | 31 | 2155 | 2150 | 5 | 110 | 51 | 19 | B6 | 1901 | N729JB | JFK | FLL | 164 | 1069 | 21 | 50 | 2013-12-31 21:00:00 |
2013 | 12 | 31 | 2159 | 2155 | 4 | 55 | 46 | 9 | B6 | 2053 | N593JB | JFK | PBI | 155 | 1028 | 21 | 55 | 2013-12-31 21:00:00 |
2013 | 12 | 31 | 2206 | 2110 | 56 | 44 | 2339 | 65 | B6 | 775 | N184JB | JFK | MSY | 195 | 1182 | 21 | 10 | 2013-12-31 21:00:00 |
2013 | 12 | 31 | 2211 | 2159 | 12 | 100 | 45 | 15 | B6 | 1183 | N715JB | JFK | MCO | 148 | 944 | 21 | 59 | 2013-12-31 21:00:00 |
2013 | 12 | 31 | 2218 | 2219 | -1 | 315 | 304 | 11 | B6 | 1203 | N625JB | JFK | SJU | 202 | 1598 | 22 | 19 | 2013-12-31 22:00:00 |
2013 | 12 | 31 | 2235 | 2245 | -10 | 2351 | 2355 | -4 | B6 | 234 | N355JB | JFK | BTV | 49 | 266 | 22 | 45 | 2013-12-31 22:00:00 |
2013 | 12 | 31 | 2245 | 2250 | -5 | 2359 | 2356 | 3 | B6 | 1816 | N318JB | JFK | SYR | 51 | 209 | 22 | 50 | 2013-12-31 22:00:00 |
2013 | 12 | 31 | 2310 | 2255 | 15 | 7 | 2356 | 11 | B6 | 718 | N279JB | JFK | BOS | 40 | 187 | 22 | 55 | 2013-12-31 22:00:00 |
2013 | 12 | 31 | 2321 | 2250 | 31 | 46 | 8 | 38 | B6 | 2002 | N179JB | JFK | BUF | 66 | 301 | 22 | 50 | 2013-12-31 22:00:00 |
2013 | 12 | 31 | 2328 | 2330 | -2 | 412 | 409 | 3 | B6 | 1389 | N651JB | EWR | SJU | 198 | 1608 | 23 | 30 | 2013-12-31 23:00:00 |
2013 | 12 | 31 | 2332 | 2245 | 47 | 58 | 3 | 55 | B6 | 486 | N334JB | JFK | ROC | 60 | 264 | 22 | 45 | 2013-12-31 22:00:00 |
2013 | 12 | 31 | 2355 | 2359 | -4 | 430 | 440 | -10 | B6 | 1503 | N509JB | JFK | SJU | 195 | 1598 | 23 | 59 | 2013-12-31 23:00:00 |
2013 | 12 | 31 | 2356 | 2359 | -3 | 436 | 445 | -9 | B6 | 745 | N665JB | JFK | PSE | 200 | 1617 | 23 | 59 | 2013-12-31 23:00:00 |
2013 | 12 | 31 | NA | 1520 | NA | NA | 1705 | NA | AA | 341 | N568AA | LGA | ORD | NA | 733 | 15 | 20 | 2013-12-31 15:00:00 |
2013 | 12 | 31 | NA | 2025 | NA | NA | 2205 | NA | AA | 371 | N482AA | LGA | ORD | NA | 733 | 20 | 25 | 2013-12-31 20:00:00 |
2013 | 12 | 31 | NA | 1932 | NA | NA | 2305 | NA | B6 | 161 | N516JB | JFK | SMF | NA | 2521 | 19 | 32 | 2013-12-31 19:00:00 |
2013 | 12 | 31 | NA | 1505 | NA | NA | 1725 | NA | EV | 4181 | N24103 | EWR | MCI | NA | 1092 | 15 | 5 | 2013-12-31 15:00:00 |
2013 | 12 | 31 | NA | 1000 | NA | NA | 1252 | NA | UA | 1124 | NA | EWR | EGE | NA | 1725 | 10 | 0 | 2013-12-31 10:00:00 |
2013 | 12 | 31 | NA | 840 | NA | NA | 1205 | NA | UA | 1151 | NA | EWR | SEA | NA | 2402 | 8 | 40 | 2013-12-31 08:00:00 |
2013 | 12 | 31 | NA | 754 | NA | NA | 1118 | NA | UA | 1455 | NA | EWR | LAX | NA | 2454 | 7 | 54 | 2013-12-31 07:00:00 |
2013 | 12 | 31 | NA | 2000 | NA | NA | 2146 | NA | UA | 1482 | NA | EWR | ORD | NA | 719 | 20 | 0 | 2013-12-31 20:00:00 |
2013 | 12 | 31 | NA | 1500 | NA | NA | 1817 | NA | UA | 1483 | NA | EWR | AUS | NA | 1504 | 15 | 0 | 2013-12-31 15:00:00 |
2013 | 12 | 31 | NA | 1430 | NA | NA | 1750 | NA | UA | 1493 | NA | EWR | LAX | NA | 2454 | 14 | 30 | 2013-12-31 14:00:00 |
2013 | 12 | 31 | NA | 855 | NA | NA | 1142 | NA | UA | 1506 | NA | EWR | JAC | NA | 1874 | 8 | 55 | 2013-12-31 08:00:00 |
2013 | 12 | 31 | NA | 705 | NA | NA | 931 | NA | UA | 1729 | NA | EWR | DEN | NA | 1605 | 7 | 5 | 2013-12-31 07:00:00 |
2013 | 12 | 31 | NA | 825 | NA | NA | 1029 | NA | US | 1831 | NA | JFK | CLT | NA | 541 | 8 | 25 | 2013-12-31 08:00:00 |
2013 | 12 | 31 | NA | 1615 | NA | NA | 1800 | NA | MQ | 3301 | N844MQ | LGA | RDU | NA | 431 | 16 | 15 | 2013-12-31 16:00:00 |
2013 | 12 | 31 | NA | 600 | NA | NA | 735 | NA | UA | 219 | NA | EWR | ORD | NA | 719 | 6 | 0 | 2013-12-31 06:00:00 |
2013 | 12 | 31 | NA | 830 | NA | NA | 1154 | NA | UA | 443 | NA | JFK | LAX | NA | 2475 | 8 | 30 | 2013-12-31 08:00:00 |
flights |> arrange(desc(dep_delay))
year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 9 | 641 | 900 | 1301 | 1242 | 1530 | 1272 | HA | 51 | N384HA | JFK | HNL | 640 | 4983 | 9 | 0 | 2013-01-09 09:00:00 |
2013 | 6 | 15 | 1432 | 1935 | 1137 | 1607 | 2120 | 1127 | MQ | 3535 | N504MQ | JFK | CMH | 74 | 483 | 19 | 35 | 2013-06-15 19:00:00 |
2013 | 1 | 10 | 1121 | 1635 | 1126 | 1239 | 1810 | 1109 | MQ | 3695 | N517MQ | EWR | ORD | 111 | 719 | 16 | 35 | 2013-01-10 16:00:00 |
2013 | 9 | 20 | 1139 | 1845 | 1014 | 1457 | 2210 | 1007 | AA | 177 | N338AA | JFK | SFO | 354 | 2586 | 18 | 45 | 2013-09-20 18:00:00 |
2013 | 7 | 22 | 845 | 1600 | 1005 | 1044 | 1815 | 989 | MQ | 3075 | N665MQ | JFK | CVG | 96 | 589 | 16 | 0 | 2013-07-22 16:00:00 |
2013 | 4 | 10 | 1100 | 1900 | 960 | 1342 | 2211 | 931 | DL | 2391 | N959DL | JFK | TPA | 139 | 1005 | 19 | 0 | 2013-04-10 19:00:00 |
2013 | 3 | 17 | 2321 | 810 | 911 | 135 | 1020 | 915 | DL | 2119 | N927DA | LGA | MSP | 167 | 1020 | 8 | 10 | 2013-03-17 08:00:00 |
2013 | 6 | 27 | 959 | 1900 | 899 | 1236 | 2226 | 850 | DL | 2007 | N3762Y | JFK | PDX | 313 | 2454 | 19 | 0 | 2013-06-27 19:00:00 |
2013 | 7 | 22 | 2257 | 759 | 898 | 121 | 1026 | 895 | DL | 2047 | N6716C | LGA | ATL | 109 | 762 | 7 | 59 | 2013-07-22 07:00:00 |
2013 | 12 | 5 | 756 | 1700 | 896 | 1058 | 2020 | 878 | AA | 172 | N5DMAA | EWR | MIA | 149 | 1085 | 17 | 0 | 2013-12-05 17:00:00 |
2013 | 5 | 3 | 1133 | 2055 | 878 | 1250 | 2215 | 875 | MQ | 3744 | N523MQ | EWR | ORD | 112 | 719 | 20 | 55 | 2013-05-03 20:00:00 |
2013 | 1 | 1 | 848 | 1835 | 853 | 1001 | 1950 | 851 | MQ | 3944 | N942MQ | JFK | BWI | 41 | 184 | 18 | 35 | 2013-01-01 18:00:00 |
2013 | 2 | 10 | 2243 | 830 | 853 | 100 | 1106 | 834 | F9 | 835 | N203FR | LGA | DEN | 233 | 1620 | 8 | 30 | 2013-02-10 08:00:00 |
2013 | 5 | 19 | 713 | 1700 | 853 | 1007 | 1955 | 852 | AA | 257 | N3HEAA | JFK | LAS | 323 | 2248 | 17 | 0 | 2013-05-19 17:00:00 |
2013 | 12 | 19 | 734 | 1725 | 849 | 1046 | 2039 | 847 | DL | 1223 | N375NC | EWR | SLC | 290 | 1969 | 17 | 25 | 2013-12-19 17:00:00 |
2013 | 12 | 17 | 705 | 1700 | 845 | 1026 | 2020 | 846 | AA | 172 | N5EMAA | EWR | MIA | 145 | 1085 | 17 | 0 | 2013-12-17 17:00:00 |
2013 | 12 | 14 | 830 | 1845 | 825 | 1210 | 2154 | 856 | DL | 2391 | N939DL | JFK | TPA | 173 | 1005 | 18 | 45 | 2013-12-14 18:00:00 |
2013 | 4 | 19 | 912 | 1940 | 812 | 1228 | 2247 | 821 | DL | 1435 | N900DE | LGA | TPA | 174 | 1010 | 19 | 40 | 2013-04-19 19:00:00 |
2013 | 6 | 27 | 753 | 1830 | 803 | 937 | 2015 | 802 | AA | 2019 | N571AA | LGA | STL | 134 | 888 | 18 | 30 | 2013-06-27 18:00:00 |
2013 | 3 | 18 | 1020 | 2100 | 800 | 1336 | 32 | 784 | DL | 2363 | N624AG | JFK | LAX | 335 | 2475 | 21 | 0 | 2013-03-18 21:00:00 |
2013 | 11 | 3 | 603 | 1645 | 798 | 829 | 1913 | 796 | DL | 2042 | N990AT | EWR | ATL | 109 | 746 | 16 | 45 | 2013-11-03 16:00:00 |
2013 | 4 | 19 | 617 | 1700 | 797 | 858 | 1955 | 783 | AA | 257 | N3GJAA | JFK | LAS | 313 | 2248 | 17 | 0 | 2013-04-19 17:00:00 |
2013 | 6 | 27 | 615 | 1705 | 790 | 853 | 2004 | 769 | DL | 503 | N372DA | JFK | SAN | 312 | 2446 | 17 | 5 | 2013-06-27 17:00:00 |
2013 | 2 | 19 | 2324 | 1016 | 788 | 114 | 1227 | 767 | DL | 2319 | N324US | LGA | MSP | 136 | 1020 | 10 | 16 | 2013-02-19 10:00:00 |
2013 | 6 | 27 | 732 | 1825 | 787 | 932 | 2032 | 780 | DL | 1715 | N335NB | LGA | MSY | 160 | 1183 | 18 | 25 | 2013-06-27 18:00:00 |
2013 | 2 | 24 | 1921 | 615 | 786 | 2135 | 842 | 773 | DL | 575 | N348NW | EWR | ATL | 111 | 746 | 6 | 15 | 2013-02-24 06:00:00 |
2013 | 4 | 19 | 606 | 1725 | 761 | 923 | 2020 | 783 | AA | 1901 | N3DGAA | JFK | IAH | 222 | 1417 | 17 | 25 | 2013-04-19 17:00:00 |
2013 | 4 | 19 | 758 | 1925 | 753 | 1049 | 2225 | 744 | DL | 1485 | N927DA | LGA | MCO | 149 | 950 | 19 | 25 | 2013-04-19 19:00:00 |
2013 | 2 | 16 | 757 | 1930 | 747 | 1013 | 2149 | 744 | 9E | 3798 | N8940E | JFK | CLT | 85 | 541 | 19 | 30 | 2013-02-16 19:00:00 |
2013 | 10 | 14 | 2042 | 900 | 702 | 2255 | 1127 | 688 | DL | 502 | N943DL | EWR | ATL | 98 | 746 | 9 | 0 | 2013-10-14 09:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2013 | 9 | 24 | NA | 1625 | NA | NA | 1750 | NA | MQ | 3622 | N524MQ | LGA | BNA | NA | 764 | 16 | 25 | 2013-09-24 16:00:00 |
2013 | 9 | 25 | NA | 1259 | NA | NA | 1507 | NA | EV | 5207 | N615QX | LGA | CLT | NA | 544 | 12 | 59 | 2013-09-25 12:00:00 |
2013 | 9 | 25 | NA | 845 | NA | NA | 1018 | NA | EV | 5286 | N615QX | LGA | BTV | NA | 258 | 8 | 45 | 2013-09-25 08:00:00 |
2013 | 9 | 25 | NA | 1755 | NA | NA | 1932 | NA | EV | 5287 | N722EV | LGA | MSN | NA | 812 | 17 | 55 | 2013-09-25 17:00:00 |
2013 | 9 | 25 | NA | 600 | NA | NA | 716 | NA | EV | 5716 | N877AS | JFK | IAD | NA | 228 | 6 | 0 | 2013-09-25 06:00:00 |
2013 | 9 | 25 | NA | 836 | NA | NA | 944 | NA | B6 | 2280 | N258JB | EWR | BOS | NA | 200 | 8 | 36 | 2013-09-25 08:00:00 |
2013 | 9 | 25 | NA | 1300 | NA | NA | 1409 | NA | US | 2148 | NA | LGA | BOS | NA | 184 | 13 | 0 | 2013-09-25 13:00:00 |
2013 | 9 | 25 | NA | 1900 | NA | NA | 2014 | NA | US | 2160 | NA | LGA | BOS | NA | 184 | 19 | 0 | 2013-09-25 19:00:00 |
2013 | 9 | 25 | NA | 1300 | NA | NA | 1450 | NA | MQ | 3388 | N817MQ | LGA | CMH | NA | 479 | 13 | 0 | 2013-09-25 13:00:00 |
2013 | 9 | 25 | NA | 1655 | NA | NA | 1840 | NA | MQ | 3411 | N735MQ | LGA | RDU | NA | 431 | 16 | 55 | 2013-09-25 16:00:00 |
2013 | 9 | 25 | NA | 1559 | NA | NA | 1719 | NA | MQ | 3748 | N530MQ | EWR | ORD | NA | 719 | 15 | 59 | 2013-09-25 15:00:00 |
2013 | 9 | 26 | NA | 915 | NA | NA | 1141 | NA | EV | 5109 | N748EV | LGA | CHS | NA | 641 | 9 | 15 | 2013-09-26 09:00:00 |
2013 | 9 | 26 | NA | 1400 | NA | NA | 1512 | NA | US | 2183 | NA | LGA | DCA | NA | 214 | 14 | 0 | 2013-09-26 14:00:00 |
2013 | 9 | 26 | NA | 1240 | NA | NA | 1525 | NA | WN | 4720 | N691WN | EWR | HOU | NA | 1411 | 12 | 40 | 2013-09-26 12:00:00 |
2013 | 9 | 27 | NA | 600 | NA | NA | 730 | NA | AA | 301 | N584AA | LGA | ORD | NA | 733 | 6 | 0 | 2013-09-27 06:00:00 |
2013 | 9 | 27 | NA | 2100 | NA | NA | 2211 | NA | US | 2164 | NA | LGA | BOS | NA | 184 | 21 | 0 | 2013-09-27 21:00:00 |
2013 | 9 | 27 | NA | 1329 | NA | NA | 1444 | NA | MQ | 3760 | N505MQ | EWR | ORD | NA | 719 | 13 | 29 | 2013-09-27 13:00:00 |
2013 | 9 | 27 | NA | 1600 | NA | NA | 1739 | NA | UA | 269 | NA | LGA | ORD | NA | 733 | 16 | 0 | 2013-09-27 16:00:00 |
2013 | 9 | 28 | NA | 1803 | NA | NA | 1927 | NA | EV | 5563 | N724EV | LGA | BTV | NA | 258 | 18 | 3 | 2013-09-28 18:00:00 |
2013 | 9 | 28 | NA | 910 | NA | NA | 1220 | NA | AA | 1 | N320AA | JFK | LAX | NA | 2475 | 9 | 10 | 2013-09-28 09:00:00 |
2013 | 9 | 28 | NA | 1635 | NA | NA | 1827 | NA | US | 581 | NA | EWR | CLT | NA | 529 | 16 | 35 | 2013-09-28 16:00:00 |
2013 | 9 | 29 | NA | 2054 | NA | NA | 2302 | NA | EV | 4536 | N13988 | EWR | CVG | NA | 569 | 20 | 54 | 2013-09-29 20:00:00 |
2013 | 9 | 29 | NA | 1830 | NA | NA | 2010 | NA | MQ | 3134 | N508MQ | EWR | ORD | NA | 719 | 18 | 30 | 2013-09-29 18:00:00 |
2013 | 9 | 29 | NA | 700 | NA | NA | 833 | NA | UA | 331 | NA | LGA | ORD | NA | 733 | 7 | 0 | 2013-09-29 07:00:00 |
2013 | 9 | 30 | NA | 1842 | NA | NA | 2019 | NA | EV | 5274 | N740EV | LGA | BNA | NA | 764 | 18 | 42 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | NA | 1455 | NA | NA | 1634 | NA | 9E | 3393 | NA | JFK | DCA | NA | 213 | 14 | 55 | 2013-09-30 14:00:00 |
2013 | 9 | 30 | NA | 2200 | NA | NA | 2312 | NA | 9E | 3525 | NA | LGA | SYR | NA | 198 | 22 | 0 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | NA | 1210 | NA | NA | 1330 | NA | MQ | 3461 | N535MQ | LGA | BNA | NA | 764 | 12 | 10 | 2013-09-30 12:00:00 |
2013 | 9 | 30 | NA | 1159 | NA | NA | 1344 | NA | MQ | 3572 | N511MQ | LGA | CLE | NA | 419 | 11 | 59 | 2013-09-30 11:00:00 |
2013 | 9 | 30 | NA | 840 | NA | NA | 1020 | NA | MQ | 3531 | N839MQ | LGA | RDU | NA | 431 | 8 | 40 | 2013-09-30 08:00:00 |
distinct()
# Remove duplicate rows, if any
flights |>
distinct()
year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 1 | 517 | 515 | 2 | 830 | 819 | 11 | UA | 1545 | N14228 | EWR | IAH | 227 | 1400 | 5 | 15 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 533 | 529 | 4 | 850 | 830 | 20 | UA | 1714 | N24211 | LGA | IAH | 227 | 1416 | 5 | 29 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 542 | 540 | 2 | 923 | 850 | 33 | AA | 1141 | N619AA | JFK | MIA | 160 | 1089 | 5 | 40 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 544 | 545 | -1 | 1004 | 1022 | -18 | B6 | 725 | N804JB | JFK | BQN | 183 | 1576 | 5 | 45 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 554 | 600 | -6 | 812 | 837 | -25 | DL | 461 | N668DN | LGA | ATL | 116 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 554 | 558 | -4 | 740 | 728 | 12 | UA | 1696 | N39463 | EWR | ORD | 150 | 719 | 5 | 58 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 555 | 600 | -5 | 913 | 854 | 19 | B6 | 507 | N516JB | EWR | FLL | 158 | 1065 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 709 | 723 | -14 | EV | 5708 | N829AS | LGA | IAD | 53 | 229 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 838 | 846 | -8 | B6 | 79 | N593JB | JFK | MCO | 140 | 944 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 753 | 745 | 8 | AA | 301 | N3ALAA | LGA | ORD | 138 | 733 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 849 | 851 | -2 | B6 | 49 | N793JB | JFK | PBI | 149 | 1028 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 853 | 856 | -3 | B6 | 71 | N657JB | JFK | TPA | 158 | 1005 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 924 | 917 | 7 | UA | 194 | N29129 | JFK | LAX | 345 | 2475 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 923 | 937 | -14 | UA | 1124 | N53441 | EWR | SFO | 361 | 2565 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 941 | 910 | 31 | AA | 707 | N3DUAA | LGA | DFW | 257 | 1389 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 559 | 0 | 702 | 706 | -4 | B6 | 1806 | N708JB | JFK | BOS | 44 | 187 | 5 | 59 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 854 | 902 | -8 | UA | 1187 | N76515 | EWR | LAS | 337 | 2227 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 851 | 858 | -7 | B6 | 371 | N595JB | LGA | FLL | 152 | 1076 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 837 | 825 | 12 | MQ | 4650 | N542MQ | LGA | ATL | 134 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 601 | 600 | 1 | 844 | 850 | -6 | B6 | 343 | N644JB | EWR | PBI | 147 | 1023 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 610 | -8 | 812 | 820 | -8 | DL | 1919 | N971DL | LGA | MSP | 170 | 1020 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 605 | -3 | 821 | 805 | 16 | MQ | 4401 | N730MQ | LGA | DTW | 105 | 502 | 6 | 5 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 858 | 910 | -12 | AA | 1895 | N633AA | EWR | MIA | 152 | 1085 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 837 | 845 | -8 | DL | 1743 | N3739P | JFK | ATL | 128 | 760 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 607 | 607 | 0 | 858 | 915 | -17 | UA | 1077 | N53442 | EWR | MIA | 157 | 1085 | 6 | 7 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 608 | 600 | 8 | 807 | 735 | 32 | MQ | 3768 | N9EAMQ | EWR | ORD | 139 | 719 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 611 | 600 | 11 | 945 | 931 | 14 | UA | 303 | N532UA | JFK | SFO | 366 | 2586 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 613 | 610 | 3 | 925 | 921 | 4 | B6 | 135 | N635JB | JFK | RSW | 175 | 1074 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 1039 | 1100 | -21 | B6 | 709 | N794JB | JFK | SJU | 182 | 1598 | 6 | 15 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 833 | 842 | -9 | DL | 575 | N326NB | EWR | ATL | 120 | 746 | 6 | 15 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2013 | 9 | 30 | 2123 | 2125 | -2 | 2223 | 2247 | -24 | EV | 5489 | N712EV | LGA | CHO | 45 | 305 | 21 | 25 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2127 | 2129 | -2 | 2314 | 2323 | -9 | EV | 3833 | N16546 | EWR | CLT | 72 | 529 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2128 | 2130 | -2 | 2328 | 2359 | -31 | B6 | 97 | N807JB | JFK | DEN | 213 | 1626 | 21 | 30 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2129 | 2059 | 30 | 2230 | 2232 | -2 | EV | 5048 | N751EV | LGA | RIC | 45 | 292 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2131 | 2140 | -9 | 2225 | 2255 | -30 | MQ | 3621 | N807MQ | JFK | DCA | 36 | 213 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2140 | 2140 | 0 | 10 | 40 | -30 | AA | 185 | N335AA | JFK | LAX | 298 | 2475 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2142 | 2129 | 13 | 2250 | 2239 | 11 | EV | 4509 | N12957 | EWR | PWM | 47 | 284 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2145 | 2145 | 0 | 115 | 140 | -25 | B6 | 1103 | N633JB | JFK | SJU | 192 | 1598 | 21 | 45 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2147 | 2137 | 10 | 30 | 27 | 3 | B6 | 1371 | N627JB | LGA | FLL | 139 | 1076 | 21 | 37 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2149 | 2156 | -7 | 2245 | 2308 | -23 | UA | 523 | N813UA | EWR | BOS | 37 | 200 | 21 | 56 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2150 | 2159 | -9 | 2250 | 2306 | -16 | EV | 3842 | N10575 | EWR | MHT | 39 | 209 | 21 | 59 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2159 | 1845 | 194 | 2344 | 2030 | 194 | 9E | 3320 | N906XJ | JFK | BUF | 50 | 301 | 18 | 45 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | 2203 | 2205 | -2 | 2339 | 2331 | 8 | EV | 5311 | N722EV | LGA | BGR | 61 | 378 | 22 | 5 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2207 | 2140 | 27 | 2257 | 2250 | 7 | MQ | 3660 | N532MQ | LGA | BNA | 97 | 764 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2211 | 2059 | 72 | 2339 | 2242 | 57 | EV | 4672 | N12145 | EWR | STL | 120 | 872 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2231 | 2245 | -14 | 2335 | 2356 | -21 | B6 | 108 | N193JB | JFK | PWM | 48 | 273 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2233 | 2113 | 80 | 112 | 30 | 42 | UA | 471 | N578UA | EWR | SFO | 318 | 2565 | 21 | 13 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2235 | 2001 | 154 | 59 | 2249 | 130 | B6 | 1083 | N804JB | JFK | MCO | 123 | 944 | 20 | 1 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2237 | 2245 | -8 | 2345 | 2353 | -8 | B6 | 234 | N318JB | JFK | BTV | 43 | 266 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2245 | -5 | 2334 | 2351 | -17 | B6 | 1816 | N354JB | JFK | SYR | 41 | 209 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2250 | -10 | 2347 | 7 | -20 | B6 | 2002 | N281JB | JFK | BUF | 52 | 301 | 22 | 50 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2241 | 2246 | -5 | 2345 | 1 | -16 | B6 | 486 | N346JB | JFK | ROC | 47 | 264 | 22 | 46 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2307 | 2255 | 12 | 2359 | 2358 | 1 | B6 | 718 | N565JB | JFK | BOS | 33 | 187 | 22 | 55 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2349 | 2359 | -10 | 325 | 350 | -25 | B6 | 745 | N516JB | JFK | PSE | 196 | 1617 | 23 | 59 | 2013-09-30 23:00:00 |
2013 | 9 | 30 | NA | 1842 | NA | NA | 2019 | NA | EV | 5274 | N740EV | LGA | BNA | NA | 764 | 18 | 42 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | NA | 1455 | NA | NA | 1634 | NA | 9E | 3393 | NA | JFK | DCA | NA | 213 | 14 | 55 | 2013-09-30 14:00:00 |
2013 | 9 | 30 | NA | 2200 | NA | NA | 2312 | NA | 9E | 3525 | NA | LGA | SYR | NA | 198 | 22 | 0 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | NA | 1210 | NA | NA | 1330 | NA | MQ | 3461 | N535MQ | LGA | BNA | NA | 764 | 12 | 10 | 2013-09-30 12:00:00 |
2013 | 9 | 30 | NA | 1159 | NA | NA | 1344 | NA | MQ | 3572 | N511MQ | LGA | CLE | NA | 419 | 11 | 59 | 2013-09-30 11:00:00 |
2013 | 9 | 30 | NA | 840 | NA | NA | 1020 | NA | MQ | 3531 | N839MQ | LGA | RDU | NA | 431 | 8 | 40 | 2013-09-30 08:00:00 |
# # Find all unique origin and destination pairs
flights |>
distinct(origin, dest)
origin | dest |
---|---|
<chr> | <chr> |
EWR | IAH |
LGA | IAH |
JFK | MIA |
JFK | BQN |
LGA | ATL |
EWR | ORD |
EWR | FLL |
LGA | IAD |
JFK | MCO |
LGA | ORD |
JFK | PBI |
JFK | TPA |
JFK | LAX |
EWR | SFO |
LGA | DFW |
JFK | BOS |
EWR | LAS |
LGA | FLL |
EWR | PBI |
LGA | MSP |
LGA | DTW |
EWR | MIA |
JFK | ATL |
JFK | SFO |
JFK | RSW |
JFK | SJU |
EWR | ATL |
EWR | PHX |
LGA | MIA |
EWR | MSP |
... | ... |
JFK | ACK |
LGA | BGR |
LGA | MSN |
LGA | ORF |
JFK | IAH |
JFK | MCI |
LGA | OMA |
LGA | DSM |
LGA | GSP |
JFK | ABQ |
LGA | ILM |
LGA | SYR |
JFK | MVY |
LGA | SBN |
JFK | STL |
LGA | LEX |
EWR | SBN |
LGA | MHT |
LGA | CAE |
JFK | JAC |
JFK | SDF |
LGA | CHO |
JFK | MKE |
LGA | AVL |
JFK | BHM |
LGA | TVC |
LGA | MYR |
EWR | TVC |
EWR | ANC |
EWR | LGA |
# keep other columns when filtering for unique rows
flights |>
distinct(origin, dest, .keep_all = TRUE)
year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 1 | 517 | 515 | 2 | 830 | 819 | 11 | UA | 1545 | N14228 | EWR | IAH | 227 | 1400 | 5 | 15 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 533 | 529 | 4 | 850 | 830 | 20 | UA | 1714 | N24211 | LGA | IAH | 227 | 1416 | 5 | 29 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 542 | 540 | 2 | 923 | 850 | 33 | AA | 1141 | N619AA | JFK | MIA | 160 | 1089 | 5 | 40 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 544 | 545 | -1 | 1004 | 1022 | -18 | B6 | 725 | N804JB | JFK | BQN | 183 | 1576 | 5 | 45 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 554 | 600 | -6 | 812 | 837 | -25 | DL | 461 | N668DN | LGA | ATL | 116 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 554 | 558 | -4 | 740 | 728 | 12 | UA | 1696 | N39463 | EWR | ORD | 150 | 719 | 5 | 58 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 555 | 600 | -5 | 913 | 854 | 19 | B6 | 507 | N516JB | EWR | FLL | 158 | 1065 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 709 | 723 | -14 | EV | 5708 | N829AS | LGA | IAD | 53 | 229 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 838 | 846 | -8 | B6 | 79 | N593JB | JFK | MCO | 140 | 944 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 753 | 745 | 8 | AA | 301 | N3ALAA | LGA | ORD | 138 | 733 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 849 | 851 | -2 | B6 | 49 | N793JB | JFK | PBI | 149 | 1028 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 853 | 856 | -3 | B6 | 71 | N657JB | JFK | TPA | 158 | 1005 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 924 | 917 | 7 | UA | 194 | N29129 | JFK | LAX | 345 | 2475 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 923 | 937 | -14 | UA | 1124 | N53441 | EWR | SFO | 361 | 2565 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 941 | 910 | 31 | AA | 707 | N3DUAA | LGA | DFW | 257 | 1389 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 559 | 0 | 702 | 706 | -4 | B6 | 1806 | N708JB | JFK | BOS | 44 | 187 | 5 | 59 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 854 | 902 | -8 | UA | 1187 | N76515 | EWR | LAS | 337 | 2227 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 851 | 858 | -7 | B6 | 371 | N595JB | LGA | FLL | 152 | 1076 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 601 | 600 | 1 | 844 | 850 | -6 | B6 | 343 | N644JB | EWR | PBI | 147 | 1023 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 610 | -8 | 812 | 820 | -8 | DL | 1919 | N971DL | LGA | MSP | 170 | 1020 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 605 | -3 | 821 | 805 | 16 | MQ | 4401 | N730MQ | LGA | DTW | 105 | 502 | 6 | 5 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 858 | 910 | -12 | AA | 1895 | N633AA | EWR | MIA | 152 | 1085 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 837 | 845 | -8 | DL | 1743 | N3739P | JFK | ATL | 128 | 760 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 611 | 600 | 11 | 945 | 931 | 14 | UA | 303 | N532UA | JFK | SFO | 366 | 2586 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 613 | 610 | 3 | 925 | 921 | 4 | B6 | 135 | N635JB | JFK | RSW | 175 | 1074 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 1039 | 1100 | -21 | B6 | 709 | N794JB | JFK | SJU | 182 | 1598 | 6 | 15 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 833 | 842 | -9 | DL | 575 | N326NB | EWR | ATL | 120 | 746 | 6 | 15 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 622 | 630 | -8 | 1017 | 1014 | 3 | US | 245 | N807AW | EWR | PHX | 342 | 2133 | 6 | 30 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 623 | 610 | 13 | 920 | 915 | 5 | AA | 1837 | N3EMAA | LGA | MIA | 153 | 1096 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 624 | 630 | -6 | 909 | 840 | 29 | EV | 4626 | N11107 | EWR | MSP | 190 | 1008 | 6 | 30 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2013 | 10 | 1 | 1149 | 1159 | -10 | 1245 | 1259 | -14 | B6 | 1191 | N346JB | JFK | ACK | 39 | 199 | 11 | 59 | 2013-10-01 11:00:00 |
2013 | 10 | 1 | 1338 | 1105 | 153 | 1446 | 1245 | 121 | EV | 5309 | N713EV | LGA | BGR | 57 | 378 | 11 | 5 | 2013-10-01 11:00:00 |
2013 | 10 | 1 | 1345 | 1350 | -5 | 1457 | 1526 | -29 | EV | 5181 | N612QX | LGA | MSN | 115 | 812 | 13 | 50 | 2013-10-01 13:00:00 |
2013 | 10 | 1 | 1543 | 1545 | -2 | 1702 | 1721 | -19 | EV | 5293 | N398CA | LGA | ORF | 46 | 296 | 15 | 45 | 2013-10-01 15:00:00 |
2013 | 10 | 1 | 1658 | 1700 | -2 | 2002 | 1955 | 7 | AA | 211 | N3FVAA | JFK | IAH | 214 | 1417 | 17 | 0 | 2013-10-01 17:00:00 |
2013 | 10 | 1 | 1728 | 1736 | -8 | 1910 | 2006 | -56 | 9E | 3310 | N907XJ | JFK | MCI | 143 | 1113 | 17 | 36 | 2013-10-01 17:00:00 |
2013 | 10 | 1 | 1732 | 1730 | 2 | 1925 | 1953 | -28 | EV | 5298 | N709EV | LGA | OMA | 153 | 1148 | 17 | 30 | 2013-10-01 17:00:00 |
2013 | 10 | 1 | 1857 | 1900 | -3 | 2044 | 2117 | -33 | 9E | 3445 | N906XJ | LGA | DSM | 146 | 1031 | 19 | 0 | 2013-10-01 19:00:00 |
2013 | 10 | 1 | 1930 | 1900 | 30 | 2129 | 2119 | 10 | 9E | 3854 | N8884E | LGA | GSP | 86 | 610 | 19 | 0 | 2013-10-01 19:00:00 |
2013 | 10 | 1 | 1955 | 2001 | -6 | 2213 | 2248 | -35 | B6 | 65 | N554JB | JFK | ABQ | 230 | 1826 | 20 | 1 | 2013-10-01 20:00:00 |
2013 | 10 | 1 | 2051 | 2110 | -19 | 2219 | 2306 | -47 | EV | 4885 | N752EV | LGA | ILM | 66 | 500 | 21 | 10 | 2013-10-01 21:00:00 |
2013 | 10 | 1 | 2150 | 2159 | -9 | 2246 | 2308 | -22 | 9E | 3525 | N922XJ | LGA | SYR | 34 | 198 | 21 | 59 | 2013-10-01 21:00:00 |
2013 | 10 | 3 | 1414 | 1350 | 24 | 1514 | 1453 | 21 | B6 | 1338 | N368JB | JFK | MVY | 36 | 173 | 13 | 50 | 2013-10-03 13:00:00 |
2013 | 10 | 18 | 1820 | 1745 | 35 | 2030 | 2011 | 19 | EV | 5624 | N748EV | LGA | SBN | 104 | 651 | 17 | 45 | 2013-10-18 17:00:00 |
2013 | 11 | 2 | 1519 | 1459 | 20 | 1654 | 1702 | -8 | DL | 567 | N329NB | JFK | STL | 129 | 892 | 14 | 59 | 2013-11-02 14:00:00 |
2013 | 11 | 24 | 2026 | 2035 | -9 | 2227 | 2249 | -22 | 9E | 3669 | N8604C | LGA | LEX | 90 | 604 | 20 | 35 | 2013-11-24 20:00:00 |
2013 | 12 | 1 | 1241 | 1215 | 26 | 1431 | 1431 | 0 | EV | 3264 | N16976 | EWR | SBN | 94 | 637 | 12 | 15 | 2013-12-01 12:00:00 |
2013 | 12 | 19 | 1056 | 1103 | -7 | 1210 | 1219 | -9 | EV | 5252 | N848AS | LGA | MHT | 39 | 195 | 11 | 3 | 2013-12-19 11:00:00 |
2013 | 12 | 19 | 1914 | 1915 | -1 | 2130 | 2144 | -14 | EV | 5567 | N848AS | LGA | CAE | 97 | 617 | 19 | 15 | 2013-12-19 19:00:00 |
2013 | 12 | 21 | 802 | 800 | 2 | 1115 | 1102 | 13 | DL | 2379 | N6705Y | JFK | JAC | 281 | 1894 | 8 | 0 | 2013-12-21 08:00:00 |
2013 | 12 | 21 | 1610 | 1610 | 0 | 1839 | 1855 | -16 | 9E | 2941 | N8930E | JFK | SDF | 114 | 662 | 16 | 10 | 2013-12-21 16:00:00 |
2013 | 3 | 1 | 2046 | 2045 | 1 | 2206 | 2220 | -14 | EV | 5343 | N197PQ | LGA | CHO | 48 | 305 | 20 | 45 | 2013-03-01 20:00:00 |
2013 | 3 | 2 | 1606 | 1610 | -4 | 1723 | 1758 | -35 | 9E | 3437 | N927XJ | JFK | MKE | 109 | 745 | 16 | 10 | 2013-03-02 16:00:00 |
2013 | 4 | 14 | 937 | 945 | -8 | 1130 | 1159 | -29 | 9E | 3632 | N8936A | LGA | AVL | 93 | 599 | 9 | 45 | 2013-04-14 09:00:00 |
2013 | 5 | 25 | 1007 | 1000 | 7 | 1129 | 1148 | -19 | EV | 5621 | N751EV | JFK | BHM | 117 | 865 | 10 | 0 | 2013-05-25 10:00:00 |
2013 | 6 | 14 | 1756 | 1800 | -4 | 2004 | 2005 | -1 | MQ | 3402 | N722MQ | LGA | TVC | 101 | 655 | 18 | 0 | 2013-06-14 18:00:00 |
2013 | 6 | 15 | 1517 | 1520 | -3 | 1656 | 1730 | -34 | EV | 5163 | N605QX | LGA | MYR | 74 | 563 | 15 | 20 | 2013-06-15 15:00:00 |
2013 | 7 | 5 | 1355 | 1400 | -5 | 1550 | 1620 | -30 | EV | 4137 | N11164 | EWR | TVC | 93 | 644 | 14 | 0 | 2013-07-05 14:00:00 |
2013 | 7 | 6 | 1629 | 1615 | 14 | 1954 | 1953 | 1 | UA | 887 | N587UA | EWR | ANC | 418 | 3370 | 16 | 15 | 2013-07-06 16:00:00 |
2013 | 7 | 27 | NA | 106 | NA | NA | 245 | NA | US | 1632 | NA | EWR | LGA | NA | 17 | 1 | 6 | 2013-07-27 01:00:00 |
If you want to find the number of occurrences instead, you’re better off swapping distinct()
for count()
, and with the sort = TRUE
argument you can arrange them in descending order of number of occurrences.
flights |>
count(origin, dest, sort = TRUE)
origin | dest | n |
---|---|---|
<chr> | <chr> | <int> |
JFK | LAX | 11262 |
LGA | ATL | 10263 |
LGA | ORD | 8857 |
JFK | SFO | 8204 |
LGA | CLT | 6168 |
EWR | ORD | 6100 |
JFK | BOS | 5898 |
LGA | MIA | 5781 |
JFK | MCO | 5464 |
EWR | BOS | 5327 |
EWR | SFO | 5127 |
LGA | DTW | 5040 |
EWR | CLT | 5026 |
EWR | ATL | 5022 |
EWR | MCO | 4941 |
EWR | LAX | 4912 |
LGA | DFW | 4858 |
JFK | SJU | 4752 |
LGA | DCA | 4716 |
LGA | BOS | 4283 |
JFK | FLL | 4254 |
LGA | FLL | 4008 |
JFK | LAS | 3987 |
EWR | IAH | 3973 |
EWR | FLL | 3793 |
LGA | MSP | 3713 |
LGA | DEN | 3704 |
LGA | MCO | 3677 |
JFK | BUF | 3582 |
LGA | RDU | 3581 |
... | ... | ... |
JFK | EGE | 103 |
LGA | OMA | 95 |
LGA | IND | 87 |
LGA | TVC | 77 |
LGA | SAV | 68 |
EWR | MYR | 56 |
LGA | CHO | 52 |
EWR | PHL | 49 |
JFK | SDF | 46 |
LGA | GRR | 46 |
EWR | BZN | 36 |
EWR | TVC | 24 |
EWR | JAC | 23 |
JFK | PSP | 19 |
LGA | EYW | 17 |
EWR | HDN | 15 |
EWR | MTJ | 15 |
LGA | BWI | 15 |
LGA | CAE | 12 |
LGA | AVL | 10 |
EWR | ANC | 8 |
LGA | SBN | 6 |
EWR | SBN | 4 |
LGA | MYR | 3 |
JFK | JAC | 2 |
EWR | LGA | 1 |
JFK | BHM | 1 |
JFK | MEM | 1 |
JFK | STL | 1 |
LGA | LEX | 1 |
Exercises
3.2.1. Single pipeline:
- Had an arrival delay of two or more hours
- Flew to Houston (IAH or HOU)
- Were operated by United, American, or Delta
- Departed in summer (July, August, and September)
- Arrived more than two hours late, but didn’t leave late
- Were delayed by at least an hour, but made up over 30 minutes in flight
3.2.2. Sort flights to find the flights with longest departure delays. Find the flights that left earliest in the morning.
3.2.3. Sort flights to find the fastest flights. (Hint: Try including a math calculation inside of your function.)
3.2.4. Was there a flight on every day of 2013?
3.2.5. Which flights traveled the farthest distance? Which traveled the least distance?
3.2.6. Does it matter what order you used filter() and arrange() if you’re using both? Why/why not? Think about the results and how much work the functions would have to do.
#3.2.1. Had an arrival delay of two or more hours
#3.2.1. Flew to Houston (IAH or HOU)
#3.2.1. Were operated by United, American, or Delta
#
#3.2.1. Departed in summer (July, August, and September)
#3.2.1. Arrived more than two hours late, but didn’t leave late
#3.2.1. Were delayed by at least an hour, but made up over 30 minutes in flight
#3.2.2. Sort flights to find the flights with longest departure delays. Find the flights that left earliest in the morning.
#3.2.3. Sort flights to find the fastest flights. (Hint: Try including a math calculation inside of your function.)
#3.2.4. Was there a flight on every day of 2013?
#
#3.2.5. Which flights traveled the farthest distance? Which traveled the least distance?
#3.2.6. Does it matter what order you used filter() and arrange() if you’re using both? Why/why not?
# Think about the results and how much work the functions would have to do.
Columns
There are four important verbs that affect the columns without changing the rows:
mutate()
creates new columns that are derived from the existing columnsselect()
changes which columns are presentrename()
changes the names of the columnsrelocate()
changes the positions of the columns.
mutate()
By default, mutate()
adds new columns on the right hand side of your dataset, which makes it difficult to see what’s happening here. We can use the .before
argument to instead add the variables to the left hand side.
flights |>
mutate(
gain = dep_delay - arr_delay, # gain, how much time a delayed flight made up in the air
speed = distance / air_time * 60, # the speed in miles per hour
.after = day # try: .before = 1
)
year | month | day | gain | speed | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | ... | carrier | flight | tailnum | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <dbl> | <dbl> | <int> | <int> | <dbl> | <int> | <int> | ... | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 1 | -9 | 370.0441 | 517 | 515 | 2 | 830 | 819 | ... | UA | 1545 | N14228 | EWR | IAH | 227 | 1400 | 5 | 15 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | -16 | 374.2731 | 533 | 529 | 4 | 850 | 830 | ... | UA | 1714 | N24211 | LGA | IAH | 227 | 1416 | 5 | 29 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | -31 | 408.3750 | 542 | 540 | 2 | 923 | 850 | ... | AA | 1141 | N619AA | JFK | MIA | 160 | 1089 | 5 | 40 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 17 | 516.7213 | 544 | 545 | -1 | 1004 | 1022 | ... | B6 | 725 | N804JB | JFK | BQN | 183 | 1576 | 5 | 45 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 19 | 394.1379 | 554 | 600 | -6 | 812 | 837 | ... | DL | 461 | N668DN | LGA | ATL | 116 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | -16 | 287.6000 | 554 | 558 | -4 | 740 | 728 | ... | UA | 1696 | N39463 | EWR | ORD | 150 | 719 | 5 | 58 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | -24 | 404.4304 | 555 | 600 | -5 | 913 | 854 | ... | B6 | 507 | N516JB | EWR | FLL | 158 | 1065 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 11 | 259.2453 | 557 | 600 | -3 | 709 | 723 | ... | EV | 5708 | N829AS | LGA | IAD | 53 | 229 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 5 | 404.5714 | 557 | 600 | -3 | 838 | 846 | ... | B6 | 79 | N593JB | JFK | MCO | 140 | 944 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | -10 | 318.6957 | 558 | 600 | -2 | 753 | 745 | ... | AA | 301 | N3ALAA | LGA | ORD | 138 | 733 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 0 | 413.9597 | 558 | 600 | -2 | 849 | 851 | ... | B6 | 49 | N793JB | JFK | PBI | 149 | 1028 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 1 | 381.6456 | 558 | 600 | -2 | 853 | 856 | ... | B6 | 71 | N657JB | JFK | TPA | 158 | 1005 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | -9 | 430.4348 | 558 | 600 | -2 | 924 | 917 | ... | UA | 194 | N29129 | JFK | LAX | 345 | 2475 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 12 | 426.3158 | 558 | 600 | -2 | 923 | 937 | ... | UA | 1124 | N53441 | EWR | SFO | 361 | 2565 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | -32 | 324.2802 | 559 | 600 | -1 | 941 | 910 | ... | AA | 707 | N3DUAA | LGA | DFW | 257 | 1389 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 4 | 255.0000 | 559 | 559 | 0 | 702 | 706 | ... | B6 | 1806 | N708JB | JFK | BOS | 44 | 187 | 5 | 59 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 7 | 396.4985 | 559 | 600 | -1 | 854 | 902 | ... | UA | 1187 | N76515 | EWR | LAS | 337 | 2227 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 7 | 424.7368 | 600 | 600 | 0 | 851 | 858 | ... | B6 | 371 | N595JB | LGA | FLL | 152 | 1076 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | -12 | 341.1940 | 600 | 600 | 0 | 837 | 825 | ... | MQ | 4650 | N542MQ | LGA | ATL | 134 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 7 | 417.5510 | 601 | 600 | 1 | 844 | 850 | ... | B6 | 343 | N644JB | EWR | PBI | 147 | 1023 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 0 | 360.0000 | 602 | 610 | -8 | 812 | 820 | ... | DL | 1919 | N971DL | LGA | MSP | 170 | 1020 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | -19 | 286.8571 | 602 | 605 | -3 | 821 | 805 | ... | MQ | 4401 | N730MQ | LGA | DTW | 105 | 502 | 6 | 5 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 8 | 428.2895 | 606 | 610 | -4 | 858 | 910 | ... | AA | 1895 | N633AA | EWR | MIA | 152 | 1085 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 4 | 356.2500 | 606 | 610 | -4 | 837 | 845 | ... | DL | 1743 | N3739P | JFK | ATL | 128 | 760 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 17 | 414.6497 | 607 | 607 | 0 | 858 | 915 | ... | UA | 1077 | N53442 | EWR | MIA | 157 | 1085 | 6 | 7 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | -24 | 310.3597 | 608 | 600 | 8 | 807 | 735 | ... | MQ | 3768 | N9EAMQ | EWR | ORD | 139 | 719 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | -3 | 423.9344 | 611 | 600 | 11 | 945 | 931 | ... | UA | 303 | N532UA | JFK | SFO | 366 | 2586 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | -1 | 368.2286 | 613 | 610 | 3 | 925 | 921 | ... | B6 | 135 | N635JB | JFK | RSW | 175 | 1074 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 21 | 526.8132 | 615 | 615 | 0 | 1039 | 1100 | ... | B6 | 709 | N794JB | JFK | SJU | 182 | 1598 | 6 | 15 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 9 | 373.0000 | 615 | 615 | 0 | 833 | 842 | ... | DL | 575 | N326NB | EWR | ATL | 120 | 746 | 6 | 15 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | |
2013 | 9 | 30 | 22 | 406.6667 | 2123 | 2125 | -2 | 2223 | 2247 | ... | EV | 5489 | N712EV | LGA | CHO | 45 | 305 | 21 | 25 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 7 | 440.8333 | 2127 | 2129 | -2 | 2314 | 2323 | ... | EV | 3833 | N16546 | EWR | CLT | 72 | 529 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 29 | 458.0282 | 2128 | 2130 | -2 | 2328 | 2359 | ... | B6 | 97 | N807JB | JFK | DEN | 213 | 1626 | 21 | 30 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 32 | 389.3333 | 2129 | 2059 | 30 | 2230 | 2232 | ... | EV | 5048 | N751EV | LGA | RIC | 45 | 292 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 21 | 355.0000 | 2131 | 2140 | -9 | 2225 | 2255 | ... | MQ | 3621 | N807MQ | JFK | DCA | 36 | 213 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 30 | 498.3221 | 2140 | 2140 | 0 | 10 | 40 | ... | AA | 185 | N335AA | JFK | LAX | 298 | 2475 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2 | 362.5532 | 2142 | 2129 | 13 | 2250 | 2239 | ... | EV | 4509 | N12957 | EWR | PWM | 47 | 284 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 25 | 499.3750 | 2145 | 2145 | 0 | 115 | 140 | ... | B6 | 1103 | N633JB | JFK | SJU | 192 | 1598 | 21 | 45 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 7 | 464.4604 | 2147 | 2137 | 10 | 30 | 27 | ... | B6 | 1371 | N627JB | LGA | FLL | 139 | 1076 | 21 | 37 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 16 | 324.3243 | 2149 | 2156 | -7 | 2245 | 2308 | ... | UA | 523 | N813UA | EWR | BOS | 37 | 200 | 21 | 56 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 7 | 321.5385 | 2150 | 2159 | -9 | 2250 | 2306 | ... | EV | 3842 | N10575 | EWR | MHT | 39 | 209 | 21 | 59 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 0 | 361.2000 | 2159 | 1845 | 194 | 2344 | 2030 | ... | 9E | 3320 | N906XJ | JFK | BUF | 50 | 301 | 18 | 45 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | -10 | 371.8033 | 2203 | 2205 | -2 | 2339 | 2331 | ... | EV | 5311 | N722EV | LGA | BGR | 61 | 378 | 22 | 5 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 20 | 472.5773 | 2207 | 2140 | 27 | 2257 | 2250 | ... | MQ | 3660 | N532MQ | LGA | BNA | 97 | 764 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 15 | 436.0000 | 2211 | 2059 | 72 | 2339 | 2242 | ... | EV | 4672 | N12145 | EWR | STL | 120 | 872 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 7 | 341.2500 | 2231 | 2245 | -14 | 2335 | 2356 | ... | B6 | 108 | N193JB | JFK | PWM | 48 | 273 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 38 | 483.9623 | 2233 | 2113 | 80 | 112 | 30 | ... | UA | 471 | N578UA | EWR | SFO | 318 | 2565 | 21 | 13 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 24 | 460.4878 | 2235 | 2001 | 154 | 59 | 2249 | ... | B6 | 1083 | N804JB | JFK | MCO | 123 | 944 | 20 | 1 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 0 | 371.1628 | 2237 | 2245 | -8 | 2345 | 2353 | ... | B6 | 234 | N318JB | JFK | BTV | 43 | 266 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 12 | 305.8537 | 2240 | 2245 | -5 | 2334 | 2351 | ... | B6 | 1816 | N354JB | JFK | SYR | 41 | 209 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 10 | 347.3077 | 2240 | 2250 | -10 | 2347 | 7 | ... | B6 | 2002 | N281JB | JFK | BUF | 52 | 301 | 22 | 50 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 11 | 337.0213 | 2241 | 2246 | -5 | 2345 | 1 | ... | B6 | 486 | N346JB | JFK | ROC | 47 | 264 | 22 | 46 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 11 | 340.0000 | 2307 | 2255 | 12 | 2359 | 2358 | ... | B6 | 718 | N565JB | JFK | BOS | 33 | 187 | 22 | 55 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 15 | 495.0000 | 2349 | 2359 | -10 | 325 | 350 | ... | B6 | 745 | N516JB | JFK | PSE | 196 | 1617 | 23 | 59 | 2013-09-30 23:00:00 |
2013 | 9 | 30 | NA | NA | NA | 1842 | NA | NA | 2019 | ... | EV | 5274 | N740EV | LGA | BNA | NA | 764 | 18 | 42 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | NA | NA | NA | 1455 | NA | NA | 1634 | ... | 9E | 3393 | NA | JFK | DCA | NA | 213 | 14 | 55 | 2013-09-30 14:00:00 |
2013 | 9 | 30 | NA | NA | NA | 2200 | NA | NA | 2312 | ... | 9E | 3525 | NA | LGA | SYR | NA | 198 | 22 | 0 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | NA | NA | NA | 1210 | NA | NA | 1330 | ... | MQ | 3461 | N535MQ | LGA | BNA | NA | 764 | 12 | 10 | 2013-09-30 12:00:00 |
2013 | 9 | 30 | NA | NA | NA | 1159 | NA | NA | 1344 | ... | MQ | 3572 | N511MQ | LGA | CLE | NA | 419 | 11 | 59 | 2013-09-30 11:00:00 |
2013 | 9 | 30 | NA | NA | NA | 840 | NA | NA | 1020 | ... | MQ | 3531 | N839MQ | LGA | RDU | NA | 431 | 8 | 40 | 2013-09-30 08:00:00 |
flights |>
mutate(
gain = dep_delay - arr_delay,
hours = air_time / 60,
gain_per_hour = gain / hours,
.keep = "used"
)
dep_delay | arr_delay | air_time | gain | hours | gain_per_hour |
---|---|---|---|---|---|
<dbl> | <dbl> | <dbl> | <dbl> | <dbl> | <dbl> |
2 | 11 | 227 | -9 | 3.7833333 | -2.3788546 |
4 | 20 | 227 | -16 | 3.7833333 | -4.2290749 |
2 | 33 | 160 | -31 | 2.6666667 | -11.6250000 |
-1 | -18 | 183 | 17 | 3.0500000 | 5.5737705 |
-6 | -25 | 116 | 19 | 1.9333333 | 9.8275862 |
-4 | 12 | 150 | -16 | 2.5000000 | -6.4000000 |
-5 | 19 | 158 | -24 | 2.6333333 | -9.1139241 |
-3 | -14 | 53 | 11 | 0.8833333 | 12.4528302 |
-3 | -8 | 140 | 5 | 2.3333333 | 2.1428571 |
-2 | 8 | 138 | -10 | 2.3000000 | -4.3478261 |
-2 | -2 | 149 | 0 | 2.4833333 | 0.0000000 |
-2 | -3 | 158 | 1 | 2.6333333 | 0.3797468 |
-2 | 7 | 345 | -9 | 5.7500000 | -1.5652174 |
-2 | -14 | 361 | 12 | 6.0166667 | 1.9944598 |
-1 | 31 | 257 | -32 | 4.2833333 | -7.4708171 |
0 | -4 | 44 | 4 | 0.7333333 | 5.4545455 |
-1 | -8 | 337 | 7 | 5.6166667 | 1.2462908 |
0 | -7 | 152 | 7 | 2.5333333 | 2.7631579 |
0 | 12 | 134 | -12 | 2.2333333 | -5.3731343 |
1 | -6 | 147 | 7 | 2.4500000 | 2.8571429 |
-8 | -8 | 170 | 0 | 2.8333333 | 0.0000000 |
-3 | 16 | 105 | -19 | 1.7500000 | -10.8571429 |
-4 | -12 | 152 | 8 | 2.5333333 | 3.1578947 |
-4 | -8 | 128 | 4 | 2.1333333 | 1.8750000 |
0 | -17 | 157 | 17 | 2.6166667 | 6.4968153 |
8 | 32 | 139 | -24 | 2.3166667 | -10.3597122 |
11 | 14 | 366 | -3 | 6.1000000 | -0.4918033 |
3 | 4 | 175 | -1 | 2.9166667 | -0.3428571 |
0 | -21 | 182 | 21 | 3.0333333 | 6.9230769 |
0 | -9 | 120 | 9 | 2.0000000 | 4.5000000 |
... | ... | ... | ... | ... | ... |
-2 | -24 | 45 | 22 | 0.7500000 | 29.333333 |
-2 | -9 | 72 | 7 | 1.2000000 | 5.833333 |
-2 | -31 | 213 | 29 | 3.5500000 | 8.169014 |
30 | -2 | 45 | 32 | 0.7500000 | 42.666667 |
-9 | -30 | 36 | 21 | 0.6000000 | 35.000000 |
0 | -30 | 298 | 30 | 4.9666667 | 6.040268 |
13 | 11 | 47 | 2 | 0.7833333 | 2.553191 |
0 | -25 | 192 | 25 | 3.2000000 | 7.812500 |
10 | 3 | 139 | 7 | 2.3166667 | 3.021583 |
-7 | -23 | 37 | 16 | 0.6166667 | 25.945946 |
-9 | -16 | 39 | 7 | 0.6500000 | 10.769231 |
194 | 194 | 50 | 0 | 0.8333333 | 0.000000 |
-2 | 8 | 61 | -10 | 1.0166667 | -9.836066 |
27 | 7 | 97 | 20 | 1.6166667 | 12.371134 |
72 | 57 | 120 | 15 | 2.0000000 | 7.500000 |
-14 | -21 | 48 | 7 | 0.8000000 | 8.750000 |
80 | 42 | 318 | 38 | 5.3000000 | 7.169811 |
154 | 130 | 123 | 24 | 2.0500000 | 11.707317 |
-8 | -8 | 43 | 0 | 0.7166667 | 0.000000 |
-5 | -17 | 41 | 12 | 0.6833333 | 17.560976 |
-10 | -20 | 52 | 10 | 0.8666667 | 11.538462 |
-5 | -16 | 47 | 11 | 0.7833333 | 14.042553 |
12 | 1 | 33 | 11 | 0.5500000 | 20.000000 |
-10 | -25 | 196 | 15 | 3.2666667 | 4.591837 |
NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA |
NA | NA | NA | NA | NA | NA |
select()
There are a number of helper functions you can use within select()
:
starts_with("abc")
: matches names that begin with “abc”.ends_with("xyz")
: matches names that end with “xyz”.contains("ijk")
: matches names that contain “ijk”.num_range("x", 1:3)
: matches x1, x2 and x3.
See ?select
for more details
flights |>
select(year, month, day)
year | month | day |
---|---|---|
<int> | <int> | <int> |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
... | ... | ... |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
flights |>
select(year:day)
year | month | day |
---|---|---|
<int> | <int> | <int> |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
2013 | 1 | 1 |
... | ... | ... |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
2013 | 9 | 30 |
flights |>
select(!year:day)
dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
517 | 515 | 2 | 830 | 819 | 11 | UA | 1545 | N14228 | EWR | IAH | 227 | 1400 | 5 | 15 | 2013-01-01 05:00:00 |
533 | 529 | 4 | 850 | 830 | 20 | UA | 1714 | N24211 | LGA | IAH | 227 | 1416 | 5 | 29 | 2013-01-01 05:00:00 |
542 | 540 | 2 | 923 | 850 | 33 | AA | 1141 | N619AA | JFK | MIA | 160 | 1089 | 5 | 40 | 2013-01-01 05:00:00 |
544 | 545 | -1 | 1004 | 1022 | -18 | B6 | 725 | N804JB | JFK | BQN | 183 | 1576 | 5 | 45 | 2013-01-01 05:00:00 |
554 | 600 | -6 | 812 | 837 | -25 | DL | 461 | N668DN | LGA | ATL | 116 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
554 | 558 | -4 | 740 | 728 | 12 | UA | 1696 | N39463 | EWR | ORD | 150 | 719 | 5 | 58 | 2013-01-01 05:00:00 |
555 | 600 | -5 | 913 | 854 | 19 | B6 | 507 | N516JB | EWR | FLL | 158 | 1065 | 6 | 0 | 2013-01-01 06:00:00 |
557 | 600 | -3 | 709 | 723 | -14 | EV | 5708 | N829AS | LGA | IAD | 53 | 229 | 6 | 0 | 2013-01-01 06:00:00 |
557 | 600 | -3 | 838 | 846 | -8 | B6 | 79 | N593JB | JFK | MCO | 140 | 944 | 6 | 0 | 2013-01-01 06:00:00 |
558 | 600 | -2 | 753 | 745 | 8 | AA | 301 | N3ALAA | LGA | ORD | 138 | 733 | 6 | 0 | 2013-01-01 06:00:00 |
558 | 600 | -2 | 849 | 851 | -2 | B6 | 49 | N793JB | JFK | PBI | 149 | 1028 | 6 | 0 | 2013-01-01 06:00:00 |
558 | 600 | -2 | 853 | 856 | -3 | B6 | 71 | N657JB | JFK | TPA | 158 | 1005 | 6 | 0 | 2013-01-01 06:00:00 |
558 | 600 | -2 | 924 | 917 | 7 | UA | 194 | N29129 | JFK | LAX | 345 | 2475 | 6 | 0 | 2013-01-01 06:00:00 |
558 | 600 | -2 | 923 | 937 | -14 | UA | 1124 | N53441 | EWR | SFO | 361 | 2565 | 6 | 0 | 2013-01-01 06:00:00 |
559 | 600 | -1 | 941 | 910 | 31 | AA | 707 | N3DUAA | LGA | DFW | 257 | 1389 | 6 | 0 | 2013-01-01 06:00:00 |
559 | 559 | 0 | 702 | 706 | -4 | B6 | 1806 | N708JB | JFK | BOS | 44 | 187 | 5 | 59 | 2013-01-01 05:00:00 |
559 | 600 | -1 | 854 | 902 | -8 | UA | 1187 | N76515 | EWR | LAS | 337 | 2227 | 6 | 0 | 2013-01-01 06:00:00 |
600 | 600 | 0 | 851 | 858 | -7 | B6 | 371 | N595JB | LGA | FLL | 152 | 1076 | 6 | 0 | 2013-01-01 06:00:00 |
600 | 600 | 0 | 837 | 825 | 12 | MQ | 4650 | N542MQ | LGA | ATL | 134 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
601 | 600 | 1 | 844 | 850 | -6 | B6 | 343 | N644JB | EWR | PBI | 147 | 1023 | 6 | 0 | 2013-01-01 06:00:00 |
602 | 610 | -8 | 812 | 820 | -8 | DL | 1919 | N971DL | LGA | MSP | 170 | 1020 | 6 | 10 | 2013-01-01 06:00:00 |
602 | 605 | -3 | 821 | 805 | 16 | MQ | 4401 | N730MQ | LGA | DTW | 105 | 502 | 6 | 5 | 2013-01-01 06:00:00 |
606 | 610 | -4 | 858 | 910 | -12 | AA | 1895 | N633AA | EWR | MIA | 152 | 1085 | 6 | 10 | 2013-01-01 06:00:00 |
606 | 610 | -4 | 837 | 845 | -8 | DL | 1743 | N3739P | JFK | ATL | 128 | 760 | 6 | 10 | 2013-01-01 06:00:00 |
607 | 607 | 0 | 858 | 915 | -17 | UA | 1077 | N53442 | EWR | MIA | 157 | 1085 | 6 | 7 | 2013-01-01 06:00:00 |
608 | 600 | 8 | 807 | 735 | 32 | MQ | 3768 | N9EAMQ | EWR | ORD | 139 | 719 | 6 | 0 | 2013-01-01 06:00:00 |
611 | 600 | 11 | 945 | 931 | 14 | UA | 303 | N532UA | JFK | SFO | 366 | 2586 | 6 | 0 | 2013-01-01 06:00:00 |
613 | 610 | 3 | 925 | 921 | 4 | B6 | 135 | N635JB | JFK | RSW | 175 | 1074 | 6 | 10 | 2013-01-01 06:00:00 |
615 | 615 | 0 | 1039 | 1100 | -21 | B6 | 709 | N794JB | JFK | SJU | 182 | 1598 | 6 | 15 | 2013-01-01 06:00:00 |
615 | 615 | 0 | 833 | 842 | -9 | DL | 575 | N326NB | EWR | ATL | 120 | 746 | 6 | 15 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2123 | 2125 | -2 | 2223 | 2247 | -24 | EV | 5489 | N712EV | LGA | CHO | 45 | 305 | 21 | 25 | 2013-09-30 21:00:00 |
2127 | 2129 | -2 | 2314 | 2323 | -9 | EV | 3833 | N16546 | EWR | CLT | 72 | 529 | 21 | 29 | 2013-09-30 21:00:00 |
2128 | 2130 | -2 | 2328 | 2359 | -31 | B6 | 97 | N807JB | JFK | DEN | 213 | 1626 | 21 | 30 | 2013-09-30 21:00:00 |
2129 | 2059 | 30 | 2230 | 2232 | -2 | EV | 5048 | N751EV | LGA | RIC | 45 | 292 | 20 | 59 | 2013-09-30 20:00:00 |
2131 | 2140 | -9 | 2225 | 2255 | -30 | MQ | 3621 | N807MQ | JFK | DCA | 36 | 213 | 21 | 40 | 2013-09-30 21:00:00 |
2140 | 2140 | 0 | 10 | 40 | -30 | AA | 185 | N335AA | JFK | LAX | 298 | 2475 | 21 | 40 | 2013-09-30 21:00:00 |
2142 | 2129 | 13 | 2250 | 2239 | 11 | EV | 4509 | N12957 | EWR | PWM | 47 | 284 | 21 | 29 | 2013-09-30 21:00:00 |
2145 | 2145 | 0 | 115 | 140 | -25 | B6 | 1103 | N633JB | JFK | SJU | 192 | 1598 | 21 | 45 | 2013-09-30 21:00:00 |
2147 | 2137 | 10 | 30 | 27 | 3 | B6 | 1371 | N627JB | LGA | FLL | 139 | 1076 | 21 | 37 | 2013-09-30 21:00:00 |
2149 | 2156 | -7 | 2245 | 2308 | -23 | UA | 523 | N813UA | EWR | BOS | 37 | 200 | 21 | 56 | 2013-09-30 21:00:00 |
2150 | 2159 | -9 | 2250 | 2306 | -16 | EV | 3842 | N10575 | EWR | MHT | 39 | 209 | 21 | 59 | 2013-09-30 21:00:00 |
2159 | 1845 | 194 | 2344 | 2030 | 194 | 9E | 3320 | N906XJ | JFK | BUF | 50 | 301 | 18 | 45 | 2013-09-30 18:00:00 |
2203 | 2205 | -2 | 2339 | 2331 | 8 | EV | 5311 | N722EV | LGA | BGR | 61 | 378 | 22 | 5 | 2013-09-30 22:00:00 |
2207 | 2140 | 27 | 2257 | 2250 | 7 | MQ | 3660 | N532MQ | LGA | BNA | 97 | 764 | 21 | 40 | 2013-09-30 21:00:00 |
2211 | 2059 | 72 | 2339 | 2242 | 57 | EV | 4672 | N12145 | EWR | STL | 120 | 872 | 20 | 59 | 2013-09-30 20:00:00 |
2231 | 2245 | -14 | 2335 | 2356 | -21 | B6 | 108 | N193JB | JFK | PWM | 48 | 273 | 22 | 45 | 2013-09-30 22:00:00 |
2233 | 2113 | 80 | 112 | 30 | 42 | UA | 471 | N578UA | EWR | SFO | 318 | 2565 | 21 | 13 | 2013-09-30 21:00:00 |
2235 | 2001 | 154 | 59 | 2249 | 130 | B6 | 1083 | N804JB | JFK | MCO | 123 | 944 | 20 | 1 | 2013-09-30 20:00:00 |
2237 | 2245 | -8 | 2345 | 2353 | -8 | B6 | 234 | N318JB | JFK | BTV | 43 | 266 | 22 | 45 | 2013-09-30 22:00:00 |
2240 | 2245 | -5 | 2334 | 2351 | -17 | B6 | 1816 | N354JB | JFK | SYR | 41 | 209 | 22 | 45 | 2013-09-30 22:00:00 |
2240 | 2250 | -10 | 2347 | 7 | -20 | B6 | 2002 | N281JB | JFK | BUF | 52 | 301 | 22 | 50 | 2013-09-30 22:00:00 |
2241 | 2246 | -5 | 2345 | 1 | -16 | B6 | 486 | N346JB | JFK | ROC | 47 | 264 | 22 | 46 | 2013-09-30 22:00:00 |
2307 | 2255 | 12 | 2359 | 2358 | 1 | B6 | 718 | N565JB | JFK | BOS | 33 | 187 | 22 | 55 | 2013-09-30 22:00:00 |
2349 | 2359 | -10 | 325 | 350 | -25 | B6 | 745 | N516JB | JFK | PSE | 196 | 1617 | 23 | 59 | 2013-09-30 23:00:00 |
NA | 1842 | NA | NA | 2019 | NA | EV | 5274 | N740EV | LGA | BNA | NA | 764 | 18 | 42 | 2013-09-30 18:00:00 |
NA | 1455 | NA | NA | 1634 | NA | 9E | 3393 | NA | JFK | DCA | NA | 213 | 14 | 55 | 2013-09-30 14:00:00 |
NA | 2200 | NA | NA | 2312 | NA | 9E | 3525 | NA | LGA | SYR | NA | 198 | 22 | 0 | 2013-09-30 22:00:00 |
NA | 1210 | NA | NA | 1330 | NA | MQ | 3461 | N535MQ | LGA | BNA | NA | 764 | 12 | 10 | 2013-09-30 12:00:00 |
NA | 1159 | NA | NA | 1344 | NA | MQ | 3572 | N511MQ | LGA | CLE | NA | 419 | 11 | 59 | 2013-09-30 11:00:00 |
NA | 840 | NA | NA | 1020 | NA | MQ | 3531 | N839MQ | LGA | RDU | NA | 431 | 8 | 40 | 2013-09-30 08:00:00 |
#Select all columns that are characters:
flights |>
select(!where(is.character))
year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | flight | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <int> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 1 | 517 | 515 | 2 | 830 | 819 | 11 | 1545 | 227 | 1400 | 5 | 15 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 533 | 529 | 4 | 850 | 830 | 20 | 1714 | 227 | 1416 | 5 | 29 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 542 | 540 | 2 | 923 | 850 | 33 | 1141 | 160 | 1089 | 5 | 40 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 544 | 545 | -1 | 1004 | 1022 | -18 | 725 | 183 | 1576 | 5 | 45 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 554 | 600 | -6 | 812 | 837 | -25 | 461 | 116 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 554 | 558 | -4 | 740 | 728 | 12 | 1696 | 150 | 719 | 5 | 58 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 555 | 600 | -5 | 913 | 854 | 19 | 507 | 158 | 1065 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 709 | 723 | -14 | 5708 | 53 | 229 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 838 | 846 | -8 | 79 | 140 | 944 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 753 | 745 | 8 | 301 | 138 | 733 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 849 | 851 | -2 | 49 | 149 | 1028 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 853 | 856 | -3 | 71 | 158 | 1005 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 924 | 917 | 7 | 194 | 345 | 2475 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 923 | 937 | -14 | 1124 | 361 | 2565 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 941 | 910 | 31 | 707 | 257 | 1389 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 559 | 0 | 702 | 706 | -4 | 1806 | 44 | 187 | 5 | 59 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 854 | 902 | -8 | 1187 | 337 | 2227 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 851 | 858 | -7 | 371 | 152 | 1076 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 837 | 825 | 12 | 4650 | 134 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 601 | 600 | 1 | 844 | 850 | -6 | 343 | 147 | 1023 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 610 | -8 | 812 | 820 | -8 | 1919 | 170 | 1020 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 605 | -3 | 821 | 805 | 16 | 4401 | 105 | 502 | 6 | 5 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 858 | 910 | -12 | 1895 | 152 | 1085 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 837 | 845 | -8 | 1743 | 128 | 760 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 607 | 607 | 0 | 858 | 915 | -17 | 1077 | 157 | 1085 | 6 | 7 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 608 | 600 | 8 | 807 | 735 | 32 | 3768 | 139 | 719 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 611 | 600 | 11 | 945 | 931 | 14 | 303 | 366 | 2586 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 613 | 610 | 3 | 925 | 921 | 4 | 135 | 175 | 1074 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 1039 | 1100 | -21 | 709 | 182 | 1598 | 6 | 15 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 833 | 842 | -9 | 575 | 120 | 746 | 6 | 15 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2013 | 9 | 30 | 2123 | 2125 | -2 | 2223 | 2247 | -24 | 5489 | 45 | 305 | 21 | 25 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2127 | 2129 | -2 | 2314 | 2323 | -9 | 3833 | 72 | 529 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2128 | 2130 | -2 | 2328 | 2359 | -31 | 97 | 213 | 1626 | 21 | 30 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2129 | 2059 | 30 | 2230 | 2232 | -2 | 5048 | 45 | 292 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2131 | 2140 | -9 | 2225 | 2255 | -30 | 3621 | 36 | 213 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2140 | 2140 | 0 | 10 | 40 | -30 | 185 | 298 | 2475 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2142 | 2129 | 13 | 2250 | 2239 | 11 | 4509 | 47 | 284 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2145 | 2145 | 0 | 115 | 140 | -25 | 1103 | 192 | 1598 | 21 | 45 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2147 | 2137 | 10 | 30 | 27 | 3 | 1371 | 139 | 1076 | 21 | 37 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2149 | 2156 | -7 | 2245 | 2308 | -23 | 523 | 37 | 200 | 21 | 56 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2150 | 2159 | -9 | 2250 | 2306 | -16 | 3842 | 39 | 209 | 21 | 59 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2159 | 1845 | 194 | 2344 | 2030 | 194 | 3320 | 50 | 301 | 18 | 45 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | 2203 | 2205 | -2 | 2339 | 2331 | 8 | 5311 | 61 | 378 | 22 | 5 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2207 | 2140 | 27 | 2257 | 2250 | 7 | 3660 | 97 | 764 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2211 | 2059 | 72 | 2339 | 2242 | 57 | 4672 | 120 | 872 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2231 | 2245 | -14 | 2335 | 2356 | -21 | 108 | 48 | 273 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2233 | 2113 | 80 | 112 | 30 | 42 | 471 | 318 | 2565 | 21 | 13 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2235 | 2001 | 154 | 59 | 2249 | 130 | 1083 | 123 | 944 | 20 | 1 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2237 | 2245 | -8 | 2345 | 2353 | -8 | 234 | 43 | 266 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2245 | -5 | 2334 | 2351 | -17 | 1816 | 41 | 209 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2250 | -10 | 2347 | 7 | -20 | 2002 | 52 | 301 | 22 | 50 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2241 | 2246 | -5 | 2345 | 1 | -16 | 486 | 47 | 264 | 22 | 46 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2307 | 2255 | 12 | 2359 | 2358 | 1 | 718 | 33 | 187 | 22 | 55 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2349 | 2359 | -10 | 325 | 350 | -25 | 745 | 196 | 1617 | 23 | 59 | 2013-09-30 23:00:00 |
2013 | 9 | 30 | NA | 1842 | NA | NA | 2019 | NA | 5274 | NA | 764 | 18 | 42 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | NA | 1455 | NA | NA | 1634 | NA | 3393 | NA | 213 | 14 | 55 | 2013-09-30 14:00:00 |
2013 | 9 | 30 | NA | 2200 | NA | NA | 2312 | NA | 3525 | NA | 198 | 22 | 0 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | NA | 1210 | NA | NA | 1330 | NA | 3461 | NA | 764 | 12 | 10 | 2013-09-30 12:00:00 |
2013 | 9 | 30 | NA | 1159 | NA | NA | 1344 | NA | 3572 | NA | 419 | 11 | 59 | 2013-09-30 11:00:00 |
2013 | 9 | 30 | NA | 840 | NA | NA | 1020 | NA | 3531 | NA | 431 | 8 | 40 | 2013-09-30 08:00:00 |
# rename variable while select
flights |>
select(tail_num = tailnum)
tail_num |
---|
<chr> |
N14228 |
N24211 |
N619AA |
N804JB |
N668DN |
N39463 |
N516JB |
N829AS |
N593JB |
N3ALAA |
N793JB |
N657JB |
N29129 |
N53441 |
N3DUAA |
N708JB |
N76515 |
N595JB |
N542MQ |
N644JB |
N971DL |
N730MQ |
N633AA |
N3739P |
N53442 |
N9EAMQ |
N532UA |
N635JB |
N794JB |
N326NB |
... |
N712EV |
N16546 |
N807JB |
N751EV |
N807MQ |
N335AA |
N12957 |
N633JB |
N627JB |
N813UA |
N10575 |
N906XJ |
N722EV |
N532MQ |
N12145 |
N193JB |
N578UA |
N804JB |
N318JB |
N354JB |
N281JB |
N346JB |
N565JB |
N516JB |
N740EV |
NA |
NA |
N535MQ |
N511MQ |
N839MQ |
rename()
If you want to keep all the existing variables and just want to rename a few, you can use rename()
instead of select()
:
also try: janitor::clean_names()
flights |>
rename(tail_num = tailnum)
year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tail_num | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 1 | 517 | 515 | 2 | 830 | 819 | 11 | UA | 1545 | N14228 | EWR | IAH | 227 | 1400 | 5 | 15 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 533 | 529 | 4 | 850 | 830 | 20 | UA | 1714 | N24211 | LGA | IAH | 227 | 1416 | 5 | 29 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 542 | 540 | 2 | 923 | 850 | 33 | AA | 1141 | N619AA | JFK | MIA | 160 | 1089 | 5 | 40 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 544 | 545 | -1 | 1004 | 1022 | -18 | B6 | 725 | N804JB | JFK | BQN | 183 | 1576 | 5 | 45 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 554 | 600 | -6 | 812 | 837 | -25 | DL | 461 | N668DN | LGA | ATL | 116 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 554 | 558 | -4 | 740 | 728 | 12 | UA | 1696 | N39463 | EWR | ORD | 150 | 719 | 5 | 58 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 555 | 600 | -5 | 913 | 854 | 19 | B6 | 507 | N516JB | EWR | FLL | 158 | 1065 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 709 | 723 | -14 | EV | 5708 | N829AS | LGA | IAD | 53 | 229 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 838 | 846 | -8 | B6 | 79 | N593JB | JFK | MCO | 140 | 944 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 753 | 745 | 8 | AA | 301 | N3ALAA | LGA | ORD | 138 | 733 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 849 | 851 | -2 | B6 | 49 | N793JB | JFK | PBI | 149 | 1028 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 853 | 856 | -3 | B6 | 71 | N657JB | JFK | TPA | 158 | 1005 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 924 | 917 | 7 | UA | 194 | N29129 | JFK | LAX | 345 | 2475 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 923 | 937 | -14 | UA | 1124 | N53441 | EWR | SFO | 361 | 2565 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 941 | 910 | 31 | AA | 707 | N3DUAA | LGA | DFW | 257 | 1389 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 559 | 0 | 702 | 706 | -4 | B6 | 1806 | N708JB | JFK | BOS | 44 | 187 | 5 | 59 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 854 | 902 | -8 | UA | 1187 | N76515 | EWR | LAS | 337 | 2227 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 851 | 858 | -7 | B6 | 371 | N595JB | LGA | FLL | 152 | 1076 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 837 | 825 | 12 | MQ | 4650 | N542MQ | LGA | ATL | 134 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 601 | 600 | 1 | 844 | 850 | -6 | B6 | 343 | N644JB | EWR | PBI | 147 | 1023 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 610 | -8 | 812 | 820 | -8 | DL | 1919 | N971DL | LGA | MSP | 170 | 1020 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 605 | -3 | 821 | 805 | 16 | MQ | 4401 | N730MQ | LGA | DTW | 105 | 502 | 6 | 5 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 858 | 910 | -12 | AA | 1895 | N633AA | EWR | MIA | 152 | 1085 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 837 | 845 | -8 | DL | 1743 | N3739P | JFK | ATL | 128 | 760 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 607 | 607 | 0 | 858 | 915 | -17 | UA | 1077 | N53442 | EWR | MIA | 157 | 1085 | 6 | 7 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 608 | 600 | 8 | 807 | 735 | 32 | MQ | 3768 | N9EAMQ | EWR | ORD | 139 | 719 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 611 | 600 | 11 | 945 | 931 | 14 | UA | 303 | N532UA | JFK | SFO | 366 | 2586 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 613 | 610 | 3 | 925 | 921 | 4 | B6 | 135 | N635JB | JFK | RSW | 175 | 1074 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 1039 | 1100 | -21 | B6 | 709 | N794JB | JFK | SJU | 182 | 1598 | 6 | 15 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 833 | 842 | -9 | DL | 575 | N326NB | EWR | ATL | 120 | 746 | 6 | 15 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2013 | 9 | 30 | 2123 | 2125 | -2 | 2223 | 2247 | -24 | EV | 5489 | N712EV | LGA | CHO | 45 | 305 | 21 | 25 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2127 | 2129 | -2 | 2314 | 2323 | -9 | EV | 3833 | N16546 | EWR | CLT | 72 | 529 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2128 | 2130 | -2 | 2328 | 2359 | -31 | B6 | 97 | N807JB | JFK | DEN | 213 | 1626 | 21 | 30 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2129 | 2059 | 30 | 2230 | 2232 | -2 | EV | 5048 | N751EV | LGA | RIC | 45 | 292 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2131 | 2140 | -9 | 2225 | 2255 | -30 | MQ | 3621 | N807MQ | JFK | DCA | 36 | 213 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2140 | 2140 | 0 | 10 | 40 | -30 | AA | 185 | N335AA | JFK | LAX | 298 | 2475 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2142 | 2129 | 13 | 2250 | 2239 | 11 | EV | 4509 | N12957 | EWR | PWM | 47 | 284 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2145 | 2145 | 0 | 115 | 140 | -25 | B6 | 1103 | N633JB | JFK | SJU | 192 | 1598 | 21 | 45 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2147 | 2137 | 10 | 30 | 27 | 3 | B6 | 1371 | N627JB | LGA | FLL | 139 | 1076 | 21 | 37 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2149 | 2156 | -7 | 2245 | 2308 | -23 | UA | 523 | N813UA | EWR | BOS | 37 | 200 | 21 | 56 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2150 | 2159 | -9 | 2250 | 2306 | -16 | EV | 3842 | N10575 | EWR | MHT | 39 | 209 | 21 | 59 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2159 | 1845 | 194 | 2344 | 2030 | 194 | 9E | 3320 | N906XJ | JFK | BUF | 50 | 301 | 18 | 45 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | 2203 | 2205 | -2 | 2339 | 2331 | 8 | EV | 5311 | N722EV | LGA | BGR | 61 | 378 | 22 | 5 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2207 | 2140 | 27 | 2257 | 2250 | 7 | MQ | 3660 | N532MQ | LGA | BNA | 97 | 764 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2211 | 2059 | 72 | 2339 | 2242 | 57 | EV | 4672 | N12145 | EWR | STL | 120 | 872 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2231 | 2245 | -14 | 2335 | 2356 | -21 | B6 | 108 | N193JB | JFK | PWM | 48 | 273 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2233 | 2113 | 80 | 112 | 30 | 42 | UA | 471 | N578UA | EWR | SFO | 318 | 2565 | 21 | 13 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2235 | 2001 | 154 | 59 | 2249 | 130 | B6 | 1083 | N804JB | JFK | MCO | 123 | 944 | 20 | 1 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2237 | 2245 | -8 | 2345 | 2353 | -8 | B6 | 234 | N318JB | JFK | BTV | 43 | 266 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2245 | -5 | 2334 | 2351 | -17 | B6 | 1816 | N354JB | JFK | SYR | 41 | 209 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2250 | -10 | 2347 | 7 | -20 | B6 | 2002 | N281JB | JFK | BUF | 52 | 301 | 22 | 50 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2241 | 2246 | -5 | 2345 | 1 | -16 | B6 | 486 | N346JB | JFK | ROC | 47 | 264 | 22 | 46 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2307 | 2255 | 12 | 2359 | 2358 | 1 | B6 | 718 | N565JB | JFK | BOS | 33 | 187 | 22 | 55 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2349 | 2359 | -10 | 325 | 350 | -25 | B6 | 745 | N516JB | JFK | PSE | 196 | 1617 | 23 | 59 | 2013-09-30 23:00:00 |
2013 | 9 | 30 | NA | 1842 | NA | NA | 2019 | NA | EV | 5274 | N740EV | LGA | BNA | NA | 764 | 18 | 42 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | NA | 1455 | NA | NA | 1634 | NA | 9E | 3393 | NA | JFK | DCA | NA | 213 | 14 | 55 | 2013-09-30 14:00:00 |
2013 | 9 | 30 | NA | 2200 | NA | NA | 2312 | NA | 9E | 3525 | NA | LGA | SYR | NA | 198 | 22 | 0 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | NA | 1210 | NA | NA | 1330 | NA | MQ | 3461 | N535MQ | LGA | BNA | NA | 764 | 12 | 10 | 2013-09-30 12:00:00 |
2013 | 9 | 30 | NA | 1159 | NA | NA | 1344 | NA | MQ | 3572 | N511MQ | LGA | CLE | NA | 419 | 11 | 59 | 2013-09-30 11:00:00 |
2013 | 9 | 30 | NA | 840 | NA | NA | 1020 | NA | MQ | 3531 | N839MQ | LGA | RDU | NA | 431 | 8 | 40 | 2013-09-30 08:00:00 |
relocate()
By default relocate()
moves variables to the front:
flights |>
relocate(time_hour, air_time)
# flights |>
# relocate(year:dep_time, .after = time_hour)
# flights |>
# relocate(starts_with("arr"), .before = dep_time)
time_hour | air_time | year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | dest | distance | hour | minute |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<dttm> | <dbl> | <int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> |
2013-01-01 05:00:00 | 227 | 2013 | 1 | 1 | 517 | 515 | 2 | 830 | 819 | 11 | UA | 1545 | N14228 | EWR | IAH | 1400 | 5 | 15 |
2013-01-01 05:00:00 | 227 | 2013 | 1 | 1 | 533 | 529 | 4 | 850 | 830 | 20 | UA | 1714 | N24211 | LGA | IAH | 1416 | 5 | 29 |
2013-01-01 05:00:00 | 160 | 2013 | 1 | 1 | 542 | 540 | 2 | 923 | 850 | 33 | AA | 1141 | N619AA | JFK | MIA | 1089 | 5 | 40 |
2013-01-01 05:00:00 | 183 | 2013 | 1 | 1 | 544 | 545 | -1 | 1004 | 1022 | -18 | B6 | 725 | N804JB | JFK | BQN | 1576 | 5 | 45 |
2013-01-01 06:00:00 | 116 | 2013 | 1 | 1 | 554 | 600 | -6 | 812 | 837 | -25 | DL | 461 | N668DN | LGA | ATL | 762 | 6 | 0 |
2013-01-01 05:00:00 | 150 | 2013 | 1 | 1 | 554 | 558 | -4 | 740 | 728 | 12 | UA | 1696 | N39463 | EWR | ORD | 719 | 5 | 58 |
2013-01-01 06:00:00 | 158 | 2013 | 1 | 1 | 555 | 600 | -5 | 913 | 854 | 19 | B6 | 507 | N516JB | EWR | FLL | 1065 | 6 | 0 |
2013-01-01 06:00:00 | 53 | 2013 | 1 | 1 | 557 | 600 | -3 | 709 | 723 | -14 | EV | 5708 | N829AS | LGA | IAD | 229 | 6 | 0 |
2013-01-01 06:00:00 | 140 | 2013 | 1 | 1 | 557 | 600 | -3 | 838 | 846 | -8 | B6 | 79 | N593JB | JFK | MCO | 944 | 6 | 0 |
2013-01-01 06:00:00 | 138 | 2013 | 1 | 1 | 558 | 600 | -2 | 753 | 745 | 8 | AA | 301 | N3ALAA | LGA | ORD | 733 | 6 | 0 |
2013-01-01 06:00:00 | 149 | 2013 | 1 | 1 | 558 | 600 | -2 | 849 | 851 | -2 | B6 | 49 | N793JB | JFK | PBI | 1028 | 6 | 0 |
2013-01-01 06:00:00 | 158 | 2013 | 1 | 1 | 558 | 600 | -2 | 853 | 856 | -3 | B6 | 71 | N657JB | JFK | TPA | 1005 | 6 | 0 |
2013-01-01 06:00:00 | 345 | 2013 | 1 | 1 | 558 | 600 | -2 | 924 | 917 | 7 | UA | 194 | N29129 | JFK | LAX | 2475 | 6 | 0 |
2013-01-01 06:00:00 | 361 | 2013 | 1 | 1 | 558 | 600 | -2 | 923 | 937 | -14 | UA | 1124 | N53441 | EWR | SFO | 2565 | 6 | 0 |
2013-01-01 06:00:00 | 257 | 2013 | 1 | 1 | 559 | 600 | -1 | 941 | 910 | 31 | AA | 707 | N3DUAA | LGA | DFW | 1389 | 6 | 0 |
2013-01-01 05:00:00 | 44 | 2013 | 1 | 1 | 559 | 559 | 0 | 702 | 706 | -4 | B6 | 1806 | N708JB | JFK | BOS | 187 | 5 | 59 |
2013-01-01 06:00:00 | 337 | 2013 | 1 | 1 | 559 | 600 | -1 | 854 | 902 | -8 | UA | 1187 | N76515 | EWR | LAS | 2227 | 6 | 0 |
2013-01-01 06:00:00 | 152 | 2013 | 1 | 1 | 600 | 600 | 0 | 851 | 858 | -7 | B6 | 371 | N595JB | LGA | FLL | 1076 | 6 | 0 |
2013-01-01 06:00:00 | 134 | 2013 | 1 | 1 | 600 | 600 | 0 | 837 | 825 | 12 | MQ | 4650 | N542MQ | LGA | ATL | 762 | 6 | 0 |
2013-01-01 06:00:00 | 147 | 2013 | 1 | 1 | 601 | 600 | 1 | 844 | 850 | -6 | B6 | 343 | N644JB | EWR | PBI | 1023 | 6 | 0 |
2013-01-01 06:00:00 | 170 | 2013 | 1 | 1 | 602 | 610 | -8 | 812 | 820 | -8 | DL | 1919 | N971DL | LGA | MSP | 1020 | 6 | 10 |
2013-01-01 06:00:00 | 105 | 2013 | 1 | 1 | 602 | 605 | -3 | 821 | 805 | 16 | MQ | 4401 | N730MQ | LGA | DTW | 502 | 6 | 5 |
2013-01-01 06:00:00 | 152 | 2013 | 1 | 1 | 606 | 610 | -4 | 858 | 910 | -12 | AA | 1895 | N633AA | EWR | MIA | 1085 | 6 | 10 |
2013-01-01 06:00:00 | 128 | 2013 | 1 | 1 | 606 | 610 | -4 | 837 | 845 | -8 | DL | 1743 | N3739P | JFK | ATL | 760 | 6 | 10 |
2013-01-01 06:00:00 | 157 | 2013 | 1 | 1 | 607 | 607 | 0 | 858 | 915 | -17 | UA | 1077 | N53442 | EWR | MIA | 1085 | 6 | 7 |
2013-01-01 06:00:00 | 139 | 2013 | 1 | 1 | 608 | 600 | 8 | 807 | 735 | 32 | MQ | 3768 | N9EAMQ | EWR | ORD | 719 | 6 | 0 |
2013-01-01 06:00:00 | 366 | 2013 | 1 | 1 | 611 | 600 | 11 | 945 | 931 | 14 | UA | 303 | N532UA | JFK | SFO | 2586 | 6 | 0 |
2013-01-01 06:00:00 | 175 | 2013 | 1 | 1 | 613 | 610 | 3 | 925 | 921 | 4 | B6 | 135 | N635JB | JFK | RSW | 1074 | 6 | 10 |
2013-01-01 06:00:00 | 182 | 2013 | 1 | 1 | 615 | 615 | 0 | 1039 | 1100 | -21 | B6 | 709 | N794JB | JFK | SJU | 1598 | 6 | 15 |
2013-01-01 06:00:00 | 120 | 2013 | 1 | 1 | 615 | 615 | 0 | 833 | 842 | -9 | DL | 575 | N326NB | EWR | ATL | 746 | 6 | 15 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2013-09-30 21:00:00 | 45 | 2013 | 9 | 30 | 2123 | 2125 | -2 | 2223 | 2247 | -24 | EV | 5489 | N712EV | LGA | CHO | 305 | 21 | 25 |
2013-09-30 21:00:00 | 72 | 2013 | 9 | 30 | 2127 | 2129 | -2 | 2314 | 2323 | -9 | EV | 3833 | N16546 | EWR | CLT | 529 | 21 | 29 |
2013-09-30 21:00:00 | 213 | 2013 | 9 | 30 | 2128 | 2130 | -2 | 2328 | 2359 | -31 | B6 | 97 | N807JB | JFK | DEN | 1626 | 21 | 30 |
2013-09-30 20:00:00 | 45 | 2013 | 9 | 30 | 2129 | 2059 | 30 | 2230 | 2232 | -2 | EV | 5048 | N751EV | LGA | RIC | 292 | 20 | 59 |
2013-09-30 21:00:00 | 36 | 2013 | 9 | 30 | 2131 | 2140 | -9 | 2225 | 2255 | -30 | MQ | 3621 | N807MQ | JFK | DCA | 213 | 21 | 40 |
2013-09-30 21:00:00 | 298 | 2013 | 9 | 30 | 2140 | 2140 | 0 | 10 | 40 | -30 | AA | 185 | N335AA | JFK | LAX | 2475 | 21 | 40 |
2013-09-30 21:00:00 | 47 | 2013 | 9 | 30 | 2142 | 2129 | 13 | 2250 | 2239 | 11 | EV | 4509 | N12957 | EWR | PWM | 284 | 21 | 29 |
2013-09-30 21:00:00 | 192 | 2013 | 9 | 30 | 2145 | 2145 | 0 | 115 | 140 | -25 | B6 | 1103 | N633JB | JFK | SJU | 1598 | 21 | 45 |
2013-09-30 21:00:00 | 139 | 2013 | 9 | 30 | 2147 | 2137 | 10 | 30 | 27 | 3 | B6 | 1371 | N627JB | LGA | FLL | 1076 | 21 | 37 |
2013-09-30 21:00:00 | 37 | 2013 | 9 | 30 | 2149 | 2156 | -7 | 2245 | 2308 | -23 | UA | 523 | N813UA | EWR | BOS | 200 | 21 | 56 |
2013-09-30 21:00:00 | 39 | 2013 | 9 | 30 | 2150 | 2159 | -9 | 2250 | 2306 | -16 | EV | 3842 | N10575 | EWR | MHT | 209 | 21 | 59 |
2013-09-30 18:00:00 | 50 | 2013 | 9 | 30 | 2159 | 1845 | 194 | 2344 | 2030 | 194 | 9E | 3320 | N906XJ | JFK | BUF | 301 | 18 | 45 |
2013-09-30 22:00:00 | 61 | 2013 | 9 | 30 | 2203 | 2205 | -2 | 2339 | 2331 | 8 | EV | 5311 | N722EV | LGA | BGR | 378 | 22 | 5 |
2013-09-30 21:00:00 | 97 | 2013 | 9 | 30 | 2207 | 2140 | 27 | 2257 | 2250 | 7 | MQ | 3660 | N532MQ | LGA | BNA | 764 | 21 | 40 |
2013-09-30 20:00:00 | 120 | 2013 | 9 | 30 | 2211 | 2059 | 72 | 2339 | 2242 | 57 | EV | 4672 | N12145 | EWR | STL | 872 | 20 | 59 |
2013-09-30 22:00:00 | 48 | 2013 | 9 | 30 | 2231 | 2245 | -14 | 2335 | 2356 | -21 | B6 | 108 | N193JB | JFK | PWM | 273 | 22 | 45 |
2013-09-30 21:00:00 | 318 | 2013 | 9 | 30 | 2233 | 2113 | 80 | 112 | 30 | 42 | UA | 471 | N578UA | EWR | SFO | 2565 | 21 | 13 |
2013-09-30 20:00:00 | 123 | 2013 | 9 | 30 | 2235 | 2001 | 154 | 59 | 2249 | 130 | B6 | 1083 | N804JB | JFK | MCO | 944 | 20 | 1 |
2013-09-30 22:00:00 | 43 | 2013 | 9 | 30 | 2237 | 2245 | -8 | 2345 | 2353 | -8 | B6 | 234 | N318JB | JFK | BTV | 266 | 22 | 45 |
2013-09-30 22:00:00 | 41 | 2013 | 9 | 30 | 2240 | 2245 | -5 | 2334 | 2351 | -17 | B6 | 1816 | N354JB | JFK | SYR | 209 | 22 | 45 |
2013-09-30 22:00:00 | 52 | 2013 | 9 | 30 | 2240 | 2250 | -10 | 2347 | 7 | -20 | B6 | 2002 | N281JB | JFK | BUF | 301 | 22 | 50 |
2013-09-30 22:00:00 | 47 | 2013 | 9 | 30 | 2241 | 2246 | -5 | 2345 | 1 | -16 | B6 | 486 | N346JB | JFK | ROC | 264 | 22 | 46 |
2013-09-30 22:00:00 | 33 | 2013 | 9 | 30 | 2307 | 2255 | 12 | 2359 | 2358 | 1 | B6 | 718 | N565JB | JFK | BOS | 187 | 22 | 55 |
2013-09-30 23:00:00 | 196 | 2013 | 9 | 30 | 2349 | 2359 | -10 | 325 | 350 | -25 | B6 | 745 | N516JB | JFK | PSE | 1617 | 23 | 59 |
2013-09-30 18:00:00 | NA | 2013 | 9 | 30 | NA | 1842 | NA | NA | 2019 | NA | EV | 5274 | N740EV | LGA | BNA | 764 | 18 | 42 |
2013-09-30 14:00:00 | NA | 2013 | 9 | 30 | NA | 1455 | NA | NA | 1634 | NA | 9E | 3393 | NA | JFK | DCA | 213 | 14 | 55 |
2013-09-30 22:00:00 | NA | 2013 | 9 | 30 | NA | 2200 | NA | NA | 2312 | NA | 9E | 3525 | NA | LGA | SYR | 198 | 22 | 0 |
2013-09-30 12:00:00 | NA | 2013 | 9 | 30 | NA | 1210 | NA | NA | 1330 | NA | MQ | 3461 | N535MQ | LGA | BNA | 764 | 12 | 10 |
2013-09-30 11:00:00 | NA | 2013 | 9 | 30 | NA | 1159 | NA | NA | 1344 | NA | MQ | 3572 | N511MQ | LGA | CLE | 419 | 11 | 59 |
2013-09-30 08:00:00 | NA | 2013 | 9 | 30 | NA | 840 | NA | NA | 1020 | NA | MQ | 3531 | N839MQ | LGA | RDU | 431 | 8 | 40 |
3.3. Exercises
3.3.1 Compare dep_time, sched_dep_time, and dep_delay. How would you expect those three numbers to be related?
3.3.2. Brainstorm as many ways as possible to select dep_time, dep_delay, arr_time, and arr_delay from flights.
3.3.3. What happens if you specify the name of the same variable multiple times in a select() call?
3.3.4. What does the any_of() function do? Why might it be helpful in conjunction with this vector?
variables <- c("year", "month", "day", "dep_delay", "arr_delay")
3.3.5. Does the result of running the following code surprise you? How do the select helpers deal with upper and lower case by default? How can you change that default?
flights |> select(contains("TIME"))
dep_time | sched_dep_time | arr_time | sched_arr_time | air_time | time_hour |
---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <dbl> | <dttm> |
517 | 515 | 830 | 819 | 227 | 2013-01-01 05:00:00 |
533 | 529 | 850 | 830 | 227 | 2013-01-01 05:00:00 |
542 | 540 | 923 | 850 | 160 | 2013-01-01 05:00:00 |
544 | 545 | 1004 | 1022 | 183 | 2013-01-01 05:00:00 |
554 | 600 | 812 | 837 | 116 | 2013-01-01 06:00:00 |
554 | 558 | 740 | 728 | 150 | 2013-01-01 05:00:00 |
555 | 600 | 913 | 854 | 158 | 2013-01-01 06:00:00 |
557 | 600 | 709 | 723 | 53 | 2013-01-01 06:00:00 |
557 | 600 | 838 | 846 | 140 | 2013-01-01 06:00:00 |
558 | 600 | 753 | 745 | 138 | 2013-01-01 06:00:00 |
558 | 600 | 849 | 851 | 149 | 2013-01-01 06:00:00 |
558 | 600 | 853 | 856 | 158 | 2013-01-01 06:00:00 |
558 | 600 | 924 | 917 | 345 | 2013-01-01 06:00:00 |
558 | 600 | 923 | 937 | 361 | 2013-01-01 06:00:00 |
559 | 600 | 941 | 910 | 257 | 2013-01-01 06:00:00 |
559 | 559 | 702 | 706 | 44 | 2013-01-01 05:00:00 |
559 | 600 | 854 | 902 | 337 | 2013-01-01 06:00:00 |
600 | 600 | 851 | 858 | 152 | 2013-01-01 06:00:00 |
600 | 600 | 837 | 825 | 134 | 2013-01-01 06:00:00 |
601 | 600 | 844 | 850 | 147 | 2013-01-01 06:00:00 |
602 | 610 | 812 | 820 | 170 | 2013-01-01 06:00:00 |
602 | 605 | 821 | 805 | 105 | 2013-01-01 06:00:00 |
606 | 610 | 858 | 910 | 152 | 2013-01-01 06:00:00 |
606 | 610 | 837 | 845 | 128 | 2013-01-01 06:00:00 |
607 | 607 | 858 | 915 | 157 | 2013-01-01 06:00:00 |
608 | 600 | 807 | 735 | 139 | 2013-01-01 06:00:00 |
611 | 600 | 945 | 931 | 366 | 2013-01-01 06:00:00 |
613 | 610 | 925 | 921 | 175 | 2013-01-01 06:00:00 |
615 | 615 | 1039 | 1100 | 182 | 2013-01-01 06:00:00 |
615 | 615 | 833 | 842 | 120 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... |
2123 | 2125 | 2223 | 2247 | 45 | 2013-09-30 21:00:00 |
2127 | 2129 | 2314 | 2323 | 72 | 2013-09-30 21:00:00 |
2128 | 2130 | 2328 | 2359 | 213 | 2013-09-30 21:00:00 |
2129 | 2059 | 2230 | 2232 | 45 | 2013-09-30 20:00:00 |
2131 | 2140 | 2225 | 2255 | 36 | 2013-09-30 21:00:00 |
2140 | 2140 | 10 | 40 | 298 | 2013-09-30 21:00:00 |
2142 | 2129 | 2250 | 2239 | 47 | 2013-09-30 21:00:00 |
2145 | 2145 | 115 | 140 | 192 | 2013-09-30 21:00:00 |
2147 | 2137 | 30 | 27 | 139 | 2013-09-30 21:00:00 |
2149 | 2156 | 2245 | 2308 | 37 | 2013-09-30 21:00:00 |
2150 | 2159 | 2250 | 2306 | 39 | 2013-09-30 21:00:00 |
2159 | 1845 | 2344 | 2030 | 50 | 2013-09-30 18:00:00 |
2203 | 2205 | 2339 | 2331 | 61 | 2013-09-30 22:00:00 |
2207 | 2140 | 2257 | 2250 | 97 | 2013-09-30 21:00:00 |
2211 | 2059 | 2339 | 2242 | 120 | 2013-09-30 20:00:00 |
2231 | 2245 | 2335 | 2356 | 48 | 2013-09-30 22:00:00 |
2233 | 2113 | 112 | 30 | 318 | 2013-09-30 21:00:00 |
2235 | 2001 | 59 | 2249 | 123 | 2013-09-30 20:00:00 |
2237 | 2245 | 2345 | 2353 | 43 | 2013-09-30 22:00:00 |
2240 | 2245 | 2334 | 2351 | 41 | 2013-09-30 22:00:00 |
2240 | 2250 | 2347 | 7 | 52 | 2013-09-30 22:00:00 |
2241 | 2246 | 2345 | 1 | 47 | 2013-09-30 22:00:00 |
2307 | 2255 | 2359 | 2358 | 33 | 2013-09-30 22:00:00 |
2349 | 2359 | 325 | 350 | 196 | 2013-09-30 23:00:00 |
NA | 1842 | NA | 2019 | NA | 2013-09-30 18:00:00 |
NA | 1455 | NA | 1634 | NA | 2013-09-30 14:00:00 |
NA | 2200 | NA | 2312 | NA | 2013-09-30 22:00:00 |
NA | 1210 | NA | 1330 | NA | 2013-09-30 12:00:00 |
NA | 1159 | NA | 1344 | NA | 2013-09-30 11:00:00 |
NA | 840 | NA | 1020 | NA | 2013-09-30 08:00:00 |
3.3.6. Rename air_time to air_time_min to indicate units of measurement and move it to the beginning of the data frame.
3.3.7. Why doesn’t the following work, and what does the error mean?
flights |>
select(tailnum) |>
arrange(arr_delay)
Error in `arrange()`:
i In argument: `..1 = arr_delay`.
Caused by error:
! object 'arr_delay' not found
Traceback:
1. arrange(select(flights, tailnum), arr_delay)
2. arrange.data.frame(select(flights, tailnum), arr_delay)
3. arrange_rows(.data, dots = dots, locale = .locale)
4. mutate(data, `:=`("{name}", !!dot), .keep = "none")
5. mutate.data.frame(data, `:=`("{name}", !!dot), .keep = "none")
6. mutate_cols(.data, dplyr_quosures(...), by)
7. withCallingHandlers(for (i in seq_along(dots)) {
. poke_error_context(dots, i, mask = mask)
. context_poke("column", old_current_column)
. new_columns <- mutate_col(dots[[i]], data, mask, new_columns)
. }, error = dplyr_error_handler(dots = dots, mask = mask, bullets = mutate_bullets,
. error_call = error_call, error_class = "dplyr:::mutate_error"),
. warning = dplyr_warning_handler(state = warnings_state, mask = mask,
. error_call = error_call))
8. mutate_col(dots[[i]], data, mask, new_columns)
9. mask$eval_all_mutate(quo)
10. eval()
11. .handleSimpleError(function (cnd)
. {
. local_error_context(dots, i = frame[[i_sym]], mask = mask)
. if (inherits(cnd, "dplyr:::internal_error")) {
. parent <- error_cnd(message = bullets(cnd))
. }
. else {
. parent <- cnd
. }
. message <- c(cnd_bullet_header(action), i = if (has_active_group_context(mask)) cnd_bullet_cur_group_label())
. abort(message, class = error_class, parent = parent, call = error_call)
. }, "object 'arr_delay' not found", base::quote(NULL))
12. h(simpleError(msg, call))
13. abort(message, class = error_class, parent = parent, call = error_call)
14. signal_abort(cnd, .file)
The pipe
flights |>
filter(dest == "IAH") |>
mutate(speed = distance / air_time * 60) |>
select(year:day, dep_time, carrier, flight, speed) |>
arrange(desc(speed))
year | month | day | dep_time | carrier | flight | speed |
---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <chr> | <int> | <dbl> |
2013 | 7 | 9 | 707 | UA | 226 | 521.7391 |
2013 | 8 | 27 | 1850 | UA | 1128 | 521.2270 |
2013 | 8 | 28 | 902 | UA | 1711 | 518.5185 |
2013 | 8 | 28 | 2122 | UA | 1022 | 518.5185 |
2013 | 6 | 11 | 1628 | UA | 1178 | 515.3374 |
2013 | 8 | 27 | 1017 | UA | 333 | 515.3374 |
2013 | 8 | 27 | 1205 | UA | 1421 | 515.3374 |
2013 | 8 | 27 | 1758 | UA | 302 | 515.3374 |
2013 | 9 | 27 | 521 | UA | 252 | 515.3374 |
2013 | 8 | 28 | 625 | UA | 559 | 514.9091 |
2013 | 8 | 28 | 1505 | UA | 1695 | 512.1951 |
2013 | 9 | 7 | 2025 | UA | 1022 | 512.1951 |
2013 | 9 | 8 | 1830 | UA | 404 | 512.1951 |
2013 | 8 | 27 | 1651 | UA | 525 | 511.8072 |
2013 | 9 | 4 | 542 | UA | 1714 | 511.8072 |
2013 | 9 | 6 | 2006 | UA | 1128 | 511.8072 |
2013 | 9 | 8 | 1849 | UA | 1128 | 511.8072 |
2013 | 6 | 11 | 2017 | UA | 350 | 509.0909 |
2013 | 7 | 8 | 2131 | UA | 260 | 509.0909 |
2013 | 7 | 8 | 2213 | UA | 1740 | 509.0909 |
2013 | 7 | 12 | 1718 | UA | 268 | 509.0909 |
2013 | 7 | 19 | 634 | UA | 226 | 509.0909 |
2013 | 9 | 27 | 2003 | UA | 1712 | 509.0909 |
2013 | 8 | 27 | 1854 | UA | 315 | 508.7425 |
2013 | 6 | 11 | 1517 | UA | 1611 | 506.0241 |
2013 | 6 | 15 | 852 | UA | 215 | 506.0241 |
2013 | 7 | 7 | 1649 | UA | 1254 | 506.0241 |
2013 | 7 | 9 | 851 | UA | 1711 | 506.0241 |
2013 | 7 | 9 | 2001 | UA | 299 | 506.0241 |
2013 | 7 | 9 | 2331 | UA | 1178 | 506.0241 |
... | ... | ... | ... | ... | ... | ... |
2013 | 6 | 10 | NA | UA | 318 | NA |
2013 | 6 | 15 | 2037 | UA | 1611 | NA |
2013 | 6 | 17 | NA | UA | 318 | NA |
2013 | 6 | 17 | NA | UA | 1178 | NA |
2013 | 6 | 19 | NA | UA | 430 | NA |
2013 | 6 | 19 | NA | UA | 531 | NA |
2013 | 6 | 20 | 1256 | UA | 636 | NA |
2013 | 6 | 22 | NA | UA | 251 | NA |
2013 | 6 | 25 | NA | UA | 453 | NA |
2013 | 6 | 27 | 1951 | UA | 1611 | NA |
2013 | 6 | 28 | NA | UA | 768 | NA |
2013 | 7 | 10 | 1905 | AA | 1901 | NA |
2013 | 7 | 10 | NA | UA | 1661 | NA |
2013 | 7 | 11 | NA | UA | 508 | NA |
2013 | 7 | 16 | 1302 | UA | 824 | NA |
2013 | 7 | 17 | NA | UA | 226 | NA |
2013 | 7 | 22 | NA | UA | 1259 | NA |
2013 | 7 | 22 | NA | UA | 1661 | NA |
2013 | 7 | 23 | NA | UA | 1454 | NA |
2013 | 7 | 28 | NA | UA | 408 | NA |
2013 | 8 | 2 | NA | UA | 349 | NA |
2013 | 8 | 13 | NA | UA | 220 | NA |
2013 | 8 | 14 | 1537 | UA | 1178 | NA |
2013 | 8 | 16 | 1456 | UA | 1257 | NA |
2013 | 9 | 2 | NA | UA | 1128 | NA |
2013 | 9 | 12 | 1815 | UA | 1695 | NA |
2013 | 9 | 12 | NA | UA | 404 | NA |
2013 | 9 | 12 | NA | UA | 525 | NA |
2013 | 9 | 12 | NA | UA | 1128 | NA |
2013 | 9 | 20 | 752 | UA | 1591 | NA |
What would happen if we didn’t have the pipe? We could nest each function call inside the previous call:
arrange(
select(
mutate(
filter(
flights,
dest == "IAH"
),
speed = distance / air_time * 60
),
year:day, dep_time, carrier, flight, speed
),
desc(speed)
)
year | month | day | dep_time | carrier | flight | speed |
---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <chr> | <int> | <dbl> |
2013 | 7 | 9 | 707 | UA | 226 | 521.7391 |
2013 | 8 | 27 | 1850 | UA | 1128 | 521.2270 |
2013 | 8 | 28 | 902 | UA | 1711 | 518.5185 |
2013 | 8 | 28 | 2122 | UA | 1022 | 518.5185 |
2013 | 6 | 11 | 1628 | UA | 1178 | 515.3374 |
2013 | 8 | 27 | 1017 | UA | 333 | 515.3374 |
2013 | 8 | 27 | 1205 | UA | 1421 | 515.3374 |
2013 | 8 | 27 | 1758 | UA | 302 | 515.3374 |
2013 | 9 | 27 | 521 | UA | 252 | 515.3374 |
2013 | 8 | 28 | 625 | UA | 559 | 514.9091 |
2013 | 8 | 28 | 1505 | UA | 1695 | 512.1951 |
2013 | 9 | 7 | 2025 | UA | 1022 | 512.1951 |
2013 | 9 | 8 | 1830 | UA | 404 | 512.1951 |
2013 | 8 | 27 | 1651 | UA | 525 | 511.8072 |
2013 | 9 | 4 | 542 | UA | 1714 | 511.8072 |
2013 | 9 | 6 | 2006 | UA | 1128 | 511.8072 |
2013 | 9 | 8 | 1849 | UA | 1128 | 511.8072 |
2013 | 6 | 11 | 2017 | UA | 350 | 509.0909 |
2013 | 7 | 8 | 2131 | UA | 260 | 509.0909 |
2013 | 7 | 8 | 2213 | UA | 1740 | 509.0909 |
2013 | 7 | 12 | 1718 | UA | 268 | 509.0909 |
2013 | 7 | 19 | 634 | UA | 226 | 509.0909 |
2013 | 9 | 27 | 2003 | UA | 1712 | 509.0909 |
2013 | 8 | 27 | 1854 | UA | 315 | 508.7425 |
2013 | 6 | 11 | 1517 | UA | 1611 | 506.0241 |
2013 | 6 | 15 | 852 | UA | 215 | 506.0241 |
2013 | 7 | 7 | 1649 | UA | 1254 | 506.0241 |
2013 | 7 | 9 | 851 | UA | 1711 | 506.0241 |
2013 | 7 | 9 | 2001 | UA | 299 | 506.0241 |
2013 | 7 | 9 | 2331 | UA | 1178 | 506.0241 |
... | ... | ... | ... | ... | ... | ... |
2013 | 6 | 10 | NA | UA | 318 | NA |
2013 | 6 | 15 | 2037 | UA | 1611 | NA |
2013 | 6 | 17 | NA | UA | 318 | NA |
2013 | 6 | 17 | NA | UA | 1178 | NA |
2013 | 6 | 19 | NA | UA | 430 | NA |
2013 | 6 | 19 | NA | UA | 531 | NA |
2013 | 6 | 20 | 1256 | UA | 636 | NA |
2013 | 6 | 22 | NA | UA | 251 | NA |
2013 | 6 | 25 | NA | UA | 453 | NA |
2013 | 6 | 27 | 1951 | UA | 1611 | NA |
2013 | 6 | 28 | NA | UA | 768 | NA |
2013 | 7 | 10 | 1905 | AA | 1901 | NA |
2013 | 7 | 10 | NA | UA | 1661 | NA |
2013 | 7 | 11 | NA | UA | 508 | NA |
2013 | 7 | 16 | 1302 | UA | 824 | NA |
2013 | 7 | 17 | NA | UA | 226 | NA |
2013 | 7 | 22 | NA | UA | 1259 | NA |
2013 | 7 | 22 | NA | UA | 1661 | NA |
2013 | 7 | 23 | NA | UA | 1454 | NA |
2013 | 7 | 28 | NA | UA | 408 | NA |
2013 | 8 | 2 | NA | UA | 349 | NA |
2013 | 8 | 13 | NA | UA | 220 | NA |
2013 | 8 | 14 | 1537 | UA | 1178 | NA |
2013 | 8 | 16 | 1456 | UA | 1257 | NA |
2013 | 9 | 2 | NA | UA | 1128 | NA |
2013 | 9 | 12 | 1815 | UA | 1695 | NA |
2013 | 9 | 12 | NA | UA | 404 | NA |
2013 | 9 | 12 | NA | UA | 525 | NA |
2013 | 9 | 12 | NA | UA | 1128 | NA |
2013 | 9 | 20 | 752 | UA | 1591 | NA |
Or we could use a bunch of intermediate objects:
flights1 <- filter(flights, dest == "IAH")
flights2 <- mutate(flights1, speed = distance / air_time * 60)
flights3 <- select(flights2, year:day, dep_time, carrier, flight, speed)
arrange(flights3, desc(speed))
year | month | day | dep_time | carrier | flight | speed |
---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <chr> | <int> | <dbl> |
2013 | 7 | 9 | 707 | UA | 226 | 521.7391 |
2013 | 8 | 27 | 1850 | UA | 1128 | 521.2270 |
2013 | 8 | 28 | 902 | UA | 1711 | 518.5185 |
2013 | 8 | 28 | 2122 | UA | 1022 | 518.5185 |
2013 | 6 | 11 | 1628 | UA | 1178 | 515.3374 |
2013 | 8 | 27 | 1017 | UA | 333 | 515.3374 |
2013 | 8 | 27 | 1205 | UA | 1421 | 515.3374 |
2013 | 8 | 27 | 1758 | UA | 302 | 515.3374 |
2013 | 9 | 27 | 521 | UA | 252 | 515.3374 |
2013 | 8 | 28 | 625 | UA | 559 | 514.9091 |
2013 | 8 | 28 | 1505 | UA | 1695 | 512.1951 |
2013 | 9 | 7 | 2025 | UA | 1022 | 512.1951 |
2013 | 9 | 8 | 1830 | UA | 404 | 512.1951 |
2013 | 8 | 27 | 1651 | UA | 525 | 511.8072 |
2013 | 9 | 4 | 542 | UA | 1714 | 511.8072 |
2013 | 9 | 6 | 2006 | UA | 1128 | 511.8072 |
2013 | 9 | 8 | 1849 | UA | 1128 | 511.8072 |
2013 | 6 | 11 | 2017 | UA | 350 | 509.0909 |
2013 | 7 | 8 | 2131 | UA | 260 | 509.0909 |
2013 | 7 | 8 | 2213 | UA | 1740 | 509.0909 |
2013 | 7 | 12 | 1718 | UA | 268 | 509.0909 |
2013 | 7 | 19 | 634 | UA | 226 | 509.0909 |
2013 | 9 | 27 | 2003 | UA | 1712 | 509.0909 |
2013 | 8 | 27 | 1854 | UA | 315 | 508.7425 |
2013 | 6 | 11 | 1517 | UA | 1611 | 506.0241 |
2013 | 6 | 15 | 852 | UA | 215 | 506.0241 |
2013 | 7 | 7 | 1649 | UA | 1254 | 506.0241 |
2013 | 7 | 9 | 851 | UA | 1711 | 506.0241 |
2013 | 7 | 9 | 2001 | UA | 299 | 506.0241 |
2013 | 7 | 9 | 2331 | UA | 1178 | 506.0241 |
... | ... | ... | ... | ... | ... | ... |
2013 | 6 | 10 | NA | UA | 318 | NA |
2013 | 6 | 15 | 2037 | UA | 1611 | NA |
2013 | 6 | 17 | NA | UA | 318 | NA |
2013 | 6 | 17 | NA | UA | 1178 | NA |
2013 | 6 | 19 | NA | UA | 430 | NA |
2013 | 6 | 19 | NA | UA | 531 | NA |
2013 | 6 | 20 | 1256 | UA | 636 | NA |
2013 | 6 | 22 | NA | UA | 251 | NA |
2013 | 6 | 25 | NA | UA | 453 | NA |
2013 | 6 | 27 | 1951 | UA | 1611 | NA |
2013 | 6 | 28 | NA | UA | 768 | NA |
2013 | 7 | 10 | 1905 | AA | 1901 | NA |
2013 | 7 | 10 | NA | UA | 1661 | NA |
2013 | 7 | 11 | NA | UA | 508 | NA |
2013 | 7 | 16 | 1302 | UA | 824 | NA |
2013 | 7 | 17 | NA | UA | 226 | NA |
2013 | 7 | 22 | NA | UA | 1259 | NA |
2013 | 7 | 22 | NA | UA | 1661 | NA |
2013 | 7 | 23 | NA | UA | 1454 | NA |
2013 | 7 | 28 | NA | UA | 408 | NA |
2013 | 8 | 2 | NA | UA | 349 | NA |
2013 | 8 | 13 | NA | UA | 220 | NA |
2013 | 8 | 14 | 1537 | UA | 1178 | NA |
2013 | 8 | 16 | 1456 | UA | 1257 | NA |
2013 | 9 | 2 | NA | UA | 1128 | NA |
2013 | 9 | 12 | 1815 | UA | 1695 | NA |
2013 | 9 | 12 | NA | UA | 404 | NA |
2013 | 9 | 12 | NA | UA | 525 | NA |
2013 | 9 | 12 | NA | UA | 1128 | NA |
2013 | 9 | 20 | 752 | UA | 1591 | NA |
Groups
group_by()
divide your dataset into groups meaningful for your analysis:
flights |>
group_by(month)
year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 1 | 517 | 515 | 2 | 830 | 819 | 11 | UA | 1545 | N14228 | EWR | IAH | 227 | 1400 | 5 | 15 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 533 | 529 | 4 | 850 | 830 | 20 | UA | 1714 | N24211 | LGA | IAH | 227 | 1416 | 5 | 29 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 542 | 540 | 2 | 923 | 850 | 33 | AA | 1141 | N619AA | JFK | MIA | 160 | 1089 | 5 | 40 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 544 | 545 | -1 | 1004 | 1022 | -18 | B6 | 725 | N804JB | JFK | BQN | 183 | 1576 | 5 | 45 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 554 | 600 | -6 | 812 | 837 | -25 | DL | 461 | N668DN | LGA | ATL | 116 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 554 | 558 | -4 | 740 | 728 | 12 | UA | 1696 | N39463 | EWR | ORD | 150 | 719 | 5 | 58 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 555 | 600 | -5 | 913 | 854 | 19 | B6 | 507 | N516JB | EWR | FLL | 158 | 1065 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 709 | 723 | -14 | EV | 5708 | N829AS | LGA | IAD | 53 | 229 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 838 | 846 | -8 | B6 | 79 | N593JB | JFK | MCO | 140 | 944 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 753 | 745 | 8 | AA | 301 | N3ALAA | LGA | ORD | 138 | 733 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 849 | 851 | -2 | B6 | 49 | N793JB | JFK | PBI | 149 | 1028 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 853 | 856 | -3 | B6 | 71 | N657JB | JFK | TPA | 158 | 1005 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 924 | 917 | 7 | UA | 194 | N29129 | JFK | LAX | 345 | 2475 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 923 | 937 | -14 | UA | 1124 | N53441 | EWR | SFO | 361 | 2565 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 941 | 910 | 31 | AA | 707 | N3DUAA | LGA | DFW | 257 | 1389 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 559 | 0 | 702 | 706 | -4 | B6 | 1806 | N708JB | JFK | BOS | 44 | 187 | 5 | 59 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 854 | 902 | -8 | UA | 1187 | N76515 | EWR | LAS | 337 | 2227 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 851 | 858 | -7 | B6 | 371 | N595JB | LGA | FLL | 152 | 1076 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 837 | 825 | 12 | MQ | 4650 | N542MQ | LGA | ATL | 134 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 601 | 600 | 1 | 844 | 850 | -6 | B6 | 343 | N644JB | EWR | PBI | 147 | 1023 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 610 | -8 | 812 | 820 | -8 | DL | 1919 | N971DL | LGA | MSP | 170 | 1020 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 605 | -3 | 821 | 805 | 16 | MQ | 4401 | N730MQ | LGA | DTW | 105 | 502 | 6 | 5 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 858 | 910 | -12 | AA | 1895 | N633AA | EWR | MIA | 152 | 1085 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 837 | 845 | -8 | DL | 1743 | N3739P | JFK | ATL | 128 | 760 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 607 | 607 | 0 | 858 | 915 | -17 | UA | 1077 | N53442 | EWR | MIA | 157 | 1085 | 6 | 7 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 608 | 600 | 8 | 807 | 735 | 32 | MQ | 3768 | N9EAMQ | EWR | ORD | 139 | 719 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 611 | 600 | 11 | 945 | 931 | 14 | UA | 303 | N532UA | JFK | SFO | 366 | 2586 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 613 | 610 | 3 | 925 | 921 | 4 | B6 | 135 | N635JB | JFK | RSW | 175 | 1074 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 1039 | 1100 | -21 | B6 | 709 | N794JB | JFK | SJU | 182 | 1598 | 6 | 15 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 833 | 842 | -9 | DL | 575 | N326NB | EWR | ATL | 120 | 746 | 6 | 15 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2013 | 9 | 30 | 2123 | 2125 | -2 | 2223 | 2247 | -24 | EV | 5489 | N712EV | LGA | CHO | 45 | 305 | 21 | 25 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2127 | 2129 | -2 | 2314 | 2323 | -9 | EV | 3833 | N16546 | EWR | CLT | 72 | 529 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2128 | 2130 | -2 | 2328 | 2359 | -31 | B6 | 97 | N807JB | JFK | DEN | 213 | 1626 | 21 | 30 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2129 | 2059 | 30 | 2230 | 2232 | -2 | EV | 5048 | N751EV | LGA | RIC | 45 | 292 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2131 | 2140 | -9 | 2225 | 2255 | -30 | MQ | 3621 | N807MQ | JFK | DCA | 36 | 213 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2140 | 2140 | 0 | 10 | 40 | -30 | AA | 185 | N335AA | JFK | LAX | 298 | 2475 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2142 | 2129 | 13 | 2250 | 2239 | 11 | EV | 4509 | N12957 | EWR | PWM | 47 | 284 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2145 | 2145 | 0 | 115 | 140 | -25 | B6 | 1103 | N633JB | JFK | SJU | 192 | 1598 | 21 | 45 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2147 | 2137 | 10 | 30 | 27 | 3 | B6 | 1371 | N627JB | LGA | FLL | 139 | 1076 | 21 | 37 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2149 | 2156 | -7 | 2245 | 2308 | -23 | UA | 523 | N813UA | EWR | BOS | 37 | 200 | 21 | 56 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2150 | 2159 | -9 | 2250 | 2306 | -16 | EV | 3842 | N10575 | EWR | MHT | 39 | 209 | 21 | 59 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2159 | 1845 | 194 | 2344 | 2030 | 194 | 9E | 3320 | N906XJ | JFK | BUF | 50 | 301 | 18 | 45 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | 2203 | 2205 | -2 | 2339 | 2331 | 8 | EV | 5311 | N722EV | LGA | BGR | 61 | 378 | 22 | 5 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2207 | 2140 | 27 | 2257 | 2250 | 7 | MQ | 3660 | N532MQ | LGA | BNA | 97 | 764 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2211 | 2059 | 72 | 2339 | 2242 | 57 | EV | 4672 | N12145 | EWR | STL | 120 | 872 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2231 | 2245 | -14 | 2335 | 2356 | -21 | B6 | 108 | N193JB | JFK | PWM | 48 | 273 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2233 | 2113 | 80 | 112 | 30 | 42 | UA | 471 | N578UA | EWR | SFO | 318 | 2565 | 21 | 13 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2235 | 2001 | 154 | 59 | 2249 | 130 | B6 | 1083 | N804JB | JFK | MCO | 123 | 944 | 20 | 1 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2237 | 2245 | -8 | 2345 | 2353 | -8 | B6 | 234 | N318JB | JFK | BTV | 43 | 266 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2245 | -5 | 2334 | 2351 | -17 | B6 | 1816 | N354JB | JFK | SYR | 41 | 209 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2250 | -10 | 2347 | 7 | -20 | B6 | 2002 | N281JB | JFK | BUF | 52 | 301 | 22 | 50 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2241 | 2246 | -5 | 2345 | 1 | -16 | B6 | 486 | N346JB | JFK | ROC | 47 | 264 | 22 | 46 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2307 | 2255 | 12 | 2359 | 2358 | 1 | B6 | 718 | N565JB | JFK | BOS | 33 | 187 | 22 | 55 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2349 | 2359 | -10 | 325 | 350 | -25 | B6 | 745 | N516JB | JFK | PSE | 196 | 1617 | 23 | 59 | 2013-09-30 23:00:00 |
2013 | 9 | 30 | NA | 1842 | NA | NA | 2019 | NA | EV | 5274 | N740EV | LGA | BNA | NA | 764 | 18 | 42 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | NA | 1455 | NA | NA | 1634 | NA | 9E | 3393 | NA | JFK | DCA | NA | 213 | 14 | 55 | 2013-09-30 14:00:00 |
2013 | 9 | 30 | NA | 2200 | NA | NA | 2312 | NA | 9E | 3525 | NA | LGA | SYR | NA | 198 | 22 | 0 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | NA | 1210 | NA | NA | 1330 | NA | MQ | 3461 | N535MQ | LGA | BNA | NA | 764 | 12 | 10 | 2013-09-30 12:00:00 |
2013 | 9 | 30 | NA | 1159 | NA | NA | 1344 | NA | MQ | 3572 | N511MQ | LGA | CLE | NA | 419 | 11 | 59 | 2013-09-30 11:00:00 |
2013 | 9 | 30 | NA | 840 | NA | NA | 1020 | NA | MQ | 3531 | N839MQ | LGA | RDU | NA | 431 | 8 | 40 | 2013-09-30 08:00:00 |
summarize()
The most important grouped operation is a summary, which, if being used to calculate a single summary statistic, reduces the data frame to have a single row for each group.
flights |>
group_by(month) |>
summarize(
avg_delay = mean(dep_delay)
)
month | avg_delay |
---|---|
<int> | <dbl> |
1 | NA |
2 | NA |
3 | NA |
4 | NA |
5 | NA |
6 | NA |
7 | NA |
8 | NA |
9 | NA |
10 | NA |
11 | NA |
12 | NA |
flights |>
group_by(month) |>
summarize(
avg_delay = mean(dep_delay, na.rm = TRUE)
)
month | avg_delay |
---|---|
<int> | <dbl> |
1 | 10.036665 |
2 | 10.816843 |
3 | 13.227076 |
4 | 13.938038 |
5 | 12.986859 |
6 | 20.846332 |
7 | 21.727787 |
8 | 12.611040 |
9 | 6.722476 |
10 | 6.243988 |
11 | 5.435362 |
12 | 16.576688 |
flights |>
group_by(month) |>
summarize(
avg_delay = mean(dep_delay, na.rm = TRUE),
n = n()
)
month | avg_delay | n |
---|---|---|
<int> | <dbl> | <int> |
1 | 10.036665 | 27004 |
2 | 10.816843 | 24951 |
3 | 13.227076 | 28834 |
4 | 13.938038 | 28330 |
5 | 12.986859 | 28796 |
6 | 20.846332 | 28243 |
7 | 21.727787 | 29425 |
8 | 12.611040 | 29327 |
9 | 6.722476 | 27574 |
10 | 6.243988 | 28889 |
11 | 5.435362 | 27268 |
12 | 16.576688 | 28135 |
The slice_
functions
df |> slice_head(n = 1)
takes the first row from each group.df |> slice_tail(n = 1)
takes the last row in each group.df |> slice_min(x, n = 1)
takes the row with the smallest value of column x.df |> slice_max(x, n = 1)
takes the row with the largest value of column x.df |> slice_sample(n = 1)
takes one random row.
You can vary n to select more than one row, or instead of n =, you can use prop = 0.1 to select (e.g.) 10% of the rows in each group
flights |>
group_by(dest) |>
slice_max(arr_delay, with_ties = FALSE, n = 1) |>
relocate(dest)
dest | year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<chr> | <int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
ABQ | 2013 | 7 | 22 | 2145 | 2007 | 98 | 132 | 2259 | 153 | B6 | 1505 | N784JB | JFK | 259 | 1826 | 20 | 7 | 2013-07-22 20:00:00 |
ACK | 2013 | 7 | 23 | 1139 | 800 | 219 | 1250 | 909 | 221 | B6 | 1491 | N192JB | JFK | 44 | 199 | 8 | 0 | 2013-07-23 08:00:00 |
ALB | 2013 | 1 | 25 | 123 | 2000 | 323 | 229 | 2101 | 328 | EV | 4309 | N13908 | EWR | 30 | 143 | 20 | 0 | 2013-01-25 20:00:00 |
ANC | 2013 | 8 | 17 | 1740 | 1625 | 75 | 2042 | 2003 | 39 | UA | 887 | N528UA | EWR | 404 | 3370 | 16 | 25 | 2013-08-17 16:00:00 |
ATL | 2013 | 7 | 22 | 2257 | 759 | 898 | 121 | 1026 | 895 | DL | 2047 | N6716C | LGA | 109 | 762 | 7 | 59 | 2013-07-22 07:00:00 |
AUS | 2013 | 7 | 10 | 2056 | 1505 | 351 | 2347 | 1758 | 349 | UA | 503 | N803UA | EWR | 192 | 1504 | 15 | 5 | 2013-07-10 15:00:00 |
AVL | 2013 | 8 | 13 | 1156 | 832 | 204 | 1417 | 1029 | 228 | EV | 4175 | N13538 | EWR | 108 | 583 | 8 | 32 | 2013-08-13 08:00:00 |
BDL | 2013 | 2 | 21 | 1728 | 1316 | 252 | 1839 | 1413 | 266 | EV | 4103 | N16976 | EWR | 26 | 116 | 13 | 16 | 2013-02-21 13:00:00 |
BGR | 2013 | 12 | 1 | 1504 | 1056 | 248 | 1628 | 1230 | 238 | EV | 5309 | N615QX | LGA | 57 | 378 | 10 | 56 | 2013-12-01 10:00:00 |
BHM | 2013 | 4 | 10 | 25 | 1900 | 325 | 136 | 2045 | 291 | EV | 5038 | N713EV | LGA | 115 | 866 | 19 | 0 | 2013-04-10 19:00:00 |
BNA | 2013 | 1 | 25 | 2020 | 1527 | 293 | 2304 | 1700 | 364 | EV | 3835 | N14920 | EWR | 124 | 748 | 15 | 27 | 2013-01-25 15:00:00 |
BOS | 2013 | 3 | 8 | 1819 | 1200 | 379 | 2005 | 1303 | 422 | B6 | 1174 | N329JB | EWR | 47 | 200 | 12 | 0 | 2013-03-08 12:00:00 |
BQN | 2013 | 6 | 13 | 6 | 2034 | 212 | 358 | 30 | 208 | UA | 1071 | N77296 | EWR | 216 | 1585 | 20 | 34 | 2013-06-13 20:00:00 |
BTV | 2013 | 9 | 12 | 2125 | 1459 | 386 | 2258 | 1622 | 396 | B6 | 1734 | N178JB | JFK | 52 | 266 | 14 | 59 | 2013-09-12 14:00:00 |
BUF | 2013 | 11 | 27 | 1503 | 815 | 408 | 1628 | 952 | 396 | 9E | 2906 | N930XJ | JFK | 56 | 301 | 8 | 15 | 2013-11-27 08:00:00 |
BUR | 2013 | 6 | 27 | 2146 | 1800 | 226 | 109 | 2102 | 247 | B6 | 359 | N635JB | JFK | 321 | 2465 | 18 | 0 | 2013-06-27 18:00:00 |
BWI | 2013 | 1 | 1 | 848 | 1835 | 853 | 1001 | 1950 | 851 | MQ | 3944 | N942MQ | JFK | 41 | 184 | 18 | 35 | 2013-01-01 18:00:00 |
BZN | 2013 | 12 | 28 | 1104 | 819 | 165 | 1353 | 1119 | 154 | UA | 568 | N436UA | EWR | 267 | 1882 | 8 | 19 | 2013-12-28 08:00:00 |
CAE | 2013 | 4 | 14 | 2148 | 1846 | 182 | 2400 | 2016 | 224 | EV | 4471 | N15983 | EWR | 100 | 602 | 18 | 46 | 2013-04-14 18:00:00 |
CAK | 2013 | 12 | 18 | 1702 | 950 | 432 | 1836 | 1123 | 433 | FL | 160 | N972AT | LGA | 70 | 397 | 9 | 50 | 2013-12-18 09:00:00 |
CHO | 2013 | 3 | 8 | 2355 | 1940 | 255 | 109 | 2121 | 228 | EV | 5325 | N611QX | LGA | 42 | 305 | 19 | 40 | 2013-03-08 19:00:00 |
CHS | 2013 | 3 | 8 | 1202 | 751 | 251 | 1530 | 959 | 331 | EV | 4532 | N15555 | EWR | 88 | 628 | 7 | 51 | 2013-03-08 07:00:00 |
CLE | 2013 | 12 | 22 | 2236 | 1430 | 486 | 15 | 1626 | 469 | EV | 4159 | N15912 | LGA | 71 | 419 | 14 | 30 | 2013-12-22 14:00:00 |
CLT | 2013 | 2 | 16 | 757 | 1930 | 747 | 1013 | 2149 | 744 | 9E | 3798 | N8940E | JFK | 85 | 541 | 19 | 30 | 2013-02-16 19:00:00 |
CMH | 2013 | 6 | 15 | 1432 | 1935 | 1137 | 1607 | 2120 | 1127 | MQ | 3535 | N504MQ | JFK | 74 | 483 | 19 | 35 | 2013-06-15 19:00:00 |
CRW | 2013 | 4 | 18 | 2158 | 1845 | 193 | 2339 | 2030 | 189 | MQ | 4517 | N713MQ | LGA | 73 | 444 | 18 | 45 | 2013-04-18 18:00:00 |
CVG | 2013 | 7 | 22 | 845 | 1600 | 1005 | 1044 | 1815 | 989 | MQ | 3075 | N665MQ | JFK | 96 | 589 | 16 | 0 | 2013-07-22 16:00:00 |
DAY | 2013 | 12 | 5 | 1504 | 955 | 309 | 1709 | 1217 | 292 | 9E | 4060 | N8877A | LGA | 96 | 549 | 9 | 55 | 2013-12-05 09:00:00 |
DCA | 2013 | 2 | 27 | 1529 | 845 | 404 | 1639 | 1015 | 384 | 9E | 3405 | N922XJ | JFK | 49 | 213 | 8 | 45 | 2013-02-27 08:00:00 |
DEN | 2013 | 2 | 10 | 2243 | 830 | 853 | 100 | 1106 | 834 | F9 | 835 | N203FR | LGA | 233 | 1620 | 8 | 30 | 2013-02-10 08:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
PIT | 2013 | 6 | 25 | 1421 | 805 | 376 | 1602 | 950 | 372 | 9E | 3611 | N8458A | JFK | 64 | 340 | 8 | 5 | 2013-06-25 08:00:00 |
PSE | 2013 | 6 | 28 | 317 | 2359 | 198 | 652 | 350 | 182 | B6 | 745 | N568JB | JFK | 199 | 1617 | 23 | 59 | 2013-06-28 23:00:00 |
PSP | 2013 | 3 | 16 | 1046 | 1055 | -9 | 1412 | 1355 | 17 | VX | 55 | N839VA | JFK | 365 | 2378 | 10 | 55 | 2013-03-16 10:00:00 |
PVD | 2013 | 3 | 18 | 200 | 2115 | 285 | 259 | 2214 | 285 | EV | 4404 | N11547 | EWR | 27 | 160 | 21 | 15 | 2013-03-18 21:00:00 |
PWM | 2013 | 3 | 8 | 1300 | 829 | 271 | 1505 | 955 | 310 | EV | 4224 | N12540 | EWR | 52 | 284 | 8 | 29 | 2013-03-08 08:00:00 |
RDU | 2013 | 6 | 13 | 1833 | 1250 | 343 | 2135 | 1425 | 430 | MQ | 3361 | N804MQ | JFK | 76 | 427 | 12 | 50 | 2013-06-13 12:00:00 |
RIC | 2013 | 7 | 22 | 41 | 1638 | 483 | 154 | 1811 | 463 | EV | 4300 | N13970 | EWR | 47 | 277 | 16 | 38 | 2013-07-22 16:00:00 |
ROC | 2013 | 6 | 27 | 2334 | 1635 | 419 | 32 | 1805 | 387 | EV | 4322 | N11191 | EWR | 40 | 246 | 16 | 35 | 2013-06-27 16:00:00 |
RSW | 2013 | 2 | 27 | 2138 | 1658 | 280 | 39 | 2007 | 272 | B6 | 139 | N228JB | JFK | 162 | 1074 | 16 | 58 | 2013-02-27 16:00:00 |
SAN | 2013 | 6 | 27 | 615 | 1705 | 790 | 853 | 2004 | 769 | DL | 503 | N372DA | JFK | 312 | 2446 | 17 | 5 | 2013-06-27 17:00:00 |
SAT | 2013 | 12 | 1 | 657 | 1930 | 687 | 1010 | 2249 | 681 | DL | 1091 | N342NW | JFK | 211 | 1587 | 19 | 30 | 2013-12-01 19:00:00 |
SAV | 2013 | 12 | 5 | 1735 | 1024 | 431 | 2009 | 1246 | 443 | EV | 4495 | N14977 | EWR | 111 | 708 | 10 | 24 | 2013-12-05 10:00:00 |
SBN | 2013 | 11 | 22 | 2013 | 1905 | 68 | 2224 | 2131 | 53 | EV | 5383 | N398CA | LGA | 110 | 651 | 19 | 5 | 2013-11-22 19:00:00 |
SDF | 2013 | 7 | 10 | 2111 | 1615 | 296 | 57 | 1900 | 357 | 9E | 3926 | N800AY | JFK | 110 | 662 | 16 | 15 | 2013-07-10 16:00:00 |
SEA | 2013 | 6 | 24 | 159 | 1735 | 504 | 432 | 2108 | 444 | DL | 1543 | N727TW | JFK | 307 | 2422 | 17 | 35 | 2013-06-24 17:00:00 |
SFO | 2013 | 9 | 20 | 1139 | 1845 | 1014 | 1457 | 2210 | 1007 | AA | 177 | N338AA | JFK | 354 | 2586 | 18 | 45 | 2013-09-20 18:00:00 |
SJC | 2013 | 7 | 10 | 2227 | 1855 | 212 | 202 | 2216 | 226 | B6 | 669 | N621JB | JFK | 338 | 2569 | 18 | 55 | 2013-07-10 18:00:00 |
SJU | 2013 | 7 | 18 | 2131 | 1455 | 396 | 116 | 1905 | 371 | AA | 1635 | N5FNAA | JFK | 198 | 1598 | 14 | 55 | 2013-07-18 14:00:00 |
SLC | 2013 | 12 | 19 | 734 | 1725 | 849 | 1046 | 2039 | 847 | DL | 1223 | N375NC | EWR | 290 | 1969 | 17 | 25 | 2013-12-19 17:00:00 |
SMF | 2013 | 4 | 19 | 2346 | 1845 | 301 | 248 | 2217 | 271 | B6 | 171 | N706JB | JFK | 335 | 2521 | 18 | 45 | 2013-04-19 18:00:00 |
SNA | 2013 | 7 | 23 | 1034 | 715 | 199 | 1307 | 958 | 189 | UA | 288 | N514UA | EWR | 307 | 2434 | 7 | 15 | 2013-07-23 07:00:00 |
SRQ | 2013 | 6 | 24 | 1713 | 1055 | 378 | 2205 | 1411 | 474 | DL | 1903 | N345NB | LGA | 154 | 1047 | 10 | 55 | 2013-06-24 10:00:00 |
STL | 2013 | 6 | 27 | 753 | 1830 | 803 | 937 | 2015 | 802 | AA | 2019 | N571AA | LGA | 134 | 888 | 18 | 30 | 2013-06-27 18:00:00 |
STT | 2013 | 2 | 11 | 1416 | 810 | 366 | 1845 | 1315 | 330 | AA | 655 | N625AA | JFK | 180 | 1623 | 8 | 10 | 2013-02-11 08:00:00 |
SYR | 2013 | 7 | 10 | 2257 | 1705 | 352 | 116 | 1845 | 391 | B6 | 1516 | N238JB | JFK | 42 | 209 | 17 | 5 | 2013-07-10 17:00:00 |
TPA | 2013 | 4 | 10 | 1100 | 1900 | 960 | 1342 | 2211 | 931 | DL | 2391 | N959DL | JFK | 139 | 1005 | 19 | 0 | 2013-04-10 19:00:00 |
TUL | 2013 | 1 | 20 | 2347 | 1936 | 251 | 230 | 2208 | 262 | EV | 4333 | N14177 | EWR | 208 | 1215 | 19 | 36 | 2013-01-20 19:00:00 |
TVC | 2013 | 8 | 10 | 1120 | 730 | 230 | 1323 | 943 | 220 | EV | 5144 | N718EV | LGA | 96 | 655 | 7 | 30 | 2013-08-10 07:00:00 |
TYS | 2013 | 4 | 12 | 51 | 2000 | 291 | 250 | 2209 | 281 | EV | 3826 | N15986 | EWR | 103 | 631 | 20 | 0 | 2013-04-12 20:00:00 |
XNA | 2013 | 3 | 8 | 1311 | 822 | 289 | 1615 | 1045 | 330 | EV | 4140 | N18556 | EWR | 168 | 1131 | 8 | 22 | 2013-03-08 08:00:00 |
Grouping by multiple variables
daily <- flights |>
group_by(year, month, day)
daily
year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 1 | 517 | 515 | 2 | 830 | 819 | 11 | UA | 1545 | N14228 | EWR | IAH | 227 | 1400 | 5 | 15 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 533 | 529 | 4 | 850 | 830 | 20 | UA | 1714 | N24211 | LGA | IAH | 227 | 1416 | 5 | 29 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 542 | 540 | 2 | 923 | 850 | 33 | AA | 1141 | N619AA | JFK | MIA | 160 | 1089 | 5 | 40 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 544 | 545 | -1 | 1004 | 1022 | -18 | B6 | 725 | N804JB | JFK | BQN | 183 | 1576 | 5 | 45 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 554 | 600 | -6 | 812 | 837 | -25 | DL | 461 | N668DN | LGA | ATL | 116 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 554 | 558 | -4 | 740 | 728 | 12 | UA | 1696 | N39463 | EWR | ORD | 150 | 719 | 5 | 58 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 555 | 600 | -5 | 913 | 854 | 19 | B6 | 507 | N516JB | EWR | FLL | 158 | 1065 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 709 | 723 | -14 | EV | 5708 | N829AS | LGA | IAD | 53 | 229 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 838 | 846 | -8 | B6 | 79 | N593JB | JFK | MCO | 140 | 944 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 753 | 745 | 8 | AA | 301 | N3ALAA | LGA | ORD | 138 | 733 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 849 | 851 | -2 | B6 | 49 | N793JB | JFK | PBI | 149 | 1028 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 853 | 856 | -3 | B6 | 71 | N657JB | JFK | TPA | 158 | 1005 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 924 | 917 | 7 | UA | 194 | N29129 | JFK | LAX | 345 | 2475 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 923 | 937 | -14 | UA | 1124 | N53441 | EWR | SFO | 361 | 2565 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 941 | 910 | 31 | AA | 707 | N3DUAA | LGA | DFW | 257 | 1389 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 559 | 0 | 702 | 706 | -4 | B6 | 1806 | N708JB | JFK | BOS | 44 | 187 | 5 | 59 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 854 | 902 | -8 | UA | 1187 | N76515 | EWR | LAS | 337 | 2227 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 851 | 858 | -7 | B6 | 371 | N595JB | LGA | FLL | 152 | 1076 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 837 | 825 | 12 | MQ | 4650 | N542MQ | LGA | ATL | 134 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 601 | 600 | 1 | 844 | 850 | -6 | B6 | 343 | N644JB | EWR | PBI | 147 | 1023 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 610 | -8 | 812 | 820 | -8 | DL | 1919 | N971DL | LGA | MSP | 170 | 1020 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 605 | -3 | 821 | 805 | 16 | MQ | 4401 | N730MQ | LGA | DTW | 105 | 502 | 6 | 5 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 858 | 910 | -12 | AA | 1895 | N633AA | EWR | MIA | 152 | 1085 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 837 | 845 | -8 | DL | 1743 | N3739P | JFK | ATL | 128 | 760 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 607 | 607 | 0 | 858 | 915 | -17 | UA | 1077 | N53442 | EWR | MIA | 157 | 1085 | 6 | 7 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 608 | 600 | 8 | 807 | 735 | 32 | MQ | 3768 | N9EAMQ | EWR | ORD | 139 | 719 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 611 | 600 | 11 | 945 | 931 | 14 | UA | 303 | N532UA | JFK | SFO | 366 | 2586 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 613 | 610 | 3 | 925 | 921 | 4 | B6 | 135 | N635JB | JFK | RSW | 175 | 1074 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 1039 | 1100 | -21 | B6 | 709 | N794JB | JFK | SJU | 182 | 1598 | 6 | 15 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 833 | 842 | -9 | DL | 575 | N326NB | EWR | ATL | 120 | 746 | 6 | 15 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2013 | 9 | 30 | 2123 | 2125 | -2 | 2223 | 2247 | -24 | EV | 5489 | N712EV | LGA | CHO | 45 | 305 | 21 | 25 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2127 | 2129 | -2 | 2314 | 2323 | -9 | EV | 3833 | N16546 | EWR | CLT | 72 | 529 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2128 | 2130 | -2 | 2328 | 2359 | -31 | B6 | 97 | N807JB | JFK | DEN | 213 | 1626 | 21 | 30 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2129 | 2059 | 30 | 2230 | 2232 | -2 | EV | 5048 | N751EV | LGA | RIC | 45 | 292 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2131 | 2140 | -9 | 2225 | 2255 | -30 | MQ | 3621 | N807MQ | JFK | DCA | 36 | 213 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2140 | 2140 | 0 | 10 | 40 | -30 | AA | 185 | N335AA | JFK | LAX | 298 | 2475 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2142 | 2129 | 13 | 2250 | 2239 | 11 | EV | 4509 | N12957 | EWR | PWM | 47 | 284 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2145 | 2145 | 0 | 115 | 140 | -25 | B6 | 1103 | N633JB | JFK | SJU | 192 | 1598 | 21 | 45 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2147 | 2137 | 10 | 30 | 27 | 3 | B6 | 1371 | N627JB | LGA | FLL | 139 | 1076 | 21 | 37 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2149 | 2156 | -7 | 2245 | 2308 | -23 | UA | 523 | N813UA | EWR | BOS | 37 | 200 | 21 | 56 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2150 | 2159 | -9 | 2250 | 2306 | -16 | EV | 3842 | N10575 | EWR | MHT | 39 | 209 | 21 | 59 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2159 | 1845 | 194 | 2344 | 2030 | 194 | 9E | 3320 | N906XJ | JFK | BUF | 50 | 301 | 18 | 45 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | 2203 | 2205 | -2 | 2339 | 2331 | 8 | EV | 5311 | N722EV | LGA | BGR | 61 | 378 | 22 | 5 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2207 | 2140 | 27 | 2257 | 2250 | 7 | MQ | 3660 | N532MQ | LGA | BNA | 97 | 764 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2211 | 2059 | 72 | 2339 | 2242 | 57 | EV | 4672 | N12145 | EWR | STL | 120 | 872 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2231 | 2245 | -14 | 2335 | 2356 | -21 | B6 | 108 | N193JB | JFK | PWM | 48 | 273 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2233 | 2113 | 80 | 112 | 30 | 42 | UA | 471 | N578UA | EWR | SFO | 318 | 2565 | 21 | 13 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2235 | 2001 | 154 | 59 | 2249 | 130 | B6 | 1083 | N804JB | JFK | MCO | 123 | 944 | 20 | 1 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2237 | 2245 | -8 | 2345 | 2353 | -8 | B6 | 234 | N318JB | JFK | BTV | 43 | 266 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2245 | -5 | 2334 | 2351 | -17 | B6 | 1816 | N354JB | JFK | SYR | 41 | 209 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2250 | -10 | 2347 | 7 | -20 | B6 | 2002 | N281JB | JFK | BUF | 52 | 301 | 22 | 50 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2241 | 2246 | -5 | 2345 | 1 | -16 | B6 | 486 | N346JB | JFK | ROC | 47 | 264 | 22 | 46 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2307 | 2255 | 12 | 2359 | 2358 | 1 | B6 | 718 | N565JB | JFK | BOS | 33 | 187 | 22 | 55 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2349 | 2359 | -10 | 325 | 350 | -25 | B6 | 745 | N516JB | JFK | PSE | 196 | 1617 | 23 | 59 | 2013-09-30 23:00:00 |
2013 | 9 | 30 | NA | 1842 | NA | NA | 2019 | NA | EV | 5274 | N740EV | LGA | BNA | NA | 764 | 18 | 42 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | NA | 1455 | NA | NA | 1634 | NA | 9E | 3393 | NA | JFK | DCA | NA | 213 | 14 | 55 | 2013-09-30 14:00:00 |
2013 | 9 | 30 | NA | 2200 | NA | NA | 2312 | NA | 9E | 3525 | NA | LGA | SYR | NA | 198 | 22 | 0 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | NA | 1210 | NA | NA | 1330 | NA | MQ | 3461 | N535MQ | LGA | BNA | NA | 764 | 12 | 10 | 2013-09-30 12:00:00 |
2013 | 9 | 30 | NA | 1159 | NA | NA | 1344 | NA | MQ | 3572 | N511MQ | LGA | CLE | NA | 419 | 11 | 59 | 2013-09-30 11:00:00 |
2013 | 9 | 30 | NA | 840 | NA | NA | 1020 | NA | MQ | 3531 | N839MQ | LGA | RDU | NA | 431 | 8 | 40 | 2013-09-30 08:00:00 |
# daily_flights <- daily |>
# summarize(n = n())
#> `summarise()` has grouped output by 'year', 'month'. You can override using
#> the `.groups` argument.
daily_flights <- daily |>
summarize(
n = n(),
.groups = "drop_last"
)
Ungrouping
You might also want to remove grouping from a data frame without using summarize()
. You can do this with ungroup()
daily |>
ungroup()
year | month | day | dep_time | sched_dep_time | dep_delay | arr_time | sched_arr_time | arr_delay | carrier | flight | tailnum | origin | dest | air_time | distance | hour | minute | time_hour |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
<int> | <int> | <int> | <int> | <int> | <dbl> | <int> | <int> | <dbl> | <chr> | <int> | <chr> | <chr> | <chr> | <dbl> | <dbl> | <dbl> | <dbl> | <dttm> |
2013 | 1 | 1 | 517 | 515 | 2 | 830 | 819 | 11 | UA | 1545 | N14228 | EWR | IAH | 227 | 1400 | 5 | 15 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 533 | 529 | 4 | 850 | 830 | 20 | UA | 1714 | N24211 | LGA | IAH | 227 | 1416 | 5 | 29 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 542 | 540 | 2 | 923 | 850 | 33 | AA | 1141 | N619AA | JFK | MIA | 160 | 1089 | 5 | 40 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 544 | 545 | -1 | 1004 | 1022 | -18 | B6 | 725 | N804JB | JFK | BQN | 183 | 1576 | 5 | 45 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 554 | 600 | -6 | 812 | 837 | -25 | DL | 461 | N668DN | LGA | ATL | 116 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 554 | 558 | -4 | 740 | 728 | 12 | UA | 1696 | N39463 | EWR | ORD | 150 | 719 | 5 | 58 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 555 | 600 | -5 | 913 | 854 | 19 | B6 | 507 | N516JB | EWR | FLL | 158 | 1065 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 709 | 723 | -14 | EV | 5708 | N829AS | LGA | IAD | 53 | 229 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 557 | 600 | -3 | 838 | 846 | -8 | B6 | 79 | N593JB | JFK | MCO | 140 | 944 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 753 | 745 | 8 | AA | 301 | N3ALAA | LGA | ORD | 138 | 733 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 849 | 851 | -2 | B6 | 49 | N793JB | JFK | PBI | 149 | 1028 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 853 | 856 | -3 | B6 | 71 | N657JB | JFK | TPA | 158 | 1005 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 924 | 917 | 7 | UA | 194 | N29129 | JFK | LAX | 345 | 2475 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 558 | 600 | -2 | 923 | 937 | -14 | UA | 1124 | N53441 | EWR | SFO | 361 | 2565 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 941 | 910 | 31 | AA | 707 | N3DUAA | LGA | DFW | 257 | 1389 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 559 | 559 | 0 | 702 | 706 | -4 | B6 | 1806 | N708JB | JFK | BOS | 44 | 187 | 5 | 59 | 2013-01-01 05:00:00 |
2013 | 1 | 1 | 559 | 600 | -1 | 854 | 902 | -8 | UA | 1187 | N76515 | EWR | LAS | 337 | 2227 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 851 | 858 | -7 | B6 | 371 | N595JB | LGA | FLL | 152 | 1076 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 600 | 600 | 0 | 837 | 825 | 12 | MQ | 4650 | N542MQ | LGA | ATL | 134 | 762 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 601 | 600 | 1 | 844 | 850 | -6 | B6 | 343 | N644JB | EWR | PBI | 147 | 1023 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 610 | -8 | 812 | 820 | -8 | DL | 1919 | N971DL | LGA | MSP | 170 | 1020 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 602 | 605 | -3 | 821 | 805 | 16 | MQ | 4401 | N730MQ | LGA | DTW | 105 | 502 | 6 | 5 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 858 | 910 | -12 | AA | 1895 | N633AA | EWR | MIA | 152 | 1085 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 606 | 610 | -4 | 837 | 845 | -8 | DL | 1743 | N3739P | JFK | ATL | 128 | 760 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 607 | 607 | 0 | 858 | 915 | -17 | UA | 1077 | N53442 | EWR | MIA | 157 | 1085 | 6 | 7 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 608 | 600 | 8 | 807 | 735 | 32 | MQ | 3768 | N9EAMQ | EWR | ORD | 139 | 719 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 611 | 600 | 11 | 945 | 931 | 14 | UA | 303 | N532UA | JFK | SFO | 366 | 2586 | 6 | 0 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 613 | 610 | 3 | 925 | 921 | 4 | B6 | 135 | N635JB | JFK | RSW | 175 | 1074 | 6 | 10 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 1039 | 1100 | -21 | B6 | 709 | N794JB | JFK | SJU | 182 | 1598 | 6 | 15 | 2013-01-01 06:00:00 |
2013 | 1 | 1 | 615 | 615 | 0 | 833 | 842 | -9 | DL | 575 | N326NB | EWR | ATL | 120 | 746 | 6 | 15 | 2013-01-01 06:00:00 |
... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... | ... |
2013 | 9 | 30 | 2123 | 2125 | -2 | 2223 | 2247 | -24 | EV | 5489 | N712EV | LGA | CHO | 45 | 305 | 21 | 25 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2127 | 2129 | -2 | 2314 | 2323 | -9 | EV | 3833 | N16546 | EWR | CLT | 72 | 529 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2128 | 2130 | -2 | 2328 | 2359 | -31 | B6 | 97 | N807JB | JFK | DEN | 213 | 1626 | 21 | 30 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2129 | 2059 | 30 | 2230 | 2232 | -2 | EV | 5048 | N751EV | LGA | RIC | 45 | 292 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2131 | 2140 | -9 | 2225 | 2255 | -30 | MQ | 3621 | N807MQ | JFK | DCA | 36 | 213 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2140 | 2140 | 0 | 10 | 40 | -30 | AA | 185 | N335AA | JFK | LAX | 298 | 2475 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2142 | 2129 | 13 | 2250 | 2239 | 11 | EV | 4509 | N12957 | EWR | PWM | 47 | 284 | 21 | 29 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2145 | 2145 | 0 | 115 | 140 | -25 | B6 | 1103 | N633JB | JFK | SJU | 192 | 1598 | 21 | 45 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2147 | 2137 | 10 | 30 | 27 | 3 | B6 | 1371 | N627JB | LGA | FLL | 139 | 1076 | 21 | 37 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2149 | 2156 | -7 | 2245 | 2308 | -23 | UA | 523 | N813UA | EWR | BOS | 37 | 200 | 21 | 56 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2150 | 2159 | -9 | 2250 | 2306 | -16 | EV | 3842 | N10575 | EWR | MHT | 39 | 209 | 21 | 59 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2159 | 1845 | 194 | 2344 | 2030 | 194 | 9E | 3320 | N906XJ | JFK | BUF | 50 | 301 | 18 | 45 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | 2203 | 2205 | -2 | 2339 | 2331 | 8 | EV | 5311 | N722EV | LGA | BGR | 61 | 378 | 22 | 5 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2207 | 2140 | 27 | 2257 | 2250 | 7 | MQ | 3660 | N532MQ | LGA | BNA | 97 | 764 | 21 | 40 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2211 | 2059 | 72 | 2339 | 2242 | 57 | EV | 4672 | N12145 | EWR | STL | 120 | 872 | 20 | 59 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2231 | 2245 | -14 | 2335 | 2356 | -21 | B6 | 108 | N193JB | JFK | PWM | 48 | 273 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2233 | 2113 | 80 | 112 | 30 | 42 | UA | 471 | N578UA | EWR | SFO | 318 | 2565 | 21 | 13 | 2013-09-30 21:00:00 |
2013 | 9 | 30 | 2235 | 2001 | 154 | 59 | 2249 | 130 | B6 | 1083 | N804JB | JFK | MCO | 123 | 944 | 20 | 1 | 2013-09-30 20:00:00 |
2013 | 9 | 30 | 2237 | 2245 | -8 | 2345 | 2353 | -8 | B6 | 234 | N318JB | JFK | BTV | 43 | 266 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2245 | -5 | 2334 | 2351 | -17 | B6 | 1816 | N354JB | JFK | SYR | 41 | 209 | 22 | 45 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2240 | 2250 | -10 | 2347 | 7 | -20 | B6 | 2002 | N281JB | JFK | BUF | 52 | 301 | 22 | 50 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2241 | 2246 | -5 | 2345 | 1 | -16 | B6 | 486 | N346JB | JFK | ROC | 47 | 264 | 22 | 46 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2307 | 2255 | 12 | 2359 | 2358 | 1 | B6 | 718 | N565JB | JFK | BOS | 33 | 187 | 22 | 55 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | 2349 | 2359 | -10 | 325 | 350 | -25 | B6 | 745 | N516JB | JFK | PSE | 196 | 1617 | 23 | 59 | 2013-09-30 23:00:00 |
2013 | 9 | 30 | NA | 1842 | NA | NA | 2019 | NA | EV | 5274 | N740EV | LGA | BNA | NA | 764 | 18 | 42 | 2013-09-30 18:00:00 |
2013 | 9 | 30 | NA | 1455 | NA | NA | 1634 | NA | 9E | 3393 | NA | JFK | DCA | NA | 213 | 14 | 55 | 2013-09-30 14:00:00 |
2013 | 9 | 30 | NA | 2200 | NA | NA | 2312 | NA | 9E | 3525 | NA | LGA | SYR | NA | 198 | 22 | 0 | 2013-09-30 22:00:00 |
2013 | 9 | 30 | NA | 1210 | NA | NA | 1330 | NA | MQ | 3461 | N535MQ | LGA | BNA | NA | 764 | 12 | 10 | 2013-09-30 12:00:00 |
2013 | 9 | 30 | NA | 1159 | NA | NA | 1344 | NA | MQ | 3572 | N511MQ | LGA | CLE | NA | 419 | 11 | 59 | 2013-09-30 11:00:00 |
2013 | 9 | 30 | NA | 840 | NA | NA | 1020 | NA | MQ | 3531 | N839MQ | LGA | RDU | NA | 431 | 8 | 40 | 2013-09-30 08:00:00 |
daily |>
ungroup() |>
summarize(
avg_delay = mean(dep_delay, na.rm = TRUE),
flights = n()
)
avg_delay | flights |
---|---|
<dbl> | <int> |
12.63907 | 336776 |
.by
Instead of using group_by()
and ungroup()
flights |>
summarize(
delay = mean(dep_delay, na.rm = TRUE),
n = n(),
.by = c(origin, dest)
)
origin | dest | delay | n |
---|---|---|---|
<chr> | <chr> | <dbl> | <int> |
EWR | IAH | 11.826551 | 3973 |
LGA | IAH | 9.058986 | 2951 |
JFK | MIA | 9.336571 | 3314 |
JFK | BQN | 6.665546 | 599 |
LGA | ATL | 11.448621 | 10263 |
EWR | ORD | 14.644163 | 6100 |
EWR | FLL | 13.532606 | 3793 |
LGA | IAD | 16.650421 | 1803 |
JFK | MCO | 10.601583 | 5464 |
LGA | ORD | 10.740758 | 8857 |
JFK | PBI | 14.420290 | 1739 |
JFK | TPA | 12.012855 | 2987 |
JFK | LAX | 8.522508 | 11262 |
EWR | SFO | 14.326394 | 5127 |
LGA | DFW | 5.806151 | 4858 |
JFK | BOS | 11.694953 | 5898 |
EWR | LAS | 11.230075 | 2010 |
LGA | FLL | 12.876453 | 4008 |
EWR | PBI | 13.962329 | 2351 |
LGA | MSP | 9.752957 | 3713 |
LGA | DTW | 7.770528 | 5040 |
EWR | MIA | 11.615385 | 2633 |
JFK | ATL | 10.465974 | 1930 |
JFK | SFO | 11.952691 | 8204 |
JFK | RSW | 10.082017 | 1339 |
JFK | SJU | 10.334039 | 4752 |
EWR | ATL | 15.501738 | 5022 |
EWR | PHX | 10.635789 | 2723 |
LGA | MIA | 7.361747 | 5781 |
EWR | MSP | 15.313163 | 2377 |
... | ... | ... | ... |
JFK | ACK | 6.4566038 | 265 |
LGA | BGR | 19.4750000 | 375 |
LGA | MSN | 27.1179245 | 218 |
LGA | ORF | 16.5538462 | 206 |
JFK | IAH | 15.6176471 | 274 |
JFK | MCI | 23.0859375 | 276 |
LGA | OMA | 27.3695652 | 95 |
LGA | DSM | 17.2222222 | 158 |
LGA | GSP | 8.2346939 | 104 |
JFK | ABQ | 13.7401575 | 254 |
LGA | ILM | 19.4166667 | 110 |
LGA | SYR | 19.1107011 | 293 |
JFK | MVY | 7.0516432 | 221 |
LGA | SBN | 31.3333333 | 6 |
JFK | STL | 20.0000000 | 1 |
LGA | LEX | -9.0000000 | 1 |
EWR | SBN | 5.7500000 | 4 |
LGA | MHT | 24.0370370 | 142 |
LGA | CAE | 29.5000000 | 12 |
JFK | JAC | 5.0000000 | 2 |
JFK | SDF | 23.9767442 | 46 |
LGA | CHO | 21.3913043 | 52 |
JFK | MKE | 19.8604651 | 183 |
LGA | AVL | -2.6000000 | 10 |
JFK | BHM | 7.0000000 | 1 |
LGA | TVC | 23.4109589 | 77 |
LGA | MYR | 0.6666667 | 3 |
EWR | TVC | 17.8695652 | 24 |
EWR | ANC | 12.8750000 | 8 |
EWR | LGA | NaN | 1 |
# group by multiple variables
flights |>
summarize(
delay = mean(dep_delay, na.rm = TRUE),
n = n(),
.by = c(origin, dest)
)
origin | dest | delay | n |
---|---|---|---|
<chr> | <chr> | <dbl> | <int> |
EWR | IAH | 11.826551 | 3973 |
LGA | IAH | 9.058986 | 2951 |
JFK | MIA | 9.336571 | 3314 |
JFK | BQN | 6.665546 | 599 |
LGA | ATL | 11.448621 | 10263 |
EWR | ORD | 14.644163 | 6100 |
EWR | FLL | 13.532606 | 3793 |
LGA | IAD | 16.650421 | 1803 |
JFK | MCO | 10.601583 | 5464 |
LGA | ORD | 10.740758 | 8857 |
JFK | PBI | 14.420290 | 1739 |
JFK | TPA | 12.012855 | 2987 |
JFK | LAX | 8.522508 | 11262 |
EWR | SFO | 14.326394 | 5127 |
LGA | DFW | 5.806151 | 4858 |
JFK | BOS | 11.694953 | 5898 |
EWR | LAS | 11.230075 | 2010 |
LGA | FLL | 12.876453 | 4008 |
EWR | PBI | 13.962329 | 2351 |
LGA | MSP | 9.752957 | 3713 |
LGA | DTW | 7.770528 | 5040 |
EWR | MIA | 11.615385 | 2633 |
JFK | ATL | 10.465974 | 1930 |
JFK | SFO | 11.952691 | 8204 |
JFK | RSW | 10.082017 | 1339 |
JFK | SJU | 10.334039 | 4752 |
EWR | ATL | 15.501738 | 5022 |
EWR | PHX | 10.635789 | 2723 |
LGA | MIA | 7.361747 | 5781 |
EWR | MSP | 15.313163 | 2377 |
... | ... | ... | ... |
JFK | ACK | 6.4566038 | 265 |
LGA | BGR | 19.4750000 | 375 |
LGA | MSN | 27.1179245 | 218 |
LGA | ORF | 16.5538462 | 206 |
JFK | IAH | 15.6176471 | 274 |
JFK | MCI | 23.0859375 | 276 |
LGA | OMA | 27.3695652 | 95 |
LGA | DSM | 17.2222222 | 158 |
LGA | GSP | 8.2346939 | 104 |
JFK | ABQ | 13.7401575 | 254 |
LGA | ILM | 19.4166667 | 110 |
LGA | SYR | 19.1107011 | 293 |
JFK | MVY | 7.0516432 | 221 |
LGA | SBN | 31.3333333 | 6 |
JFK | STL | 20.0000000 | 1 |
LGA | LEX | -9.0000000 | 1 |
EWR | SBN | 5.7500000 | 4 |
LGA | MHT | 24.0370370 | 142 |
LGA | CAE | 29.5000000 | 12 |
JFK | JAC | 5.0000000 | 2 |
JFK | SDF | 23.9767442 | 46 |
LGA | CHO | 21.3913043 | 52 |
JFK | MKE | 19.8604651 | 183 |
LGA | AVL | -2.6000000 | 10 |
JFK | BHM | 7.0000000 | 1 |
LGA | TVC | 23.4109589 | 77 |
LGA | MYR | 0.6666667 | 3 |
EWR | TVC | 17.8695652 | 24 |
EWR | ANC | 12.8750000 | 8 |
EWR | LGA | NaN | 1 |
Exercises
3.5.1. Which carrier has the worst average delays? Challenge: can you disentangle the effects of bad airports vs. bad carriers? Why/why not? (Hint: think about flights |> group_by(carrier, dest) |> summarize(n())
)
3.5.2. Find the flights that are most delayed upon departure from each destination.
3.5.3. How do delays vary over the course of the day. Illustrate your answer with a plot.
3.5.4. What happens if you supply a negative n to slice_min() and friends?
3.5.5. Explain what count() does in terms of the dplyr verbs you just learned. What does the sort argument to count() do?
3.5.6. Suppose we have the following tiny data frame:
df <- tibble(
x = 1:5,
y = c("a", "b", "a", "a", "b"),
z = c("K", "K", "L", "L", "K")
)
a. Write down what you think the output will look like, then check if you were correct, and describe what group_by() does.
df |>
group_by(y)
x | y | z |
---|---|---|
<int> | <chr> | <chr> |
1 | a | K |
2 | b | K |
3 | a | L |
4 | a | L |
5 | b | K |
b. Write down what you think the output will look like, then check if you were correct, and describe what arrange() does. Also comment on how it’s different from the group_by() in part (a)?
df |>
arrange(y)
x | y | z |
---|---|---|
<int> | <chr> | <chr> |
1 | a | K |
3 | a | L |
4 | a | L |
2 | b | K |
5 | b | K |
c. Write down what you think the output will look like, then check if you were correct, and describe what the pipeline does.
df |>
group_by(y) |>
summarize(mean_x = mean(x))
y | mean_x |
---|---|
<chr> | <dbl> |
a | 2.666667 |
b | 3.500000 |
d. Write down what you think the output will look like, then check if you were correct, and describe what the pipeline does. Then, comment on what the message says.
df |>
group_by(y, z) |>
summarize(mean_x = mean(x))
[1m[22m`summarise()` has grouped output by 'y'. You can override using the `.groups`
argument.
y | z | mean_x |
---|---|---|
<chr> | <chr> | <dbl> |
a | K | 1.0 |
a | L | 3.5 |
b | K | 3.5 |
e. Write down what you think the output will look like, then check if you were correct, and describe what the pipeline does. How is the output different from the one in part (d).
df |>
group_by(y, z) |>
summarize(mean_x = mean(x), .groups = "drop")
y | z | mean_x |
---|---|---|
<chr> | <chr> | <dbl> |
a | K | 1.0 |
a | L | 3.5 |
b | K | 3.5 |
f. Write down what you think the outputs will look like, then check if you were correct, and describe what each pipeline does. How are the outputs of the two pipelines different?
df |>
group_by(y, z) |>
summarize(mean_x = mean(x))
df |>
group_by(y, z) |>
mutate(mean_x = mean(x))
[1m[22m`summarise()` has grouped output by 'y'. You can override using the `.groups`
argument.
y | z | mean_x |
---|---|---|
<chr> | <chr> | <dbl> |
a | K | 1.0 |
a | L | 3.5 |
b | K | 3.5 |
x | y | z | mean_x |
---|---|---|---|
<int> | <chr> | <chr> | <dbl> |
1 | a | K | 1.0 |
2 | b | K | 3.5 |
3 | a | L | 3.5 |
4 | a | L | 3.5 |
5 | b | K | 3.5 |
Case study: aggregates and sample size
Whenever you do any aggregation, it’s always a good idea to include a count (n()
). That way, you can ensure that you’re not drawing conclusions based on very small amounts of data. We’ll demonstrate this with some baseball data from the Lahman package. Specifically, we will compare what proportion of times a player gets a hit (H
) vs. the number of times they try to put the ball in play (AB
):
batters <- Lahman::Batting |>
group_by(playerID) |>
summarize(
performance = sum(H, na.rm = TRUE) / sum(AB, na.rm = TRUE),
n = sum(AB, na.rm = TRUE)
)
batters
playerID | performance | n |
---|---|---|
<chr> | <dbl> | <int> |
aardsda01 | 0.00000000 | 4 |
aaronha01 | 0.30499838 | 12364 |
aaronto01 | 0.22881356 | 944 |
aasedo01 | 0.00000000 | 5 |
abadan01 | 0.09523810 | 21 |
abadfe01 | 0.11111111 | 9 |
abadijo01 | 0.22448980 | 49 |
abbated01 | 0.25361367 | 3044 |
abbeybe01 | 0.16888889 | 225 |
abbeych01 | 0.28075171 | 1756 |
abbotco01 | 0.33333333 | 3 |
abbotda01 | 0.14285714 | 7 |
abbotfr01 | 0.20857700 | 513 |
abbotgl01 | NaN | 0 |
abbotje01 | 0.26342282 | 596 |
abbotji01 | 0.09523810 | 21 |
abbotku01 | 0.25587084 | 2044 |
abbotky01 | 0.09677419 | 31 |
abbotod01 | 0.18571429 | 70 |
abbotpa01 | 0.25000000 | 20 |
aberal01 | 0.14000000 | 100 |
abercda01 | 0.00000000 | 4 |
abercre01 | 0.22279793 | 386 |
abernbi01 | 0.00000000 | 1 |
abernbr01 | 0.24423963 | 868 |
abernte01 | 0.20000000 | 5 |
abernte02 | 0.13812155 | 181 |
abernwo01 | 0.00000000 | 8 |
aberscl01 | 0.25139665 | 179 |
ablesha01 | 0.00000000 | 26 |
... | ... | ... |
zimmero01 | 0.27551020 | 98 |
zimmery01 | 0.27742711 | 6654 |
zinkch01 | NaN | 0 |
zinkwa01 | 0.00000000 | 1 |
zinnfr01 | 0.00000000 | 7 |
zinngu01 | 0.26926564 | 1103 |
zinnji01 | 0.28333333 | 120 |
zinsebi01 | NaN | 0 |
zinteal01 | 0.16666667 | 78 |
zipfebu01 | 0.22033898 | 354 |
ziskri01 | 0.28713064 | 5144 |
zitoba01 | 0.10174419 | 344 |
zitzmbi01 | 0.26693227 | 1004 |
zmiched01 | 0.05882353 | 17 |
zobribe01 | 0.26632653 | 5880 |
zoccope01 | 0.10810811 | 37 |
zoldasa01 | 0.17482517 | 286 |
zoskyed01 | 0.16000000 | 50 |
zuberbi01 | 0.13537118 | 229 |
zuberjo01 | 0.25000000 | 136 |
zuberty01 | 0.00000000 | 1 |
zuletju01 | 0.24712644 | 174 |
zumayjo01 | NaN | 0 |
zuninmi01 | 0.20007479 | 2674 |
zupcibo01 | 0.25031447 | 795 |
zupofr01 | 0.16666667 | 18 |
zuvelpa01 | 0.22199593 | 491 |
zuverge01 | 0.14788732 | 142 |
zwilldu01 | 0.28437500 | 1280 |
zychto01 | NaN | 0 |
batters |>
filter(n > 100) |>
ggplot(aes(x = n, y = performance)) +
geom_point(alpha = 1 / 10) +
geom_smooth(se = FALSE)
[1m[22m`geom_smooth()` using method = 'gam' and formula = 'y ~ s(x, bs = "cs")'
batters |>
arrange(desc(performance))
playerID | performance | n |
---|---|---|
<chr> | <dbl> | <int> |
abramge01 | 1 | 1 |
alberan01 | 1 | 1 |
banisje01 | 1 | 1 |
bartocl01 | 1 | 1 |
bassdo01 | 1 | 1 |
birasst01 | 1 | 2 |
bruneju01 | 1 | 1 |
burnscb01 | 1 | 1 |
cammaer01 | 1 | 1 |
campsh01 | 1 | 1 |
crockcl01 | 1 | 1 |
davenjo01 | 1 | 1 |
davidda01 | 1 | 1 |
devinha01 | 1 | 2 |
dupremi01 | 1 | 1 |
eddydo01 | 1 | 1 |
egeco01 | 1 | 1 |
eubanue01 | 1 | 1 |
fryjo01 | 1 | 1 |
gallaja01 | 1 | 1 |
garcimi02 | 1 | 1 |
garcira01 | 1 | 1 |
gideobr01 | 1 | 1 |
gleasro01 | 1 | 1 |
gowella01 | 1 | 1 |
grasmlo01 | 1 | 1 |
grayda01 | 1 | 1 |
hancory01 | 1 | 1 |
hesslke01 | 1 | 1 |
holloji01 | 1 | 1 |
... | ... | ... |
yardler01 | NaN | 0 |
yarnaed01 | NaN | 0 |
yeabsbe01 | NaN | 0 |
yettri01 | NaN | 0 |
ynoami01 | NaN | 0 |
yochira01 | NaN | 0 |
youngcl01 | NaN | 0 |
youngda01 | NaN | 0 |
youngda02 | NaN | 0 |
youngki01 | NaN | 0 |
youngma03 | NaN | 0 |
youngti01 | NaN | 0 |
yountla01 | NaN | 0 |
zabalan01 | NaN | 0 |
zagurmi01 | NaN | 0 |
zamorda01 | NaN | 0 |
zaratma01 | NaN | 0 |
zaskeje01 | NaN | 0 |
zavadcl01 | NaN | 0 |
zavarcl01 | NaN | 0 |
zelleba01 | NaN | 0 |
zerpaan01 | NaN | 0 |
ziemst01 | NaN | 0 |
zimmeje02 | NaN | 0 |
zimmejo01 | NaN | 0 |
zimmeky01 | NaN | 0 |
zinkch01 | NaN | 0 |
zinsebi01 | NaN | 0 |
zumayjo01 | NaN | 0 |
zychto01 | NaN | 0 |
Summary
In this chapter, you’ve learned the tools that dplyr provides for working with data frames. The tools are roughly grouped into three categories: those that manipulate the rows (like filter()
and arrange()
), those that manipulate the columns (like select()
and mutate()
), and those that manipulate groups (like group_by() and summarize()). In this chapter, we’ve focused on these “whole data frame” tools, but you haven’t yet learned much about what you can do with the individual variable.