Final R program