R script to analyse items and calculate grades