Struct stats::Frequencies

source ·
pub struct Frequencies<T> { /* private fields */ }
Expand description

A commutative data structure for exact frequency counts.

Implementations§

Create a new frequency table with no samples.

Examples found in repository?
src/frequency.rs (line 131)
130
131
132
133
134
    fn from_iter<I: IntoIterator<Item = T>>(it: I) -> Frequencies<T> {
        let mut v = Frequencies::new();
        v.extend(it);
        v
    }

Add a sample to the frequency table.

Examples found in repository?
src/frequency.rs (line 141)
139
140
141
142
143
    fn extend<I: IntoIterator<Item = T>>(&mut self, it: I) {
        for sample in it {
            self.add(sample);
        }
    }

Return the number of occurrences of v in the data.

Return the cardinality (number of unique elements) in the data.

Returns the mode if one exists.

Return a Vec of elements and their corresponding counts in descending order.

Examples found in repository?
src/frequency.rs (line 59)
58
59
60
61
62
63
64
65
66
67
68
    pub fn mode(&self) -> Option<&T> {
        let counts = self.most_frequent();
        if counts.is_empty() {
            return None;
        }
        if counts.len() >= 2 && counts[0].1 == counts[1].1 {
            None
        } else {
            Some(counts[0].0)
        }
    }

Return a Vec of elements and their corresponding counts in ascending order.

Returns the cardinality of the data.

Examples found in repository?
src/frequency.rs (line 52)
51
52
53
    pub fn cardinality(&self) -> u64 {
        self.len() as u64
    }

Returns true if there is no frequency/cardinality data.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Merges the value other into self.
Merges the values in the iterator into self.
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Extends a collection with the contents of an iterator. Read more
🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Creates a value from an iterator. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.