Summarizing data with dplyr

Besides manipulating a dataset, the most important part of dplyr is that we can easily obtain summary statistics from the data. In SQL operation, we can use the GROUP BY function for this purpose, and it is possible to perform a similar operation in dplyr. In this recipe, we will show you how to summarize data with dplyr.

Getting ready

Ensure that you completed 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 summarize data with dplyr:

  1. First, use the summarize and group_by functions to obtain the total purchase amount of each product:
    > order.dt %>% 
    + select(User, Price) ...

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.