Documentation ¶
Index ¶
- func Frequency[T comparable](items []T) map[T]int
- func Mean(s []float64) float64
- func Median[T Numbers](s []T) (T, error)
- func Percentile[T Numbers](s []T, p float64) (T, error)
- func Range[T Numbers](s []T) (T, T, error)
- func StandardDeviation(s []float64) (float64, error)
- func Variance(s []float64) (float64, error)
- type Numbers
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Frequency ¶
func Frequency[T comparable](items []T) map[T]int
Frequency calculates the frequency of elements in a slice and returns a map with the counts of each element.
Example ¶
items := []string{"a", "b", "b", "c", "c", "c", "d"} freq := Frequency(items) fmt.Printf("Frequency: %v\n", freq)
Output: Frequency: map[a:1 b:2 c:3 d:1]
func Mean ¶
Mean calculates the mean (average) value of a slice of numbers.
Example ¶
s := []float64{1, 2, 3, 4, 5} mean := Mean(s) fmt.Printf("Mean: %v\n", mean)
Output: Mean: 3
func Median ¶
Median calculates the median value of a slice of numbers.
Example ¶
s := []float64{1, 2, 3, 4, 5} median, _ := Median(s) fmt.Printf("Median: %v\n", median)
Output: Median: 3
func Percentile ¶
Percentile calculates the percentile value of a slice of numbers for a given percentage (between 0 and 100).
Example ¶
s := []int{1, 2, 3, 4, 5} percentile, _ := Percentile(s, 0.5) fmt.Printf("Percentile: %v\n", percentile)
Output: Percentile: 3
func Range ¶
Range calculates the range of a slice of numbers (maximum value minus the minimum value).
Example ¶
s := []float64{1, 2, 3, 4, 5} min, max, _ := Range(s) fmt.Printf("Range: (%v, %v)\n", min, max)
Output: Range: (1, 5)
func StandardDeviation ¶
StandardDeviation calculates the standard deviation of a slice of numbers.
Example ¶
s := []float64{1, 2, 3, 4, 5} stdDev, _ := StandardDeviation(s) fmt.Printf("Standard Deviation: %v\n", stdDev)
Output: Standard Deviation: 1.5811388300841898
Types ¶
type Numbers ¶
type Numbers interface { constraints.Signed | constraints.Float }
Numbers is a constraint that permits any numeric type.
Click to show internal directories.
Click to hide internal directories.