Modified R script for programming assignment 2