Appendix: Using R
This book uses R and is designed to be used with R. R is free, available on almost every operating system, and there are thousands of add-on packages to do almost anything you could ever want to do. We recommend you use R with RStudio.
Installing R and RStudio
- Download and install R.
- Download and install RStudio.
- Run RStudio. On the “Packages” tab, click on “Install packages” and install the package fpp2 (make sure “install dependencies” is checked).
That’s it! You should now be ready to go.
R examples in this book
We provide R code for most examples in shaded boxes like this:
These examples assume that you have the fpp2 package loaded (and that you are using at least v2.3 of the package). So you should use the command
library(fpp2) before you try any examples provided here. (This needs to be done at the start of every R session.) Sometimes we also assume that the R code that appears earlier in the same section of the book has also been run; so it is best to work through the R code in the order provided within each section.
Getting started with R
If you have never previously used R, please work through the first section (chapters 1-8) of “R for Data Science” by Garrett Grolemund and Hadley Wickham. While this does not cover time series or forecasting, it will get you used to the basics of the R language. The Coursera R Programming course is also highly recommended.
You will learn how to use R for forecasting using the exercises in this book.