R script to process data