“You must see this epic work...a game changer.”

**—Kirk Borne, Principal Data Scientist at Booz Allen Hamilton**
“Extremely well written with excellent explanations and examples, this book fully accomplishes the goal of providing the reading with both the programming and statistical skills required to become proficient with this language. I am nothing short of amazed at the consistent quality and clarity of the text and the utility of the exercises.”

—**Computerworld**

**Get 30% off with the coupon code DATASCIENCE**

*The Book of R* is a comprehensive, beginner-friendly guide to R, the world’s most popular programming language for statistical analysis. Even if you have no programming experience and little more than a grounding in the basics of mathematics, you’ll find everything you need to begin using R effectively for statistical analysis.

You’ll start with the basics, like how to handle data and write simple programs, before moving on to more advanced topics, like producing statistical summaries of your data and performing statistical tests and modeling. You’ll even learn how to create impressive data visualizations with R’s basic graphics tools and contributed packages, like ggplot2 and ggvis, as well as interactive 3D visualizations using the rgl package.

Dozens of hands-on exercises (with downloadable solutions) take you from theory to practice, as you learn:

The fundamentals of programming in R, including how to write data frames, create functions, and use variables, statements, and loops
Statistical concepts like exploratory data analysis, probabilities, hypothesis tests, and regression modeling, and how to execute them in R
How to access R’s thousands of functions, libraries, and data sets
How to draw valid and useful conclusions from your data
How to create publication-quality graphics of your results
Combining detailed explanations with real-world examples and exercises, this book will provide you with a solid understanding of both statistics and the depth of R’s functionality. Make *The Book of R* your doorway into the growing world of data analysis.

# About the Author

**Tilman M. Davies** is a senior lecturer at the University of Otago in New Zealand, where he teaches statistics and R at all university levels. He has been programming in R for 10 years and uses it in all of his courses.

# Table of Contents

**Preface**

**PART I THE LANGUAGE**

1 Getting Started

2 Numerics, Arithmetic, Assignment, and Vectors

3 Matrices and Arrays

4 Non-numeric Values

5 Lists and Data Frames

6 Special Values, Classes, and Coercion

7 Basic Plotting

8 Reading and Writing Files

**PART II PROGRAMMING**

9 Calling Functions

10 Conditions and Loops

11 Writing Functions

12 Exceptions, Timings, and Visibility

**PART III STATISTICS AND PROBABILITY**

13 Elementary Statistics

14 Basic Data Visualization

15 Probability

16 Common Probability Distributions

**PART IV STATISTICAL TESTING AND MODELING**

17 Sampling Distributions and Confidence

18 Hypothesis Testing

19 Analysis of Variance

20 Simple Linear Regression

21 Multiple Linear Regression

22 Linear Model Selection and Diagnostics

**PART V ADVANCED GRAPHICS**

23 Advanced Plot Customization

24 Going Further with the Grammar of Graphics

25 Defining Colors and Plotting in Higher Dimensions

26 Interactive 3D Plots (AVAILABLE NOW)

** APPENDICES**

A Installing R and Contributed Packages

B Working with RStudio (AVAILABLE NOW)

**Bibliography**

View the detailed Table of Contents (PDF)

View the Index (PDF)

(

top)

# Reviews

“I’ve been looking for a book like this for some time. It fills some holes in my course content that my own book doesn’t address.”

—**insideBIGDATA**

“I recommend this book to both beginners, as a good introduction to basic statistics and R, and to intermediate users as a desktop reference to assist in performing day-to-day analysis.”

—**One R Tip a Day**

“Overall, *The Book of R* is an excellent reference for novice data analysts and for students being introduced to statistical programming tools.”

**—Harry J. Foxwell, ACM's Computing Reviews**

“The book is therefore addressing two audiences with different needs – coders who might need help with understanding statistical concepts and statisticians of one breed or another who want to learn how to code. Satisfying both groups is a big ask, but Tilman Davies pulls it off.”

—**Network Security Newsletter**

“Davies' book is perhaps the most comprehensive explanation of the core R language in print, and an excellent introduction to using R for statistical programming.”

—**Oliver Keyes, Sociotechnical Systems researcher**

(

top)

# Updates

(

show updates)

**Page 238:** Exercise 11.3 (b) (ii) should read: 12 factorial is 479,001,600.

**Page 307:** The answer for Exercise 14.1 (i) has been updated in the resources file. It should appear as follows:

`magquan <- quantile(quakes$mag,c(1/3,2/3))`

magfac <- cut(quakes$mag,breaks=c(min(quakes$mag),magquan[1],

`magquan[2],max(quakes$mag)),include.lowest=TRUE)`

(

top)