Coursera assignment2 for R programming