Table of Contents
Preface vii
Overview of Chapters viii
Acknowledgements ix
About the Authors ix
1 Introduction 1
1.1 Why R? 2
1.2 Why This Book? 4
1.3 Why the Tidyverse? 6
1.4 What Tools Are Needed? 7
1.5 How This Book Can be Used in a Class 9
1.6 Plan for the Book 10
2 Foundations 13
2.1 Scripting with R 13
2.2 Understanding R 17
2.3 Working Directories 21
2.4 Setting Up an R Project 22
2.5 Loading and Using Packages and Libraries 24
2.6 Where to Get Help 29
2.7 Concluding Remarks 31
3 Data Management and Manipulation 33
3.1 Loading the Data 34
3.2 Data Wrangling 39
3.3 Grouping and Summarizing Your Data 45
3.4 Creating New Variables 48
3.5 Combining Data Sets 55
3.6 Basic Descriptive Analysis 57
3.7 Tidying a Data Set 62
3.8 Saving Your Data Set for Later Use 64
3.9 Saving Your Data Set Details for Presentation 65
4 Visualizing Your Data 69
4.1 The Global Data Set 69
4.2 The Data and Preliminaries 70
4.3 Histograms 72
4.4 Bar Plots 81
4.5 Scatterplots 84
4.6 Combining Multiple Plots 90
4.7 Saving Your Plots 94
4.8 Advanced Visualizations 95
4.9 Concluding Remarks 99
5 Essential Programming 101
5.1 Data Classes 101
5.2 Data Structures 104
5.3 Operators 110
5.4 Conditional Logic 112
5.5 User-Defined Functions 114
5.6 Making Your Code Modular 119
5.7 Loops 120
5.8 Mapping with purrr 132
5.9 Concluding Remarks 135
6 Exploratory Data Analysis 137
6.1 Visual Exploration 138
6.2 Numeric Exploration 145
6.3 Putting it All Together: Skimming Data 149
6.4 Concluding Remarks 151
7 Essential Statistical Modeling 153
7.1 Loading and Inspecting the Data 153
7.2 t-statistics 155
7.3 Chi-square Test for Contingency Tables 158
7.4 Correlation 159
7.5 Ordinary Least Squares Regression 161
7.6 Binary Response Models 171
7.7 Concluding Remarks 183
8 Parting Thoughts 185
8.1 Continuing to Learn with R 185
8.2 Where To Go from Here 186
8.3 A Final Word 187
Bibliography 189
Index 193