R script to get tidy data