Adding R code to determine optimal bins.