Updated the .R file with the solution