completed R file for program assinment 2