R script for tidy data