# Histogram list returning bin centers and count numbers rather than bin domain points

Is there a native Mathematica function, similar to HistogramList[...] which will return a list of bin centres and associated counts, rather than the bin domains. I guess it is probably a quick thing to write a custum function based on HistogramList[...] but if there is already a native function for this, then that would be great.

• Why not use the second argument of HistogramList and specify exactly which bins you want? – bill s Oct 23 '18 at 21:09
• @bills Because I don't always know that depending on my data type, I specify the number of bins either by some $n^{1/3}$ rule or some of the other histogram bin number algorithm. – Q.P. Oct 23 '18 at 21:13

If I understand the question, instead of:

list = HistogramList[RandomReal[{0, 10}, 100]]
{{0, 2, 4, 6, 8, 10}, {20, 17, 14, 27, 22}}


you want:

{MovingAverage[list[], 2], list[]}
{{1, 3, 5, 7, 9}, {23, 24, 25, 17, 11}}


or maybe you would prefer:

Thread[{MovingAverage[list[], 2], list[]}]
{{1, 23}, {3, 24}, {5, 25}, {7, 17}, {9, 11}}


A more fragile approach but quicker if one can assume a common binwidth:

SeedRandom;
list = HistogramList[RandomReal[{0, 10}, 100]]
(* {{0,2,4,6,8,10},{20,16,27,28,9}} *)

binwidth = list[[1, 2]] - list[[1, 1]];
{list[[1, Range[Length[list[]] - 1]]] + binwidth/2, list[]}
(* {{1,3,5,7,9},{20,16,27,28,9}} *)


But any additional speed is probably minuscule compared to getting the histogram counts in the first place.