r2rs-stats 0.1.1

Statistics programming for Rust based on R's stats package
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
// "Whatever you do, work at it with all your heart, as working for the Lord,
// not for human masters, since you know that you will receive an inheritance
// from the Lord as a reward. It is the Lord Christ you are serving."
// (Col 3:23-24)

pub fn canberra(row1: &[&f64], row2: &[&f64]) -> f64 {
    let mut distance = 0.0;
    for (&x1, &x2) in row1.iter().zip(row2.iter()) {
        distance += (x1 - x2).abs() / (x1.abs() + x2.abs());
    }
    distance
}