return the median value in the vector
| 84 | |
| 85 | // return the median value in the vector |
| 86 | double KeyListOpsMethods::getMedian() { |
| 87 | if (empty()) return NAN; |
| 88 | |
| 89 | //get sorted vector. if even number of elems, return middle val. |
| 90 | //if odd, average of two. |
| 91 | toArray(true, ASC); |
| 92 | size_t count = getCount(); |
| 93 | if (count % 2) { |
| 94 | //odd number of elements. Take middle one. |
| 95 | return _numArray[count/2]; |
| 96 | } else { |
| 97 | //even numnber of elements. Take average of middle 2. |
| 98 | double sum = _numArray[count/2 -1] + _numArray[count/2]; |
| 99 | return sum / 2.0; |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | // return the most common value in the vector |
| 104 | const string &KeyListOpsMethods::getMode() { |