Preface |
|
xiii | |
About the author |
|
xxi | |
|
|
1 | (54) |
|
1 A soup to nuts project example |
|
|
3 | (10) |
|
1.1 Big picture data example |
|
|
3 | (4) |
|
1.2 Little picture data example |
|
|
7 | (4) |
|
|
7 | (1) |
|
|
7 | (1) |
|
|
8 | (1) |
|
|
9 | (1) |
|
|
10 | (1) |
|
1.3 Reusing and modifying code |
|
|
11 | (2) |
|
2 Introduction to R and RStudio |
|
|
13 | (22) |
|
|
13 | (10) |
|
2.1.1 Opening an R Script |
|
|
15 | (1) |
|
2.1.2 Setting the working directory |
|
|
16 | (1) |
|
|
17 | (5) |
|
2.1.4 Helpful cheat sheets |
|
|
22 | (1) |
|
|
23 | (2) |
|
2.3 What are functions (and packages)? |
|
|
25 | (5) |
|
|
30 | (1) |
|
|
30 | (1) |
|
2.5 First steps to exploring data |
|
|
30 | (5) |
|
3 Data types and structures |
|
|
35 | (12) |
|
|
35 | (1) |
|
3.2 Numeric, character, and logical (boolean) |
|
|
36 | (4) |
|
|
40 | (7) |
|
3.3.1 Vectors (collections of "things") |
|
|
40 | (1) |
|
|
41 | (3) |
|
3.3.3 Other data structures |
|
|
44 | (3) |
|
4 Reading and writing data |
|
|
47 | (8) |
|
|
47 | (5) |
|
|
47 | (1) |
|
|
48 | (2) |
|
|
50 | (1) |
|
|
51 | (1) |
|
|
51 | (1) |
|
|
51 | (1) |
|
|
52 | (3) |
|
|
53 | (1) |
|
|
53 | (1) |
|
|
53 | (1) |
|
|
54 | (1) |
|
|
54 | (1) |
|
|
55 | (72) |
|
|
57 | (14) |
|
5.1 Starting with a pencil and paper |
|
|
57 | (3) |
|
|
58 | (2) |
|
|
60 | (6) |
|
|
64 | (2) |
|
|
66 | (2) |
|
|
68 | (3) |
|
|
68 | (2) |
|
|
70 | (1) |
|
|
71 | (6) |
|
|
71 | (2) |
|
|
72 | (1) |
|
|
73 | (4) |
|
|
73 | (1) |
|
|
74 | (3) |
|
|
77 | (16) |
|
|
81 | (2) |
|
7.1.1 Hiding code in the output |
|
|
83 | (1) |
|
|
83 | (1) |
|
|
84 | (1) |
|
|
84 | (1) |
|
|
85 | (5) |
|
|
90 | (1) |
|
7.7 Making the output file |
|
|
90 | (3) |
|
|
93 | (14) |
|
|
93 | (3) |
|
|
96 | (9) |
|
8.2.1 Modular test scripts |
|
|
98 | (3) |
|
8.2.2 How to write unit tests |
|
|
101 | (2) |
|
|
103 | (2) |
|
8.3 Test-driven development (TDD) |
|
|
105 | (2) |
|
|
107 | (20) |
|
9.1 What is Git, and why do I need it? |
|
|
107 | (2) |
|
|
109 | (1) |
|
|
110 | (7) |
|
|
111 | (1) |
|
|
112 | (5) |
|
9.4 Setting up Git on an already-made R Project |
|
|
117 | (3) |
|
9.5 Using Git through RStudio |
|
|
120 | (6) |
|
|
126 | (1) |
|
|
126 | (1) |
|
|
127 | (92) |
|
10 Subsetting: Making big things small |
|
|
129 | (32) |
|
10.1 Select specific values |
|
|
129 | (3) |
|
10.2 Logical values and operations |
|
|
132 | (7) |
|
10.2.1 Matching a single value |
|
|
133 | (1) |
|
10.2.2 Matching multiple values |
|
|
134 | (1) |
|
|
135 | (1) |
|
10.2.4 Greater than or less than |
|
|
136 | (1) |
|
10.2.5 Combining conditional statements - or, and |
|
|
136 | (3) |
|
10.3 Subsetting a data.frame |
|
|
139 | (22) |
|
10.3.1 Select specific columns |
|
|
146 | (1) |
|
10.3.2 Select specific rows |
|
|
147 | (7) |
|
10.3.3 Subset Colorado data |
|
|
154 | (7) |
|
11 Exploratory data analysis |
|
|
161 | (22) |
|
|
163 | (5) |
|
|
168 | (3) |
|
11.3 Aggregating (summaries of groups) |
|
|
171 | (7) |
|
|
178 | (5) |
|
|
183 | (24) |
|
12.1 Finding patterns in text with grep() |
|
|
185 | (4) |
|
12.2 Finding and replacing patterns in text with gsub() |
|
|
189 | (3) |
|
12.3 Useful special characters |
|
|
192 | (10) |
|
12.3.1 Multiple characters [ ] |
|
|
193 | (2) |
|
12.3.2 n-many of previous character {n} |
|
|
195 | (1) |
|
12.3.3 n-many to m-many of previous character {n,m} |
|
|
195 | (3) |
|
|
198 | (1) |
|
|
198 | (1) |
|
|
198 | (1) |
|
12.3.7 One or more of previous |
|
|
199 | (1) |
|
12.3.8 Zero or more of previous |
|
|
199 | (2) |
|
|
201 | (1) |
|
|
201 | (1) |
|
|
202 | (1) |
|
12.4 Changing capitalization |
|
|
202 | (5) |
|
|
207 | (12) |
|
13.1 Reshaping a single column |
|
|
211 | (5) |
|
13.2 Reshaping multiple columns |
|
|
216 | (3) |
|
|
219 | (114) |
|
|
221 | (20) |
|
14.1 What does the data look like? |
|
|
222 | (1) |
|
|
223 | (1) |
|
|
224 | (12) |
|
|
236 | (1) |
|
|
237 | (4) |
|
15 More graphing with ggptot2 |
|
|
241 | (36) |
|
|
242 | (11) |
|
15.2 Graphing a single numeric variable |
|
|
253 | (7) |
|
|
254 | (4) |
|
|
258 | (1) |
|
|
259 | (1) |
|
15.3 Graphing a categorical variable |
|
|
260 | (7) |
|
|
260 | (7) |
|
15.4 Graphing data over time |
|
|
267 | (4) |
|
|
271 | (6) |
|
|
272 | (5) |
|
|
277 | (16) |
|
|
279 | (7) |
|
16.2 What really are maps? |
|
|
286 | (1) |
|
16.3 Making a hotspot map |
|
|
287 | (6) |
|
|
290 | (3) |
|
|
293 | (18) |
|
|
298 | (7) |
|
17.2 Making choropleth maps |
|
|
305 | (6) |
|
|
311 | (22) |
|
18.1 Why do interactive graphs matter? |
|
|
312 | (1) |
|
18.1.1 Understanding your data |
|
|
312 | (1) |
|
18.1.2 Police departments use them |
|
|
312 | (1) |
|
18.2 Making the interactive map |
|
|
312 | (5) |
|
18.3 Adding popup information |
|
|
317 | (4) |
|
18.4 Dealing with too many markers |
|
|
321 | (2) |
|
18.5 Interactive choropleth maps |
|
|
323 | (10) |
|
|
333 | (76) |
|
|
335 | (8) |
|
|
337 | (4) |
|
19.2 Cleaning the webscraped data |
|
|
341 | (2) |
|
|
343 | (6) |
|
|
343 | (2) |
|
|
345 | (1) |
|
20.3 Making a function to scrape recipes |
|
|
346 | (3) |
|
|
349 | (6) |
|
|
349 | (3) |
|
21.2 Scraping multiple recipes |
|
|
352 | (3) |
|
22 Scraping tables from PDFs |
|
|
355 | (18) |
|
22.1 Scraping the first table |
|
|
358 | (8) |
|
|
366 | (7) |
|
23 More scraping tables from PDFs |
|
|
373 | (24) |
|
|
373 | (14) |
|
23.2 Pregnant women incarcerated |
|
|
387 | (6) |
|
23.3 Making PDF-scraped data available to others |
|
|
393 | (4) |
|
|
397 | (12) |
|
24.1 Geocoding a single address |
|
|
397 | (6) |
|
24.2 Geocoding San Francisco marijuana dispensary locations |
|
|
403 | (6) |
Bibliography |
|
409 | |