|
|
|
1 The Role of Data Wrangling |
|
|
3 | (4) |
|
|
7 | (4) |
|
|
7 | (1) |
|
|
8 | (1) |
|
|
9 | (2) |
|
|
11 | (20) |
|
3.1 Installing R and RStudio |
|
|
11 | (2) |
|
3.2 Understanding the Console |
|
|
13 | (3) |
|
|
13 | (1) |
|
3.2.2 Workspace Environment |
|
|
13 | (2) |
|
|
15 | (1) |
|
|
15 | (1) |
|
3.2.5 Workspace Options and Shortcuts |
|
|
15 | (1) |
|
|
16 | (1) |
|
|
16 | (1) |
|
3.3.2 Getting Help on Functions |
|
|
16 | (1) |
|
3.3.3 Getting Help from the Web |
|
|
17 | (1) |
|
3.4 Working with Packages |
|
|
17 | (2) |
|
3.4.1 Installing Packages |
|
|
18 | (1) |
|
|
18 | (1) |
|
3.4.3 Getting Help on Packages |
|
|
19 | (1) |
|
|
19 | (1) |
|
3.5 Assignment and Evaluation |
|
|
19 | (2) |
|
|
21 | (3) |
|
|
22 | (2) |
|
|
24 | (7) |
|
3.7.1 Notation and Naming |
|
|
24 | (1) |
|
|
25 | (1) |
|
|
26 | (5) |
|
Part II Working with Different Types of Data in R 4 Dealing with Numbers |
|
|
31 | (50) |
|
|
31 | (1) |
|
4.1.1 Creating Integer and Double Vectors |
|
|
31 | (1) |
|
4.1.2 Converting Between Integer and Double Values |
|
|
32 | (1) |
|
4.2 Generating Sequence of Non-random Numbers |
|
|
32 | (1) |
|
4.2.1 Specifying Numbers Within a Sequence |
|
|
32 | (1) |
|
4.2.2 Generating Regular Sequences |
|
|
33 | (1) |
|
4.3 Generating Sequence of Random Numbers |
|
|
33 | (4) |
|
|
34 | (1) |
|
4.3.2 Normal Distribution Numbers |
|
|
34 | (1) |
|
4.3.3 Binomial Distribution Numbers |
|
|
35 | (1) |
|
4.3.4 Poisson Distribution Numbers |
|
|
36 | (1) |
|
4.3.5 Exponential Distribution Numbers |
|
|
36 | (1) |
|
4.3.6 Gamma Distribution Numbers |
|
|
37 | (1) |
|
4.4 Setting the Seed for Reproducible Random Numbers |
|
|
37 | (1) |
|
4.5 Comparing Numeric Values |
|
|
37 | (2) |
|
4.5.1 Comparison Operators |
|
|
38 | (1) |
|
|
39 | (1) |
|
4.5.3 Floating Point Comparison |
|
|
39 | (1) |
|
|
39 | (2) |
|
5 Dealing with Character Strings |
|
|
41 | (14) |
|
5.1 Character String Basics |
|
|
41 | (5) |
|
|
41 | (1) |
|
5.1.2 Converting to Strings |
|
|
42 | (1) |
|
|
43 | (2) |
|
5.1.4 Counting String Elements and Characters |
|
|
45 | (1) |
|
5.2 String Manipulation with Base R |
|
|
46 | (3) |
|
|
46 | (1) |
|
5.2.2 Simple Character Replacement |
|
|
46 | (1) |
|
5.2.3 String Abbreviations |
|
|
47 | (1) |
|
5.2.4 Extract/Replace Substrings |
|
|
47 | (2) |
|
5.3 String Manipulation with stringr |
|
|
49 | (3) |
|
|
49 | (2) |
|
5.3.2 Duplicate Characters Within a String |
|
|
51 | (1) |
|
5.3.3 Remove Leading and Trailing Whitespace |
|
|
51 | (1) |
|
5.3.4 Pad a String with Whitespace |
|
|
52 | (1) |
|
5.4 Set Operatons for Character Strings |
|
|
52 | (3) |
|
|
52 | (1) |
|
|
52 | (1) |
|
5.4.3 Identifying Different Elements |
|
|
53 | (1) |
|
5.4.4 Testing for Element Equality |
|
|
53 | (1) |
|
5.4.5 Testing for Exact Equality |
|
|
53 | (1) |
|
5.4.6 Identifying If Elements Are Contained in a String |
|
|
54 | (1) |
|
|
54 | (1) |
|
6 Dealing with Regular Expressions |
|
|
55 | (12) |
|
|
55 | (5) |
|
|
56 | (1) |
|
|
56 | (1) |
|
|
57 | (1) |
|
6.1.4 POSIX Character Classes |
|
|
58 | (1) |
|
|
59 | (1) |
|
|
60 | (6) |
|
6.2.1 Main Regex Functions in R |
|
|
60 | (3) |
|
6.2.2 Regex Functions in stringr |
|
|
63 | (3) |
|
|
66 | (1) |
|
|
67 | (4) |
|
7.1 Creating, Converting and Inspecting Factors |
|
|
67 | (1) |
|
|
68 | (1) |
|
|
69 | (1) |
|
|
69 | (2) |
|
|
71 | (10) |
|
8.1 Getting Current Date and Time |
|
|
71 | (1) |
|
8.2 Converting Strings to Dates |
|
|
72 | (1) |
|
8.2.1 Convert Strings to Dates |
|
|
72 | (1) |
|
8.2.2 Create Dates by Merging Data |
|
|
73 | (1) |
|
8.3 Extract and Manipulate Parts of Dates |
|
|
73 | (2) |
|
8.4 Creating Date Sequences |
|
|
75 | (1) |
|
8.5 Calculations with Dates |
|
|
76 | (1) |
|
8.6 Dealing with Time Zones and Daylight Savings |
|
|
77 | (1) |
|
|
78 | (3) |
|
Part III Managing Data Structures in R |
|
|
|
|
81 | (4) |
|
9.1 Identifying the Structure |
|
|
81 | (1) |
|
|
82 | (3) |
|
|
85 | (6) |
|
|
85 | (1) |
|
10.2 Adding On To Vectors |
|
|
86 | (1) |
|
10.3 Adding Attributes to Vectors |
|
|
87 | (1) |
|
|
88 | (3) |
|
10.4.1 Subsetting with Positive Integers |
|
|
88 | (1) |
|
10.4.2 Subsetting with Negative Integers |
|
|
88 | (1) |
|
10.4.3 Subsetting with Logical Values |
|
|
89 | (1) |
|
10.4.4 Subsetting with Names |
|
|
89 | (1) |
|
10.4.5 Simplifying vs. Preserving |
|
|
89 | (2) |
|
|
91 | (8) |
|
|
91 | (1) |
|
|
92 | (1) |
|
11.3 Adding Attributes to Lists |
|
|
93 | (2) |
|
|
95 | (4) |
|
11.4.1 Subset List and Preserve Output as a List |
|
|
95 | (1) |
|
11.4.2 Subset List and Simplify Output |
|
|
96 | (1) |
|
11.4.3 Subset List to Get Elements Out of a List |
|
|
96 | (1) |
|
11.4.4 Subset List with a Nested List |
|
|
96 | (3) |
|
|
99 | (6) |
|
|
99 | (1) |
|
12.2 Adding On To Matrices |
|
|
100 | (1) |
|
12.3 Adding Attributes to Matrices |
|
|
101 | (2) |
|
|
103 | (2) |
|
|
105 | (8) |
|
13.1 Creating Data Frames |
|
|
105 | (2) |
|
13.2 Adding On To Data Frames |
|
|
107 | (2) |
|
13.3 Adding Attributes to Data Frames |
|
|
109 | (2) |
|
13.4 Subsetting Data Frames |
|
|
111 | (2) |
|
14 Dealing with Missing Values |
|
|
113 | (6) |
|
14.1 Testing for Missing Values |
|
|
113 | (1) |
|
14.2 Recoding Missing Values |
|
|
114 | (1) |
|
14.3 Excluding Missing Values |
|
|
114 | (5) |
|
Part IV Importing, Scraping, and Exporting Data with R |
|
|
|
|
119 | (10) |
|
15.1 Reading Data from Text Files |
|
|
119 | (4) |
|
|
119 | (3) |
|
|
122 | (1) |
|
15.2 Reading Data from Excel Files |
|
|
123 | (4) |
|
|
123 | (2) |
|
|
125 | (2) |
|
15.3 Load Data from Saved R Object File |
|
|
127 | (1) |
|
15.4 Additional Resources |
|
|
127 | (2) |
|
|
129 | (34) |
|
16.1 Importing Tabular and Excel Files Stored Online |
|
|
129 | (5) |
|
|
134 | (9) |
|
16.2.1 Scraping HTML Nodes |
|
|
135 | (4) |
|
16.2.2 Scraping Specific HTML Nodes |
|
|
139 | (2) |
|
|
141 | (2) |
|
16.3 Scraping HTML Table Data |
|
|
143 | (7) |
|
16.3.1 Scraping HTML Tables with rvest |
|
|
143 | (3) |
|
16.3.2 Scraping HTML Tables with XML |
|
|
146 | (4) |
|
|
150 | (12) |
|
|
150 | (1) |
|
16.4.2 Existing API Packages |
|
|
151 | (7) |
|
16.4.3 httr for All Things Else |
|
|
158 | (4) |
|
16.5 Additional Resources |
|
|
162 | (1) |
|
|
163 | (10) |
|
17.1 Writing Data to Text Files |
|
|
163 | (2) |
|
|
163 | (1) |
|
|
164 | (1) |
|
17.2 Writing Data to Excel Files |
|
|
165 | (4) |
|
|
165 | (2) |
|
|
167 | (2) |
|
17.3 Saving Data as an R Object File |
|
|
169 | (1) |
|
17.4 Additional Resources |
|
|
169 | (4) |
|
Part V Creating Efficient and Readable Code in R |
|
|
|
|
173 | (10) |
|
|
173 | (1) |
|
|
174 | (1) |
|
|
175 | (2) |
|
|
177 | (1) |
|
18.5 Returning Multiple Outputs from a Function |
|
|
177 | (1) |
|
18.6 Dealing with Invalid Parameters |
|
|
178 | (1) |
|
18.7 Saving and Sourcing Functions |
|
|
179 | (2) |
|
18.8 Additional Resources |
|
|
181 | (2) |
|
19 Loop Control Statements |
|
|
183 | (16) |
|
19.1 Basic Control Statements (i.e. if, for, while, etc.) |
|
|
183 | (7) |
|
|
183 | (1) |
|
19.1.2 if... else Statement |
|
|
184 | (2) |
|
|
186 | (1) |
|
|
187 | (2) |
|
|
189 | (1) |
|
19.1.6 Break Function to Exit a Loop |
|
|
189 | (1) |
|
19.1.7 Next Function to Skip an Iteration in a Loop |
|
|
190 | (1) |
|
|
190 | (5) |
|
19.2.1 apply() for Matrices and Data Frames |
|
|
191 | (1) |
|
19.2.2 lapply() for Lists... Output as a List |
|
|
192 | (1) |
|
19.2.3 sapply() for Lists... Output Simplified |
|
|
193 | (1) |
|
19.2.4 tapply() for Vectors |
|
|
194 | (1) |
|
19.3 Other Useful "Loop-Like" Functions |
|
|
195 | (2) |
|
19.4 Additional Resources |
|
|
197 | (2) |
|
20 Simplify Your Code with %>% |
|
|
199 | (12) |
|
|
199 | (4) |
|
|
200 | (1) |
|
20.1.2 Multiple Object Option |
|
|
200 | (1) |
|
|
201 | (2) |
|
20.2 Additional Functions |
|
|
203 | (1) |
|
20.3 Additional Pipe Operators |
|
|
204 | (3) |
|
20.4 Additional Resources |
|
|
207 | (4) |
|
Part VI Shaping and Transforming Your Data with R |
|
|
|
21 Reshaping Your Data with tidyr |
|
|
211 | (8) |
|
21.1 Making Wide Data long |
|
|
212 | (1) |
|
21.2 Making Long Data wide |
|
|
213 | (1) |
|
21.3 Splitting a Single Column into Multiple Columns |
|
|
213 | (1) |
|
21.4 Combining Multiple Columns into a Single Column |
|
|
214 | (1) |
|
21.5 Additional tidyr Functions |
|
|
215 | (2) |
|
21.6 Sequencing Your tidyr Operations |
|
|
217 | (1) |
|
21.7 Additional Resources |
|
|
218 | (1) |
|
22 Transforming Your Data with dplyr |
|
|
219 | (14) |
|
22.1 Selecting Variables of Interest |
|
|
220 | (1) |
|
|
221 | (1) |
|
22.3 Grouping Data by Categorical Variables |
|
|
222 | (1) |
|
22.4 Performing Summary Statistics on Variables |
|
|
223 | (2) |
|
22.5 Arranging Variables by Value |
|
|
225 | (1) |
|
|
226 | (2) |
|
22.7 Creating New Variables |
|
|
228 | (4) |
|
22.8 Additional Resources |
|
|
232 | (1) |
Index |
|
233 | |