Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Seq.averageBy<'T,^U> Function (F#)
Collapse the table of content
Expand the table of content

Seq.averageBy<'T,^U> Function (F#)

Returns the average of the results generated by applying the function to each element of the sequence.

Namespace/Module Path: Microsoft.FSharp.Collections.Seq

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
Seq.averageBy : ('T -> ^U) -> seq<'T> -> ^U (requires ^U with static member (+) and ^U with static member DivideByInt and ^U with static member Zero)

// Usage:
Seq.averageBy projection source


Type: 'T -> ^U

A function applied to transform each element of the sequence.


Type: seq<'T>

The input sequence.




Thrown when the input sequence has zero elements.


Thrown when the input sequence is null.

The average of the results of applying the projection function to sequence elements.

The elements are averaged using the + operator, DivideByInt method and Zero property associated with the generated type.

This function is named AverageBy in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.

The following code example shows how to use Seq.averageBy,also compares Seq.average and Seq.averageBy.

// You can use Seq.average to average elements of a list, array, or sequence. 
let average1 = Seq.average [ 1.0 .. 10.0 ]
printfn "Average: %f" average1
// To average a sequence of integers, use Seq.averageBy to convert to float. 
let average2 = Seq.averageBy (fun elem -> float elem) (seq { 1 .. 10 })
printfn "Average: %f" average2


Average: 5.500000
Average: 5.500000

Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

© 2015 Microsoft