First Draft of Complete Script

The first working draft of the R script