on_time_flights <- flights |>
filter(arr_delay < 30)The native pipe |> and the verbs in the dplyr package
filter()summarize()group_by()mutate()arrange()inner_join()select()
|>
Take this data frame, then… filter the data, then with those results… summarize
|> |>
Pull out just the rows you want in a data set, based on some criteria
Example
the data frame
the verb (function) what column (variable) to use for filtering
only keep rows where the column meets this criterion
Another example
the data frame
the verb (function) what column (variable) to use for filtering
only keep rows where the column meets this criterion
Comparisons: == != < > <= >=, combined with & (and) or | (or)
Take a column of data from a data frame and reduce it down to a single summary statistic
Example
the data frame
the verb (function) what to call the result the column to summarize
what summary statistic to calculate
Take a column of data and reduce it down to a summary statistic, by some grouping variable
Example
the data frame
the verb (function) what to call the result the column to summarize
group_by(), then what to group by
Add a new column to a data frame, computed from the columns already there
Example
the data frame
the verb (function) what to call the new column (new variable) what to put in the new column
Sort the rows of a data frame by the values in one of its columns
Arrange Rows
Example
the data frame
the verb (function) which column to sort by, largest first
freq_dest has one row per destination and its number of flights, made with group_by(dest) and summarize().
Combine two data frames by matching rows on a key column, keeping only the keys found in both
Join Data Frames
Diagram adapted from Garrick Aden-Buie’s tidyexplain
Example
the data frame
the verb (function) the second data frame the key column both share
Pull out just the columns you want in a data set, based on the column names
Example
the data frame
the verb (function) what columns (variables) to keep