added R code and notes