updated R code to meet programming assignment - draft 1