R script to obtain the output data