Chaining operations in dplyr

To perform multiple operations on data using dplyr, we can wrap up the function calls into a larger function call. Or, we can use the %>% chaining operator to chain operations instead. In this recipe, we introduced how to chain operations when using dplyr.

Getting ready

Ensure that you completed the Enhancing a data.frame with a data.table recipe to load purchase_view.tab and purchase_order.tab as both data.frame and data.table into your R environment.

How to do it…

Perform the following steps to subset and slice data with dplyr:

  1. In R, to sum up a sequence from 1 to 10, we can wrap the series of 1 to 10 with the sum function:
    > sum(1:10)
    [1] 55
    
  2. Alternatively, we can use a chaining operator to chain operations:
    > 1:10 %>% ...

Get R for Data Science Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.