prepare R data and calculate R