1: Introduction
- 1.1: Stay in Touch!
- 1.2: Preface
2: History and Overview of R
- 2.1: What is R?
- 2.2: What is S?
- 2.3: The S Philosophy
- 2.4: Back to R
- 2.5: Basic Features of R
- 2.6: Free Software
- Exercise 1
- 2.7: Design of the R System
- Exercise 2
- 2.8: Limitations of R
- Exercise 3
- 2.9: R Resources
- 2.9.1: Official Manuals
- 2.9.2: Useful Standard Texts on S and R
- 2.9.3: Other Resources
- Quiz 1
3: Getting Started with R
- 3.1: Installation
- 3.2: Getting started with the R interface
4: R Nuts and Bolts
- 4.1: Entering Input
- Exercise 4
- 4.2: Evaluation
- Exercise 5
- 4.3: R Objects
- Exercise 6
- 4.4: Numbers
- Exercise 7
- 4.5: Attributes
- Exercise 8
- 4.6: Creating Vectors
- Exercise 9
- 4.7: Mixing Objects
- Exercise 10
- 4.8: Explicit Coercion
- 4.9: Matrices
- Exercise 11
- 4.10: Lists
- Exercise 12
- 4.11: Factors
- Exercise 13
- 4.12: Missing Values
- Exercise 14
- 4.13: Data Frames
- Exercise 15
- 4.14: Names
- 4.15: Summary
- Exercise 16
- Quiz 2
5: Getting Data In and Out of R
- 5.1: Reading and Writing Data
- Exercise 17
- 5.2: Reading Data Files with read.table()
- Exercise 18
- 5.3: Reading in Larger Datasets with read.table
- Exercise 19
- 5.4: Calculating Memory Requirements for R Objects
- Exercise 20
- Quiz 3
6: Using the readr Package
- Exercise 21
- Quiz 4
7: Using Textual and Binary Formats for Storing Data
- Exercise 22
- 7.1: Using dput() and dump()
- Exercise 23
- 7.2: Binary Formats
- Exercise 24
- Quiz 5
8: Interfaces to the Outside World
- 8.1: File Connections
- Exercise 25
- 8.2: Reading Lines of a Text File
- Exercise 26
- 8.3: Reading From a URL Connection
- Exercise 27
- Quiz 6
9: Subsetting R Objects
- 9.1: Subsetting a Vector
- Exercise 28
- 9.2: Subsetting a Matrix
- 9.2.1: Dropping matrix dimensions
- Exercise 29
- 9.3: Subsetting Lists
- Exercise 30
- 9.4: Subsetting Nested Elements of a List
- Exercise 31
- 9.5: Extracting Multiple Elements of a List
- Exercise 32
- 9.6: Partial Matching
- Exercise 33
- 9.7: Removing NA Values
- Exercise 34
- Quiz 7
10: Vectorized Operations
- Exercise 35
- 10.1: Vectorized Matrix Operations
- Exercise 36
- Quiz 8
11: Dates and Times
- 11.1: Dates in R
- Exercise 37
- 11.2: Times in R
- Exercise 38
- 11.3: Operations on Dates and Times
- Exercise 39
- 11.4: Summary
- Exercise 40
- Quiz 9
12: Managing Data Frames with the dplyr package
- 12.1: Data Frames
- 12.2: The dplyr Package
- 12.3: dplyr Grammar
- 12.3.1: Common dplyr Function Properties
- Exercise 41
- 12.4: Installing the dplyr package
- Exercise 42
- 12.5: select()
- Exercise 43
- 12.6: filter()
- Exercise 44
- 12.7: arrange()
- Exercise 45
- 12.8: rename()
- Exercise 46
- 12.9: mutate()
- Exercise 47
- 12.10: group_by()
- Exercise 48
- 12.11: %>%
- Exercise 49
- 12.12: Summary
- Quiz 10
13: Control Structures
- 13.1: if-else
- Exercise 50
- 13.2: for Loops
- 13.3: Nested for loops
- Exercise 51
- 13.4: while Loops
- 13.5: repeat Loops
- Exercise 52
- 13.6: next, break
- Exercise 53
- 13.7: Summary
- Exercise 54
- Quiz 11
14: Functions
- 14.1: Functions in R
- Exercise 55
- 14.2: Your First Function
- Exercise 56
- 14.3: Argument Matching
- Exercise 57
- 14.4: Lazy Evaluation
- 14.5: The ... Argument
- Exercise 58
- 14.6: Arguments Coming After the ... Argument
- Exercise 59
- 14.7: Summary
- Exercise 60
- Quiz 12
15: Scoping Rules of R
- 15.1: A Diversion on Binding Values to Symbol
- Exercise 61
- 15.2: Scoping Rules
- Exercise 62
- 15.3: Lexical Scoping: Why Does It Matter?
- Exercise 63
- 15.4: Lexical vs. Dynamic Scoping
- Exercise 64
- 15.5: Application: Optimization
- Exercise 65
- 15.6: Plotting the Likelihood
- Exercise 66
- 15.7: Summary
- Quiz 13
16: Coding Standards for R
- Exercise 67
- Quiz 14
17: Loop Functions
- 17.1: Looping on the Command Line
- Exercise 68
- 17.2: lapply()
- Exercise 69
- 17.3: sapply()
- Exercise 70
- 17.4: split()
- Exercise 71
- 17.5: Splitting a Data Frame
- Exercise 72
- 17.6: tapply
- Exercise 73
- 17.7: apply()
- Exercise 74
- 17.8: Col/Row Sums and Means
- Exercise 75
- 17.9: Other Ways to Apply
- Exercise 76
- 17.10: mapply()
- Exercise 77
- 17.11: Vectorizing a Function
- Exercise 78
- 17.12: Summary
- Quiz 15
18: Regular Expressions
- 18.1: Before You Begin
- 18.2: Primary R Functions
- Exercise 79
- 18.3: grep()
- Exercise 80
- 18.4: grepl()
- Exercise 81
- 18.5: regexpr()
- Exercise 82
- 18.6: sub() and gsub()
- Exercise 83
- 18.7: regexec()
- Exercise 84
- 18.8: The stringr Package
- Exercise 85
- 18.9: Summary
- Exercise 86
- Quiz 16
19: Debugging
- 19.1: Something’s Wrong!
- Exercise 87
- 19.2: Figuring Out What’s Wrong
- Exercise 88
- 19.3: Debugging Tools in R
- Exercise 89
- 19.4: Using traceback()
- Exercise 90
- 19.5: Using debug()
- Exercise 91
- 19.6: Using recover()
- Exercise 92
- 19.7: Summary
- Exercise 93
- Quiz 17
20: Profiling R Code
- 20.1: Using system.time()
- Exercise 94
- 20.2: Timing Longer Expressions
- Exercise 95
- 20.3: The R Profiler
- Exercise 96
- 20.4: Using summaryRprof()
- Exercise 97
- 20.5: Summary
- Exercise 98
- Quiz 18
21: Simulation
- 21.1: Generating Random Numbers
- Exercise 99
- 21.2: Setting the random number seed
- 21.3: Simulating a Linear Model
- Exercise 100
- 21.4: Random Sampling
- Exercise 101
- 21.5: Summary
- Exercise 102
- Quiz 19
22: Data Analysis Case Study: Changes in Fine Particle Air Pollution in the U.S.
- 22.1: Synopsis
- 22.2: Loading and Processing the Raw Data
- 22.2.1: Reading in the 1999 data
- 22.2.2: Reading in the 2012 data
- Exercise 103
- 22.3: Results
- 22.3.1: Entire U.S. analysis
- 22.3.2: Changes in PM levels at an individual monitor
- 22.3.3: Changes in state-wide PM levels
- Exercise 104
- Quiz 20
23: Parallel Computation
- 23.1: Hidden Parallelism
- 23.1.1: Parallel BLAS
- Exercise 105
- 23.2: Embarrassing Parallelism
- Exercise 106
- 23.3: The Parallel Package
- 23.3.1: mclapply()
- 23.3.2: Error Handling
- Exercise 107
- 23.4: Example: Bootstrapping a Statistic
- 23.4.1: Generating Random Numbers
- 23.4.2: Using the boot package
- 23.5: Building a Socket Cluster
- 23.6: Summary
- Quiz 21
