programming exercise 2 for R programming course