
1 Mar
2013
1 Mar
'13
3:51 p.m.
gast128 wrote:
Steven Watanabe
writes:
This is called std::nth_element.
Thx, but are you sure? Median is defined as the middle element in odd distributions but is the average of the 2 middle elements in even distributions.
So? For a collection c of size 2n, you would use: nth_element( begin(c), begin(c) + n - 1, end(c) ); nth_element( begin(c), begin(c) + n, end(c) ); auto median = (c[n - 1] + c[n]) / 2;
For quartiles (or generalized quantiles) its even worse: there are multiple definitions for quartiles. I even had an article listed 11 definitions of calculating the quartile: http://www.amstat.org/publications/jse/v14n3/langford.html. Still it would have been better if Boost had done the thinking for me :)
Definitely!