added R code

final R code that should work - first update since all the work was done
without github