R program to complete course assignment