This exercise consists of two parts:

 

 

(from: Cotton, 2013, Learning R, O’Reilly)