Binning and unbinning with average option