Solutions to chapter 6: R exercises 8 and 9

Change-Id: I112c7d6032d872ac0d01ab93c3632f8ddb8b51e2