Programming assignment 3 for R