library(tidyverse)
library(nycflights13)
|>
flights filter(dest == "IAH") |>
group_by(year, month, day) |>
summarize(
n = n(),
delay = mean(arr_delay, na.rm = TRUE)
|>
) filter(n > 10)
|>
flights filter(
== "UA",
carrier %in% c("IAH", "HOU"),
dest > 0900,
sched_dep_time < 2000
sched_arr_time |>
) group_by(flight) |>
summarize(
delay = mean(arr_delay, na.rm = TRUE),
cancelled = sum(is.na(arr_delay)), n = n()
|>
) filter(n > 10)
Chapter 5
Workflow: code style
5.6 Exercises
Restyle the following pipelines following the guidelines above.
|>filter(dest=="IAH")|>group_by(year,month,day)|>summarize(n=n(),
flightsdelay=mean(arr_delay,na.rm=TRUE))|>filter(n>10)
|>filter(carrier=="UA",dest%in%c("IAH","HOU"),sched_dep_time>
flights0900,sched_arr_time<2000)|>group_by(flight)|>summarize(delay=mean(
na.rm=TRUE),cancelled=sum(is.na(arr_delay)),n=n())|>filter(n>10) arr_delay,
The restyled code is as below:---
Let us try to use the styler
package for the same task, using Ctrl + Shift + P
. The styled code using styler
is shown below:---
|>
flights filter(dest == "IAH") |>
group_by(year, month, day) |>
summarise(
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) |>
summarise(delay = mean(
arr_delay,na.rm = TRUE
cancelled = sum(is.na(arr_delay)), n = n()) |>
), filter(n > 10)