R assignment 2 - final, working version