Learn Data Science for Business

Become a Data Scientist in our online courses

Earn 6 figures or more in 6 months or less by learning R, Shiny, Machine Learning, Time Series, Web Apps, AWS, Cloud, and more!

5-10 Hours Per Week.  80/20 Skills.  End-To-End Business Projects.

Start Your Courses Now! 👉

Join over 100,000+ Data Scientists

How to Analyze Your Data Faster With R Using summarytools

Written by Matt Dancho


Hey guys, welcome back to my R-tips newsletter. Getting quick insights into your data is absolutely critical to data understanding, predictive modeling, and production. But it can be challenging if you’re just getting started. Today, I’m going to show you how to analyze your data faster using the summarytools package in R. Let’s go!

Table of Contents

Here’s what you’re learning today:

  • Why Quick Data Analysis is Important
  • How to Use summarytools to Summarize Your Data
    • Data Frame Summaries with dfSummary()
    • Descriptive Statistics with descr()
    • Frequency Tables with freq()
  • Next Steps: Join the R-Tips Newsletter to get the code and stay updated.

Get the Code (In the R-Tip 084 Folder)


R-Tips Weekly

This article is part of R-Tips Weekly, a weekly video tutorial that shows you step-by-step how to do common R coding tasks. Pretty cool, right?

Here are the links to get set up. 👇

This Tutorial is Available in Video (6-minutes)

I have a 6-minute video that walks you through setting up summarytools in R and running your first exploratory data analysis with it. 👇

Analyze Data Faster With R (Using Summarytools)

How to Analyze Your Data Faster with R Using summarytools

Why Quick Data Analysis is Important

In the fast-paced world of data science, getting quick insights into your data is crucial. It allows you to understand your data better, make informed decisions, and expedite the modeling process. However, performing exploratory data analysis (EDA) can be time-consuming if you’re not using the right tools.

Enter summarytools

The summarytools package in R simplifies the process of data exploration by providing functions that generate comprehensive summaries of your data with minimal code.

Let’s dive into how you can use summarytools to speed up your data analysis.

Getting Started with summarytools

I’ll show off some of the most important functionality in summarytools. I’ll use a customer churn dataset. You can get all of the data and code here (it’s in the R-Tip 084 Folder).

Step 1: Load Libraries and Data

First, make sure you have the summarytools and tidyverse packages installed. Then load the libraries and data needed to complete this tutorial.

Step 2: Data Frame Summaries with dfSummary()

The dfSummary() function provides a detailed summary of your data frame, including:

  • Data types
  • Missing values
  • Unique values
  • Basic statistics
  • Graphical representations

This code will open an interactive HTML report that summarizes your entire data frame, making it easy to spot anomalies or areas that need attention. Run this code:

Step 3: Descriptive Statistics with descr()

To get descriptive statistics for your numeric variables, use the descr() function. This function provides detailed statistics such as:

  • Mean
  • Median
  • Standard deviation
  • Inner quartile range (IQR)
  • Min
  • Max
  • Skewness
  • Kurtosis

Run this code:

Step 4: Frequency Tables with freq()

For categorical variables, the freq() function generates frequency tables that show the distribution of categories. This helps you understand the distribution and prevalence of each category within your data.

Run this code:

Conclusions:

By leveraging the summarytools package, you can perform a comprehensive exploratory data analysis with just a few lines of code. This not only saves you time but also enhances your understanding of the data, allowing you to make better-informed decisions.