Chapter 1 R code