solution to R Programming's ProgrammingAssignment2