Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Statistical calculations

Is there any built in library that I can use for calculating median in java??

I was working with apache.commons.math for other statistical functions but median was nowhere to be found.

Thank you,

like image 525
JJunior Avatar asked Nov 29 '22 18:11

JJunior


2 Answers

Put all the numbers into a list, sort the list, and take the middle value (or the average of the two middle values for even size). No calculations necessary

like image 159
Dave McClelland Avatar answered Dec 05 '22 01:12

Dave McClelland


Which version of Apache Commmons Math are you using? There is a median class at least in 2.1 onwards (older version i am not sure). You can use it as:

Median median = new Median();
median.evaluate(values);
like image 45
Ankit Bansal Avatar answered Dec 05 '22 01:12

Ankit Bansal