Solution to R ProgrammingAssignment2