MCPcopy Create free account
hub / github.com/arq5x/bedtools2 / getMedian

Method getMedian

src/utils/KeyListOps/KeyListOpsMethods.cpp:86–101  ·  view source on GitHub ↗

return the median value in the vector

Source from the content-addressed store, hash-verified

84
85// return the median value in the vector
86double 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
104const string &KeyListOpsMethods::getMode() {

Callers 1

KeyListOps.cppFile · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected