Part3 of programming assignment3 in R