Adding dep files and dependencies.
This commit is contained in:
parent
45f9efa578
commit
b341c0a0e4
539 changed files with 313111 additions and 0 deletions
25
vendor/github.com/montanaflynn/stats/median.go
generated
vendored
Normal file
25
vendor/github.com/montanaflynn/stats/median.go
generated
vendored
Normal file
|
@ -0,0 +1,25 @@
|
|||
package stats
|
||||
|
||||
import "math"
|
||||
|
||||
// Median gets the median number in a slice of numbers
|
||||
func Median(input Float64Data) (median float64, err error) {
|
||||
|
||||
// Start by sorting a copy of the slice
|
||||
c := sortedCopy(input)
|
||||
|
||||
// No math is needed if there are no numbers
|
||||
// For even numbers we add the two middle numbers
|
||||
// and divide by two using the mean function above
|
||||
// For odd numbers we just use the middle number
|
||||
l := len(c)
|
||||
if l == 0 {
|
||||
return math.NaN(), EmptyInput
|
||||
} else if l%2 == 0 {
|
||||
median, _ = Mean(c[l/2-1 : l/2+1])
|
||||
} else {
|
||||
median = float64(c[l/2])
|
||||
}
|
||||
|
||||
return median, nil
|
||||
}
|
Reference in a new issue