added R code for Ch4.1-4.5