Programming in R assignment 3