Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Data Wrangling with R

You're reading from  Data Wrangling with R

Product type Book
Published in Feb 2023
Publisher Packt
ISBN-13 9781803235400
Pages 384 pages
Edition 1st Edition
Languages
Concepts
Author (1):
Gustavo R Santos Gustavo R Santos
Profile icon Gustavo R Santos
Toc

Table of Contents (21) Chapters close

Preface 1. Part 1: Load and Explore Data
2. Chapter 1: Fundamentals of Data Wrangling 3. Chapter 2: Loading and Exploring Datasets 4. Chapter 3: Basic Data Visualization 5. Part 2: Data Wrangling
6. Chapter 4: Working with Strings 7. Chapter 5: Working with Numbers 8. Chapter 6: Working with Date and Time Objects 9. Chapter 7: Transformations with Base R 10. Chapter 8: Transformations with Tidyverse Libraries 11. Chapter 9: Exploratory Data Analysis 12. Part 3: Data Visualization
13. Chapter 10: Introduction to ggplot2 14. Chapter 11: Enhanced Visualizations with ggplot2 15. Chapter 12: Other Data Visualization Options 16. Part 4: Modeling
17. Chapter 13: Building a Model with R 18. Chapter 14: Build an Application with Shiny in R 19. Conclusion 20. Other Books You May Enjoy

Grouping and summarizing data

Grouping and summarizing are two complementary functions. Generally, they will be used together, as there is not much use in grouping a dataset and not calculating anything or using the groups for a purpose. That is when summarizing plays the important role of transforming the data from each group into a summary or a number that we can understand.

In the business world, requests such as the average number of sales by store, the median number of customers by day, the standard deviation of a distribution, and many other examples, are part of the routine of a data scientist. These tasks can be performed using the group_by() and summarise()functions from dplyr.

Starting with the group_by() function, observe that it alone cannot bring much value:

# group by not summarized
df %>% group_by(workclass)

Here is the result.

Figure 8.9 – Dataset grouped but not summarized

We can see in Figure 8.9 that it worked because...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime