Housekeeping and loading of necessary packages

First, clear out the workspace (after saving any R objects you will need later):

rm(list = ls())

Then, install the required packages:


The convention in this book will be to specify a simple install.packages("packagename") instruction to install the necessary packages, followed by a library("packagename") to load them into memory. Once the required packages are installed, you can either comment them out, or replace the line with conditional installation code:

try(require(dplyr) || install.packages("dplyr"))

But this syntax may not work on all R installations and GUIs, so we will keep ...

Get Practical Predictive Analytics now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.