typestar

dplyr

27 steps in 8 sets of R.

The tour at the center of modern R. Tibbles and column selection, filtering rows, mutate, group_by, window functions, and all six joins plus join_by for keys that do not share a name.

Twenty-seven steps, the longest R tour here, because dplyr is what most R code now looks like. The pipe does a lot of the work and the verbs are deliberately few, which is the whole design.

Start this tour

Tibbles & columns

  • TibblesA tibble prints tidily, never converts strings, and never partial-matches.
  • selectChoosing columns by name, position, pattern or type.
  • Reordering columnsrelocate moves columns without listing every other one.
  • The pipeChaining operations left to right instead of nesting.

Rows

New columns

  • mutateAdding or replacing columns, computed from the ones already there.
  • case_when and if_elseVectorized conditionals, evaluated in order.
  • acrossApplying the same transformation to several columns at once.
  • mutate and case_whenAdding and deriving columns inside a pipeline.

Grouping

Windows & rows

  • Window functionslag, lead, cumulative functions and ranking, within a group.
  • Row-wise workrowwise turns each row into its own group, for calculations across columns.
  • Per-group functionsgroup_modify hands each group to a function as a data frame.

Joining

  • JoinsThe six joins, and what each one does to unmatched rows.
  • Joining on different keysjoin_by handles renamed keys, inequality joins and rolling matches.
  • Combining tablesbind_rows stacks, bind_cols widens, and both check what they can.
  • dplyr joinsCombining tibbles with explicit join verbs.

Ending a pipeline

Encore

The other R tours