Originally we were using Welford’s algorithm, but this is primarily useful when computing the variance in a numerically stable manner, since Welford’s approach requires an incremental mean. I’ve removed a test for the mean of more than one instance of Number.MAX_VALUE as this is unlikely to occur in practice; most likely this was the reason I used Welford’s algorithm in the first place. There’s a paper  comparing various algorithms for computing the mean, and Welford’s is actually slightly less accurate than the naïve approach. There are some more accurate approaches but I think it’s overkill for d3.mean.  Youngs, Edward A., and Elliot M. Cramer. "Some results relevant to choice of sum and sum-of-product algorithms." Technometrics 13.3 (1971): 657-665. Related: #1842.
Showing with 11 additions and 15 deletions