I need your help!

If you find any typos, errors, or places where the text may be improved, please let me know. The best ways to provide feedback are by GitHub or hypothes.is annotations.

Opening an issue or submitting a pull request on GitHub

Hypothesis Adding an annotation using hypothes.is. To add an annotation, select some text and then click the on the pop-up menu. To see the annotations of others, click the in the upper right-hand corner of the page.

1 Introduction

How this book is organized

The book is divided into sections in with the same numbers and titles as those in R for Data Science. Not all sections have exercises. Those sections without exercises have placeholder text indicating that there are no exercises. The text for each exercise is followed by the solution.

Like R for Data Science, packages used in each chapter are loaded in a code chunk at the start of the chapter in a section titled “Prerequisites”. If exercises depend on code in a section of R for Data Science it is either provided before the exercises or within the exercise solution.

If a package is used infrequently in solutions it may not be loaded, and functions using it will be called using the package name followed by two colons, as in dplyr::mutate() (see the R for Data Science Introduction). The double colon may also be used to be explicit about the package from which a function comes.


This book is a complement to, not a substitute of, R for Data Science. It only provides the exercise solutions for it. See the R for Data Science prerequisites.

Additional, the solutions use several packages that are not used in R4DS. You can install all packages required to run the code in this book with the following line of code.


If you find any typos, errors in the solutions, have an alternative solution, or think the solution could be improved, I would love your contributions. The best way to contribute is through GitHub. Please open an issue at https://github.com/jrnold/r4ds-exercise-solutions/issues or a pull request at https://github.com/jrnold/r4ds-exercise-solutions/pulls.