The Art of R Programming

404 Pages · 4.51 mb ·

Norman Matloff

Programming

Table of contents

- Copyright (Page 6)
- Brief Contents (Page 7)
- Contents in Detail (Page 9)
- Acknowledgments (Page 19)
- Introduction (Page 21)
- Why Use R for Your Statistical Work? (Page 21)
- Whom Is This Book For? (Page 24)
- My Own Background (Page 25)
- 1: Getting Started (Page 27)
- 1.1 How to Run R (Page 27)
- 1.2 A First R Session (Page 30)
- 1.3 Introduction to Functions (Page 33)
- 1.4 Preview of Some Important R Data Structures (Page 36)
- 1.5 Extended Example: Regression Analysis of Exam Grades (Page 42)
- 1.6 Startup and Shutdown (Page 45)
- 1.7 Getting Help (Page 46)
- 2: Vectors (Page 51)
- 2.1 Scalars, Vectors, Arrays, and Matrices (Page 52)
- 2.2 Declarations (Page 54)
- 2.3 Recycling (Page 55)
- 2.4 Common Vector Operations (Page 56)
- 2.5 Using all() and any() (Page 61)
- 2.6 Vectorized Operations (Page 65)
- 2.7 NA and NULL Values (Page 69)
- 2.8 Filtering (Page 71)
- 2.9 A Vectorized if-then-else: The ifelse() Function (Page 74)
- 2.10 Testing Vector Equality (Page 80)
- 2.11 Vector Element Names (Page 82)
- 2.12 More on c() (Page 82)
- 3: Matrices and Arrays (Page 85)
- 3.1 Creating Matrices (Page 85)
- 3.2 General Matrix Operations (Page 87)
- 3.3 Applying Functions to Matrix Rows and Columns (Page 96)
- 3.4 Adding and Deleting Matrix Rows and Columns (Page 99)
- 3.5 More on the Vector/Matrix Distinction (Page 104)
- 3.6 Avoiding Unintended Dimension Reduction (Page 106)
- 3.7 Naming Matrix Rows and Columns (Page 107)
- 3.8 Higher-Dimensional Arrays (Page 108)
- 4: Lists (Page 111)
- 4.1 Creating Lists (Page 111)
- 4.2 General List Operations (Page 113)
- 4.3 Accessing List Components and Values (Page 119)
- 4.4 Applying Functions to Lists (Page 121)
- 4.5 Recursive Lists (Page 125)
- 5: Data Frames (Page 127)
- 5.1 Creating Data Frames (Page 128)
- 5.2 Other Matrix-Like Operations (Page 130)
- 5.3 Merging Data Frames (Page 135)
- 5.4 Applying Functions to Data Frames (Page 138)
- 6: Factors and Tables (Page 147)
- 6.1 Factors and Levels (Page 147)
- 6.2 Common Functions Used with Factors (Page 149)
- 6.3 Working with Tables (Page 153)
- 6.4 Other Factor- and Table-Related Functions (Page 162)
- 7: R Programming Structures (Page 165)
- 7.1 Control Statements (Page 165)
- 7.2 Arithmetic and Boolean Operators and Values (Page 171)
- 7.3 Default Values for Arguments (Page 172)
- 7.4 Return Values (Page 173)
- 7.5 Functions Are Objects (Page 175)
- 7.6 Environment and Scope Issues (Page 177)
- 7.7 No Pointers in R (Page 185)
- 7.8 Writing Upstairs (Page 187)
- 7.9 Recursion (Page 202)
- 7.10 Replacement Functions (Page 208)
- 7.11 Tools for Composing Function Code (Page 212)
- 7.12 Writing Your Own Binary Operations (Page 213)
- 7.13 Anonymous Functions (Page 213)
- 8: Doing Math and Simulations in R (Page 215)
- 8.1 Math Functions (Page 215)
- 8.2 Functions for Statistical Distributions (Page 219)
- 8.3 Sorting (Page 220)
- 8.4 Linear Algebra Operations on Vectors and Matrices (Page 222)
- 8.5 Set Operations (Page 228)
- 8.6 Simulation Programming in R (Page 230)
- 9: Object-Oriented Programming (Page 233)
- 9.1 S3 Classes (Page 234)
- 9.2 S4 Classes (Page 248)
- 9.3 S3 Versus S4 (Page 252)
- 9.4 Managing Your Objects (Page 252)
- 10: Input/Output (Page 257)
- 10.1 Accessing the Keyboard and Monitor (Page 258)
- 10.2 Reading and Writing Files (Page 261)
- 10.3 Accessing the Internet (Page 272)
- 11: String Manipulation (Page 277)
- 11.1 An Overview of String-Manipulation Functions (Page 277)
- 11.2 Regular Expressions (Page 280)
- 11.3 Use of String Utilities in the edtdbg Debugging Tool (Page 283)
- 12: Graphics (Page 287)
- 12.1 Creating Graphs (Page 287)
- 12.2 Customizing Graphs (Page 298)
- 12.3 Saving Graphs to Files (Page 306)
- 12.4 Creating Three-Dimensional Plots (Page 308)
- 13: Debugging (Page 311)
- 13.1 Fundamental Principles of Debugging (Page 311)
- 13.2 Why Use a Debugging Tool? (Page 313)
- 13.3 Using R Debugging Facilities (Page 314)
- 13.4 Moving Up in the World: More Convenient DebuggingTools (Page 326)
- 13.5 Ensuring Consistency in Debugging Simulation Code (Page 328)
- 13.6 Syntax and Runtime Errors (Page 329)
- 13.7 Running GDB on R Itself (Page 329)
- 14: Performance Enhancement: Speed and Memory (Page 331)
- 14.1 Writing Fast R Code (Page 332)
- 14.2 The Dreaded for Loop (Page 332)
- 14.3 Functional Programming and Memory Issues (Page 340)
- 14.4 Using Rprof() to Find Slow Spots in Your Code (Page 342)
- 14.5 Byte Code Compilation (Page 346)
- 14.6 Oh No, the Data Doesn’t Fit into Memory! (Page 346)
- 15: Interfacing R to Other Languages (Page 349)
- 15.1 Writing C/C++ Functions to Be Called from R (Page 349)
- 15.2 Using R from Python (Page 356)
- 16: Parallel R (Page 359)
- 16.1 The Mutual Outlinks Problem (Page 359)
- 16.2 Introducing the snow Package (Page 360)
- 16.3 Resorting to C (Page 366)
- 16.4 General Performance Considerations (Page 371)
- 16.5 Debugging Parallel R Code (Page 377)
- Appendix A: Installing R (Page 379)
- A.1 Downloading R from CRAN (Page 379)
- A.2 Installing from a Linux Package Manager (Page 379)
- A.3 Installing from Source (Page 380)
- Appendix B: Installing and Using Packages (Page 381)
- B.1 Package Basics (Page 381)
- B.2 Loading a Package from Your Hard Drive (Page 382)
- B.3 Downloading a Package from the Web (Page 382)
- B.4 Listing the Functions in a Package (Page 384)
- Index (Page 385)
- UPDATES (Page 401)