stats

Function modes

Source
pub fn modes<T, I>(it: I) -> Vec<T>
where T: PartialOrd + Clone, I: Iterator<Item = T>,
Expand description

Compute the modes on a stream of data.

If there is a single mode, then only that value is returned in the Vec however, if there multiple values tied for occuring the most amount of times those values are returned.

ยงExample

use stats;
 
let vals = vec![1, 1, 2, 2, 3];
 
assert_eq!(stats::modes(vals.into_iter()), vec![1, 2]);

This has time complexity O(n)

If the data does not have a mode, then an empty Vec is returned.