Working on Andrew's Chpt 4 & 5 R code