Created
December 14, 2014 11:38
-
-
Save acple/e87f37d1d563c268992e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//http://msdn.microsoft.com/ja-jp/library/cc981895.aspx | |
public static class Extensions | |
{ | |
public static double Median(this IEnumerable<double> source) | |
{ | |
var count = source.Count(); | |
if (count == 0) throw new InvalidOperationException("Cannot compute median for an empty set."); | |
return source.OrderBy(x => x).Take((count / 2) + 1).Skip((count - 1) / 2).Average(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment