I have a set of sorted (ascending) data in the format below:
| Category | Value | S.D. |
| A | 0.1 | 0.1 |
| A | 0.2 | 0.05 |
| A | 1.3 | 0.08 |
| B | 0.1 | 0.01 |
| B | 0.2 | 0.08 |
| B | 0.6 | 0.9 |
| B | 0.7 | 0.01 |
| B | 0.9 | 0.05 |
| B | 1.1 | 0.6 |
| C | 0.5 | 0.3 |
| C | 0.9 | 0.04 |
| C | 1.0 | 0.14 |
| C | 2.1 | 0.1 | etc...
There are about 300 rows of this. I have imported this from csv and have sorted as a List
. For example data.get(1).getCategory()
results in "A", and data.get(2).getValue()
results in "0.2" (It is a String
as I am using a library.)
The data is subject to change. I need to calculate a median value for each category, and print each median value with it's category name. Where there are an even number of entries, the middle value with the smallest S.D. should be used. For example, using the above data:
"A: 0.2"
"B: 0.7"
"C: 0.9"
Here is a single pass over a sorted list solution:
But I like this one more: