working R script and tidy data

Added final version.