solution to R Programming's ProgrammingAssignment2 v2