|
R For Dummies |
1 |
|
|
About the Authors |
5 |
|
|
Dedication |
6 |
|
|
Authors’ Acknowledgments |
6 |
|
|
Contents at a Glance |
9 |
|
|
Table of Contents |
11 |
|
|
Introduction |
21 |
|
|
About This Book |
21 |
|
|
Conventions Used in This Book |
22 |
|
|
What You’re Not to Read |
23 |
|
|
Foolish Assumptions |
24 |
|
|
How This Book Is Organized |
24 |
|
|
Icons Used in This Book |
26 |
|
|
Where to Go from Here |
26 |
|
|
Part I: R You Ready? |
27 |
|
|
Chapter 1: Introducing R: The Big Picture |
29 |
|
|
Recognizing the Benefits of Using R |
30 |
|
|
Looking At Some of the Unique Features of R |
32 |
|
|
Chapter 2: Exploring R |
35 |
|
|
Working with a Code Editor |
36 |
|
|
Starting Your First R Session |
42 |
|
|
Sourcing a Script |
45 |
|
|
Navigating the Workspace |
48 |
|
|
Chapter 3: The Fundamentals of R |
51 |
|
|
Using the Full Power of Functions |
51 |
|
|
Keeping Your Code Readable |
55 |
|
|
Getting from Base R to More |
60 |
|
|
Part 2: Getting Down to Work in R |
63 |
|
|
Chapter 4: Getting Started with Arithmetic |
65 |
|
|
Working with Numbers, Infinity, and Missing Values |
65 |
|
|
Organizing Data in Vectors |
74 |
|
|
Getting Values in and out of Vectors |
78 |
|
|
Working with Logical Vectors |
81 |
|
|
Powering Up Your Math with Vector Functions |
86 |
|
|
Chapter 5: Getting Started with Reading and Writing |
91 |
|
|
Using Character Vectors for Text Data |
91 |
|
|
Manipulating Text |
96 |
|
|
Factoring in Factors |
106 |
|
|
Chapter 6: Going on a Date with R |
113 |
|
|
Working with Dates |
113 |
|
|
Presenting Dates in Different Formats |
115 |
|
|
Adding Time Information to Dates |
117 |
|
|
Formatting Dates and Times |
118 |
|
|
Performing Operations on Dates and Times |
119 |
|
|
Chapter 7: Working in More Dimensions |
123 |
|
|
Adding a Second Dimension |
123 |
|
|
Using the Indices |
127 |
|
|
Naming Matrix Rows and Columns |
131 |
|
|
Calculating with Matrices |
133 |
|
|
Adding More Dimensions |
137 |
|
|
Combining Different Types of Values in a Data Frame |
139 |
|
|
Manipulating Values in a Data Frame |
143 |
|
|
Combining Different Objects in a List |
149 |
|
|
Part III: Coding in R |
157 |
|
|
Chapter 8: Putting the Fun in Functions |
159 |
|
|
Moving from Scripts to Functions |
159 |
|
|
Using Arguments the Smart Way |
165 |
|
|
Coping with Scoping |
170 |
|
|
Dispatching to a Method |
174 |
|
|
Chapter 9: Controlling the Logical Flow |
179 |
|
|
Making Choices with if Statements |
180 |
|
|
Doing Something Else with an if... else Statement |
182 |
|
|
Vectorizing Choices |
183 |
|
|
Making Multiple Choices |
186 |
|
|
Looping Through Values |
188 |
|
|
Looping without Loops: Meeting the Apply Family |
191 |
|
|
Chapter 10: Debugging Your Code |
199 |
|
|
Knowing What to Look For |
199 |
|
|
Reading Errors and Warnings |
200 |
|
|
Going Bug Hunting |
202 |
|
|
Generating Your Own Messages |
207 |
|
|
Recognizing the Mistakes You’re Sure to Make |
209 |
|
|
Chapter 11: Getting Help |
213 |
|
|
Finding Information in the R Help Files |
213 |
|
|
Searching the Web for Help with R |
216 |
|
|
Getting Involved in the R Community |
217 |
|
|
Making a Minimal Reproducible Example |
219 |
|
|
Part IV: Making the Data Talk |
223 |
|
|
Chapter 12: Getting Data into and out of R |
225 |
|
|
Getting Data into R |
225 |
|
|
Getting Your Data out of R |
234 |
|
|
Working with Files and Folders |
235 |
|
|
Chapter 13: Manipulating and Processing Data |
239 |
|
|
Deciding on the Most Appropriate Data Structure |
239 |
|
|
Creating Subsets of Your Data |
241 |
|
|
Adding Calculated Fields to Data |
247 |
|
|
Combining and Merging Data Sets |
250 |
|
|
Sorting and Ordering Data |
256 |
|
|
Traversing Your Data with the Apply Functions |
260 |
|
|
Getting to Know the Formula Interface |
265 |
|
|
Whipping Your Data into Shape |
266 |
|
|
Chapter 14: Summarizing Data |
273 |
|
|
Starting with the Right Data |
273 |
|
|
Describing Continuous Variables |
276 |
|
|
Describing Categories |
278 |
|
|
Describing Distributions |
281 |
|
|
Describing Multiple Variables |
284 |
|
|
Working with Tables |
290 |
|
|
Chapter 15: Testing Differences and Relations |
295 |
|
|
Taking a Closer Look at Distributions |
296 |
|
|
Comparing Two Samples |
301 |
|
|
Testing Counts and Proportions |
304 |
|
|
Working with Models |
308 |
|
|
Part V: Working with Graphics |
319 |
|
|
Chapter 16: Using Base Graphics |
321 |
|
|
Creating Different Types of Plots |
321 |
|
|
Controlling Plot Options and Arguments |
328 |
|
|
Saving Graphics to Image Files |
334 |
|
|
Chapter 17: Creating Faceted Graphics with Lattice |
337 |
|
|
Creating a Lattice Plot |
338 |
|
|
Changing Plot Options |
341 |
|
|
Plotting Different Types |
345 |
|
|
Plotting Data in Groups |
347 |
|
|
Printing and Saving a Lattice Plot |
351 |
|
|
Chapter 18: Looking At ggplot2 Graphics |
353 |
|
|
Installing and Loading ggplot2 |
353 |
|
|
Looking At Layers |
354 |
|
|
Using Geoms and Stats |
355 |
|
|
Sussing Stats |
360 |
|
|
Adding Facets, Scales, and Options |
363 |
|
|
Getting More Information |
366 |
|
|
Part VI: The Part of Tens |
367 |
|
|
Chapter 19: Ten Things You Can Do in R That You Would’ve Done in Microsoft Excel |
369 |
|
|
Adding Row and Column Totals |
369 |
|
|
Formatting Numbers |
370 |
|
|
Sorting Data |
372 |
|
|
Making Choices with If |
372 |
|
|
Calculating Conditional Totals |
373 |
|
|
Transposing Columns or Rows |
373 |
|
|
Finding Unique or Duplicated Values |
374 |
|
|
Working with Lookup Tables |
375 |
|
|
Working with Pivot Tables |
375 |
|
|
Using the Goal Seek and Solver |
376 |
|
|
Chapter 20: Ten Tips on Working with Packages |
379 |
|
|
Poking Around the Nooks and Crannies of CRAN |
379 |
|
|
Finding Interesting Packages |
380 |
|
|
Installing Packages |
380 |
|
|
Loading Packages |
381 |
|
|
Reading the Package Manual and Vignette |
381 |
|
|
Updating Packages |
382 |
|
|
Unloading Packages |
382 |
|
|
Forging Ahead with R-Forge |
383 |
|
|
Conducting Installations from BioConductor |
384 |
|
|
Reading the R Manual |
384 |
|
|
Appendix: Installing R and RStudio |
385 |
|
|
Installing and Configuring R |
385 |
|
|
Installing and Configuring RStudio |
388 |
|
|
Index |
391 |
|