Working script, but needs testing for more cases
Script for calling r script
Script for calling r script gain.r
Testing in R