R script to generate tidy data