
13.4
タイムスパン
221
#> # ... with 1.063e+04 more rows, and 4 more variables:
#> # sched_dep_time <dttm>, arr_time <dttm>,
#> # sched_arr_time <dttm>, air_time <dbl>
これらは夜行便です。発着時刻の両方に同じ日付情報を用いていますが、これらの便は翌日に到
着します。夜行便に対して、
days(1)
を足すことでこの問題を解決できます。
flights_dt <- flights_dt %>%
mutate(
overnight = arr_time < dep_time,
arr_time = arr_time + days(overnight * 1),
sched_arr_time = sched_arr_time + days
(overnight * 1)
)
今度はどの便も物理法則に違反しません。
flights_dt %>%
filter(overnight, arr_time < dep_time)
#> # A tibble: 0
×
10
#> # ... with 10 variables: origin <chr>, dest <chr>,
#> # dep_delay <dbl>, arr_delay <dbl>, dep_time <dttm>,
#> # sched_dep_time <dttm>, arr_time <dttm>, ...