added R code for ARM Ch 4.6