In just 24 lessons of one hour or less, Sams Teach Yourself R in 24 Hours helps you learn all the R skills you need to solve a wide spectrum of real-world data analysis problems. You’ll master the entire data analysis workflow, learning to build code that’s efficient, reproducible, and suitable for sharing with others.
This book’s straightforward, step-by-step approach teaches you how to import, manipulate, summarize, model, and plot data with R; formalize your analytical code; and build powerful R packages using current best practices.
Practical, hands-on examples show you how to apply what you learn.
Quizzes and exercises help you test your knowledge and stretch your skills.
Learn How To
Register your book at informit.com/register for convenient access to updates and corrections as they become available.
This book’s source code can be found at http://www.mango-solutions.com/wp/teach-yourself-r-in-24-hours-book/.
You can find all of the code in this book in an R package called Mango training available from CRAN.
Download the sample pages (includes Chapter 4 and Index)
Preface xii
HOUR 1: The R Community 1
A Concise History of R 1
The R Community 3
R Development 7
Summary 8
Q&A 8
Workshop 9
Activities 9
HOUR 2: The R Environment 11
Integrated Development Environments 11
R Syntax 14
R Objects 16
Using R Packages 23
Internal Help 28
Summary 29
Q&A 30
Workshop 30
Activities 32
HOUR 3: Single-Mode Data Structures 33
The R Data Types 33
Vectors, Matrices, and Arrays 34
Vectors 35
Matrices 49
Arrays 58
Relationship Between Single-Mode Data Objects 60
Summary 62
Q&A 62
Workshop 63
Activities 64
HOUR 4: Multi-Mode Data Structures 67
Multi-Mode Structures 67
Lists 68
Data Frames 86
Exploring Your Data 93
Summary 98
Q&A 98
Workshop 100
Activities 101
HOUR 5: Dates, Times, and Factors 103
Working with Dates and Times 103
The lubridate Package 107
Working with Categorical Data 108
Summary 112
Q&A 112
Workshop 113
Activities 114
HOUR 6: Common R Utility Functions 115
Using R Functions 115
Functions for Numeric Data 117
Logical Data 121
Missing Data 122
Character Data 123
Summary 125
Q&A 126
Workshop 126
Activities 127
HOUR 7: Writing Functions: Part I 129
The Motivation for Functions 129
Creating a Simple Function 130
The If/Else Structure 136
Summary 146
Q&A 147
Workshop 148
Activities 149
HOUR 8: Writing Functions: Part II 151
Errors and Warnings 151
Checking Inputs 155
The Ellipsis 157
Checking Multivalue Inputs 162
Using Input Definition 164
Summary 168
Q&A 168
Workshop 170
Activities 171
HOUR 9: Loops and Summaries 173
Repetitive Tasks 173
The “apply” Family of Functions 181
The apply Function 183
The lapply Function 195
The sapply Function 204
The tapply Function 208
Summary &
