Exercises
- Restyle the following pipelines following the guidelines above.
flights|>filter(dest=="IAH")|>group_by(year,month,day)|>summarize(n=n(),
delay=mean(arr_delay,na.rm=TRUE))|>filter(n>10)
flights|>filter(carrier=="UA",dest%in%c("IAH","HOU"),sched_dep_time>
0900,sched_arr_time<2000)|>group_by(flight)|>summarize(delay=mean(
arr_delay,na.rm=TRUE),cancelled=sum(is.na(arr_delay)),n=n())|>filter(n>10)
Solution
flights |> # space before/ after pipe and the last thing on a line
filter(dest == "IAH") |> # indent twice, space between operators
group_by(year, month, day) |> # space after comma
summarize( # nam
n = n(), # add spaces so that all the = line up
delay = mean(arr_delay, na.rm = TRUE)
) |>
filter(n > 10)
flights |>
filter(
carrier == "UA",
dest %in% c("IAH","HOU"),
sched_dep_time > 900,
sched_arr_time < 2000
) |>
group_by(flight) |>
summarize(
delay = mean(arr_delay, na.rm=TRUE),
cancelled = sum(is.na(arr_delay)),
n = n()
) |>
filter(n > 10)