Function stats::modes

source ·
pub fn modes<T, I>(it: I) -> (Vec<T>, u32)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 are multiple values tied for occurring 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], 2));

This has time complexity O(n)

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