R Script for transformation