The Book of R, 2nd Edition

A First Course in Programming and Statistics

Look inside
This long-awaited second edition folds years of updates into its beginner-friendly lessons on using R for data and statistical analysis.

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 writing programs in R.

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 tests and modeling. You’ll even learn how to create impressive data visualizations with R’s graphics tools and contributed packages, like ggplot2, ggvis, and rgl.

Dozens of hands-on exercises 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 datasets
  • How to draw valid and useful conclusions from your data and create publication-quality graphics of your results

The Book of R brings both statistics and R to life. With clear explanations, practical examples, and hands-on exercises, this book opens the door to the evolving world of data analysis.

New to this edition: The entire book has been revised and expanded, with nearly 100 pages of new content and exercises. You’ll find greater coverage of data plots and R graphics, guidance on using pipes to string together commands, and new ways to read and write external files, among many other lessons.
“A game changer.”
—Kirk Borne, principal data scientist at Booz Allen Hamilton
Tilman M. Davies is an academic at the Department of Mathematics and Statistics at the University of Otago in New Zealand, where he teaches statistics at all university levels. He has been programming in R since the early 2000s and uses it in all of his courses. Davies has received multiple significant research grants for his methodological work in spatial statistics and in 2024 received the Littlejohn Award, the premier research award of the New Zealand Statistical Association.
Preface
Acknowledgments
Introduction

PART I: THE LANGUAGE
Chapter 1: Getting Started
Chapter 2: Numerics, Arithmetic, Assignment, and Vectors
Chapter 3: Matrices and Arrays
Chapter 4: Non-Numeric Values
Chapter 5: Lists and Data Frames
Chapter 6: Special Values, Classes, and Coercion
Chapter 7: Basic Plotting
Chapter 8: Reading and Writing Files

PART II: PROGRAMMING
Chapter 9: Calling Functions
Chapter 10: Conditions and Loops
Chapter 11: Writing Functions
Chapter 12: Exceptions, Timings, and Visibility

PART III: STATISTICS AND PROBABILITY
Chapter 13: Elementary Statistics
Chapter 14: Basic Data Visualizations
Chapter 15: Probability
Chapter 16: Common Probability Distributions

PART IV: STATISTICAL TESTING AND MODELING
Chapter 17: Sampling Distributions and Confidence
Chapter 18: Hypothesis Testing
Chapter 19: Analysis of Variance
Chapter 20: Simple Linear Regression
Chapter 21: Multiple Linear Regression
Chapter 22: Linear Model Selection and Diagnostics

PART V: ADVANCED GRAPHICS
Chapter 23: Advanced Plot Customization
Chapter 24: Going Further with the Grammar of Graphics
Chapter 25: Defining Colors and Plotting in Higher Dimensions
Chapter 26: Interactive 3D Plots

Appendix A: Installing R and Contributed Packages
Appendix B: Working with RStudio
Reference List
The Book of R, 2nd Edition pages 26-27
The Book of R, 2nd Edition pages 52-53
The Book of R, 2nd Edition pages 104-105
The Book of R, 2nd Edition pages 200-201
The Book of R, 2nd Edition pages 306-307
The Book of R, 2nd Edition pages 400-401
The Book of R, 2nd Edition pages 504-505
The Book of R, 2nd Edition pages 622-623
The Book of R, 2nd Edition pages 730-731

About

This long-awaited second edition folds years of updates into its beginner-friendly lessons on using R for data and statistical analysis.

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 writing programs in R.

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 tests and modeling. You’ll even learn how to create impressive data visualizations with R’s graphics tools and contributed packages, like ggplot2, ggvis, and rgl.

Dozens of hands-on exercises 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 datasets
  • How to draw valid and useful conclusions from your data and create publication-quality graphics of your results

The Book of R brings both statistics and R to life. With clear explanations, practical examples, and hands-on exercises, this book opens the door to the evolving world of data analysis.

New to this edition: The entire book has been revised and expanded, with nearly 100 pages of new content and exercises. You’ll find greater coverage of data plots and R graphics, guidance on using pipes to string together commands, and new ways to read and write external files, among many other lessons.

Reviews

“A game changer.”
—Kirk Borne, principal data scientist at Booz Allen Hamilton

Author

Tilman M. Davies is an academic at the Department of Mathematics and Statistics at the University of Otago in New Zealand, where he teaches statistics at all university levels. He has been programming in R since the early 2000s and uses it in all of his courses. Davies has received multiple significant research grants for his methodological work in spatial statistics and in 2024 received the Littlejohn Award, the premier research award of the New Zealand Statistical Association.

Table of Contents

Preface
Acknowledgments
Introduction

PART I: THE LANGUAGE
Chapter 1: Getting Started
Chapter 2: Numerics, Arithmetic, Assignment, and Vectors
Chapter 3: Matrices and Arrays
Chapter 4: Non-Numeric Values
Chapter 5: Lists and Data Frames
Chapter 6: Special Values, Classes, and Coercion
Chapter 7: Basic Plotting
Chapter 8: Reading and Writing Files

PART II: PROGRAMMING
Chapter 9: Calling Functions
Chapter 10: Conditions and Loops
Chapter 11: Writing Functions
Chapter 12: Exceptions, Timings, and Visibility

PART III: STATISTICS AND PROBABILITY
Chapter 13: Elementary Statistics
Chapter 14: Basic Data Visualizations
Chapter 15: Probability
Chapter 16: Common Probability Distributions

PART IV: STATISTICAL TESTING AND MODELING
Chapter 17: Sampling Distributions and Confidence
Chapter 18: Hypothesis Testing
Chapter 19: Analysis of Variance
Chapter 20: Simple Linear Regression
Chapter 21: Multiple Linear Regression
Chapter 22: Linear Model Selection and Diagnostics

PART V: ADVANCED GRAPHICS
Chapter 23: Advanced Plot Customization
Chapter 24: Going Further with the Grammar of Graphics
Chapter 25: Defining Colors and Plotting in Higher Dimensions
Chapter 26: Interactive 3D Plots

Appendix A: Installing R and Contributed Packages
Appendix B: Working with RStudio
Reference List

Photos

The Book of R, 2nd Edition pages 26-27
The Book of R, 2nd Edition pages 52-53
The Book of R, 2nd Edition pages 104-105
The Book of R, 2nd Edition pages 200-201
The Book of R, 2nd Edition pages 306-307
The Book of R, 2nd Edition pages 400-401
The Book of R, 2nd Edition pages 504-505
The Book of R, 2nd Edition pages 622-623
The Book of R, 2nd Edition pages 730-731
  • More Websites from
    Penguin Random House
  • Common Reads
  • Library Marketing