R script to create tidy dataset