using ave instead of tapply to get max,mins