Programming in R (Week 3 assignment)