Table Of Content.d
e
vre
se
r sth
g
ir llA
.d
e
tim
iL
,g
n
ih
silb
u
P
tkca
P
.9
1
0
2
©
th
g
iryp
o
C
Datar, Radhika, and Harish Garg. Hands-On Exploratory Data Analysis with R : Become an Expert in Exploratory Data Analysis Using R Packages, Packt
Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5784233.
Created from nyulibrary-ebooks on 2022-10-24 22:33:29.
Hands-On Exploratory Data
Analysis with R
Become an expert in exploratory data analysis using
R packages
Radhika Datar
Harish Garg
.d
e
vre
se
r sth
g
ir llA
.d
e
tim
iL
,g
n
ih
silb
u
P
tkca
P
.9 BIRMINGHAM - MUMBAI
1
0
2
©
th
g
iryp
o
C
Datar, Radhika, and Harish Garg. Hands-On Exploratory Data Analysis with R : Become an Expert in Exploratory Data Analysis Using R Packages, Packt
Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5784233.
Created from nyulibrary-ebooks on 2022-10-24 22:33:29.
Hands-On Exploratory Data Analysis with R
Copyright © 2019 Packt Publishing
All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form
or by any means, without the prior written permission of the publisher, except in the case of brief quotations
embedded in critical articles or reviews.
Every effort has been made in the preparation of this book to ensure the accuracy of the information presented.
However, the information contained in this book is sold without warranty, either express or implied. Neither the
authors, nor Packt Publishing or its dealers and distributors, will be held liable for any damages caused or alleged to
have been caused directly or indirectly by this book.
Packt Publishing has endeavored to provide trademark information about all of the companies and products
mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy
of this information.
Commissioning Editor: Pravin Dhandre
Acquisition Editor: Nelson Morris
Content Development Editor: Pratik Andrade
Technical Editor: Nilesh Sawakhande
Copy Editor: Safis Editing
Language Support Editors: Storm Mann, Sophie Rogers
Project Coordinator: Namrata Swetta
Proofreader: Safis Editing
Indexer: Priyanka Dhadke
Graphics: Jisha Chirayil
Production Coordinator: Jyoti Chauhan
First published: May 2019
Production reference: 1310519
Published by Packt Publishing Ltd.
Livery Place
35 Livery Street
Birmingham
B3 2PB, UK.
.d
e
vre ISBN 978-1-78980-437-9
se
r sth www.packtpub.com
g
ir llA
.d
e
tim
iL
,g
n
ih
silb
u
P
tkca
P
.9
1
0
2
©
th
g
iryp
o
C
Datar, Radhika, and Harish Garg. Hands-On Exploratory Data Analysis with R : Become an Expert in Exploratory Data Analysis Using R Packages, Packt
Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5784233.
Created from nyulibrary-ebooks on 2022-10-24 22:33:29.
I would like to dedicate this book to my parents, and my in-laws, for their sacrifices, valuable
support, and for exemplifying the power of determination.
Also, to my husband, Omkar, for being a loving and supportive partner all throughout our
journey.
– Radhika Datar
.d
e
vre
se
r sth
g
ir llA
.d
e
tim
iL
,g
n
ih
silb
u
P
tkca
P
.9
1
0
2
©
th
g
iryp
o
C
Datar, Radhika, and Harish Garg. Hands-On Exploratory Data Analysis with R : Become an Expert in Exploratory Data Analysis Using R Packages, Packt
Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5784233.
Created from nyulibrary-ebooks on 2022-10-24 22:33:29.
mapt.io
Mapt is an online digital library that gives you full access to over 5,000 books and videos, as
well as industry leading tools to help you plan your personal development and advance
your career. For more information, please visit our website.
Why subscribe?
Spend less time learning and more time coding with practical eBooks and Videos
from over 4,000 industry professionals
Improve your learning with Skill Plans built especially for you
Get a free eBook or video every month
Mapt is fully searchable
Copy and paste, print, and bookmark content
Packt.com
.de Did you know that Packt offers eBook versions of every book published, with PDF and
vrese ePub files available? You can upgrade to the eBook version at www.packt.com and as a print
r sth book customer, you are entitled to a discount on the eBook copy. Get in touch with us at
g
ir llA [email protected] for more details.
.d
e
tim At www.packt.com, you can also read a collection of free technical articles, sign up for a
iL
,gn range of free newsletters, and receive exclusive discounts and offers on Packt books and
ih
silb eBooks.
u
P
tkca
P
.9
1
0
2
©
th
g
iryp
o
C
Datar, Radhika, and Harish Garg. Hands-On Exploratory Data Analysis with R : Become an Expert in Exploratory Data Analysis Using R Packages, Packt
Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5784233.
Created from nyulibrary-ebooks on 2022-10-24 22:33:29.
Contributors
About the authors
Radhika Datar has more than 5 years' experience in software development and content
writing. She is well versed in frameworks such as Python, PHP, and Java, and regularly
provides training on them. She has been working with Educba and Eduonix as a training
consultant since June 2016, while also working as a freelance academic writer in data
science and data analytics. She obtained her master's degree from the Symbiosis Institute of
Computer Studies and Research and her bachelor's degree from K. J. Somaiya College of
Science and Commerce.
Harish Garg is a Principal Software Developer, author, and co-founder of a software
development and training company, Bignumworks. Harish has more than 19 years of
experience in a wide variety of technologies, including blockchain, data science and
enterprise software. During this time, he has worked for companies such as McAfee, Intel,
etc.
.d
e
vre
se
r sth
g
ir llA
.d
e
tim
iL
,g
n
ih
silb
u
P
tkca
P
.9
1
0
2
©
th
g
iryp
o
C
Datar, Radhika, and Harish Garg. Hands-On Exploratory Data Analysis with R : Become an Expert in Exploratory Data Analysis Using R Packages, Packt
Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5784233.
Created from nyulibrary-ebooks on 2022-10-24 22:33:29.
About the reviewer
Prashant Sahu has a B.Tech. from NIT Rourkela (2003), and is currently pursuing his PhD
at the Indian Institute of Technology, Bombay (2014 onward) in the area of instrumentation,
data analytics, modeling, and simulation applied to semi-conductor materials and devices.
He is currently employed as the head of training services with Tech Smart Systems, Pune.
He has more than 15 years' experience and has handled many projects in the sphere of
academia and industry. He has also delivered several training courses for academia, as well
as corporate training courses for software companies across India in data analytics and data
science using Python and R. He is also an external examiner for B.E./M.E. projects, and a
member of the Syllabus Revision Committee at the University of Pune (Computer and IT).
Packt is searching for authors like you
If you're interested in becoming an author for Packt, please visit authors.packtpub.com
and apply today. We have worked with thousands of developers and tech professionals,
just like you, to help them share their insight with the global tech community. You can
make a general application, apply for a specific hot topic that we are recruiting an author
for, or submit your own idea.
.d
e
vre
se
r sth
g
ir llA
.d
e
tim
iL
,g
n
ih
silb
u
P
tkca
P
.9
1
0
2
©
th
g
iryp
o
C
Datar, Radhika, and Harish Garg. Hands-On Exploratory Data Analysis with R : Become an Expert in Exploratory Data Analysis Using R Packages, Packt
Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5784233.
Created from nyulibrary-ebooks on 2022-10-24 22:33:29.
Table of Contents
Preface 1
Section 1: Setting Up Data Analysis Environment
Chapter 1: Setting Up Our Data Analysis Environment 7
Technical requirements 7
The benefits of EDA across vertical markets 8
Manipulating data 10
Examining, cleaning, and filtering data 10
Visualizing data 11
Creating data reports 11
Installing the required R packages and tools 11
Installing R packages from the Terminal 12
Installing R packages from inside RStudio 12
Summary 13
Chapter 2: Importing Diverse Datasets 14
Technical requirements 14
Converting rectangular data into R with the readr R package 15
readr read functions 18
read_tsv method 18
read_delim method 19
read_fwf method 20
read_table method 20
read_log method 21
Reading in Excel data with the readxl R package 22
Reading in JSON data with the jsonlite R package 24
Loading the jsonlite package 24
.de Getting data into R from web APIs using the httr R package 25
vrese Getting data into R by scraping the web using the rvest package 26
r sth Importing data into R from relational databases using the DBI R
gir llA .d pSaucmkmagaery 2288
e
tim
iL Chapter 3: Examining, Cleaning, and Filtering 29
,gnih Technical requirements 30
silbu About the dataset 30
P
tkcaP .9 ResThhaep giantgh ear(n) dfu tnidctyioinng up erroneous data 3334
10 The unite() function 36
2
©
th
g
iryp
o
C
Datar, Radhika, and Harish Garg. Hands-On Exploratory Data Analysis with R : Become an Expert in Exploratory Data Analysis Using R Packages, Packt
Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5784233.
Created from nyulibrary-ebooks on 2022-10-24 22:33:29.
Table of Contents
The separate() function 38
The spread() function 39
Manipulating and mutating data 39
The mutate() function 40
The group_by() function 41
The summarize() function 42
The arrange() function 43
The glimpse() function 44
Selecting and filtering data 45
The select() function 45
The filter() function 46
Cleaning and manipulating time series data 47
Summary 50
Chapter 4: Visualizing Data Graphically with ggplot2 51
Technical requirements 51
Advanced graphics grammar of ggplot2 52
Data 52
Layers 52
Scales 53
The coordinate system 53
Faceting 53
Theme 53
Installing ggplot2 54
Scatter plots 55
Histogram plots 59
Density plots 61
Probability plots 63
dnorm() 63
pnorm() 64
rnorm() 65
Box plots 66
.d Residual plots 68
evre Summary 70
se
r sth Chapter 5: Creating Aesthetically Pleasing Reports with knitr and R
gir llA .d MarTkedcohwnnical requirements 7711
e
tim Installing R Markdown 72
iL
,g Working with R Markdown 74
n
ihsilb Reproducible data analysis reports with knitr 75
uP Exporting and customizing reports 80
tkca Summary 83
P
.9
1
0
2
©
th
g
irypo [ ii ]
C
Datar, Radhika, and Harish Garg. Hands-On Exploratory Data Analysis with R : Become an Expert in Exploratory Data Analysis Using R Packages, Packt
Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5784233.
Created from nyulibrary-ebooks on 2022-10-24 22:33:29.
Table of Contents
Section 2: Univariate, Time Series, and Multivariate
Data
Chapter 6: Univariate and Control Datasets 85
Technical requirements 86
Reading the dataset 86
Cleaning and tidying up the data 88
Understanding the structure of the data 93
Hypothesis tests 96
Statistical hypothesis in R 96
The t-test in R 97
Directional hypothesis in R 97
Correlation in R 98
Tietjen-Moore test 99
Parsimonious models 101
Probability plots 107
The Shapiro-Wilk test 110
Summary 112
Chapter 7: Time Series Datasets 113
Technical requirements 114
Introducing and reading the dataset 114
Cleaning the dataset 116
Mapping and understanding structure 120
Hypothesis test 122
t-test in R 123
Directional hypothesis in R 123
Grubbs' test and checking outliers 124
Parsimonious models 127
Bartlett's test 132
Data visualization 134
Autocorrelation plots 134
.de Spectrum plots 138
vrese Phase plots 139
r sth Summary 140
g
ir llA Chapter 8: Multivariate Datasets 141
.detim Technical requirements 142
iL Introducing and reading a dataset 142
,g
nih Cleaning the data 144
silbu Mapping and understanding the structure 146
P
tkca Hypothesis test 148
P .9 t-test in R 148
10 Directional hypothesis in R 149
2
©
th
g
irypo [ iii ]
C
Datar, Radhika, and Harish Garg. Hands-On Exploratory Data Analysis with R : Become an Expert in Exploratory Data Analysis Using R Packages, Packt
Publishing, Limited, 2019. ProQuest Ebook Central, http://ebookcentral.proquest.com/lib/nyulibrary-ebooks/detail.action?docID=5784233.
Created from nyulibrary-ebooks on 2022-10-24 22:33:29.