The static Count() method on class StatsFunctions returns the number of elements in a data set:
int numElements = StatsFunctions.Count( data );
Counts() returns an IDictionary of key-value pairs in which the keys are the unique elements in a given data set, and the values are the counts for each element.
CountIf() calculates how many elements in a data set return true when a logical function is applied. For example, suppose MeetsThreshold() is a method that returns true if a given numeric value is greater than 100:
public bool MeetsThreshold( double x )
{
return ( x > 100 );
}
This code counts the number of elements in a data set that meet the criterion:
int num = StatsFunctions.CountIf( data, new StatsFunctions.LogicalDoubleFunction( MeetsThreshold ) );
Similarly, the static Sum() method sums the elements in a data set. SumIf() sums the elements in a data set that return true when a logical function is applied:
double sum = StatsFunctions.SumIf( data, new StatsFunctions.LogicalDoubleFunction( MeetsThreshold ) );
An overload of SumIf() sums the elements in one data set based on evaluating a logical function on another data set. For instance, this code sums the elements in data2 that correspond to those elements in data where MeetsThreshold() returns true:
double sum = StatsFunctions.SumIf( data, function, data2 );
A MismatchedSizeException is raised if the two data sets do not have the same number of elements.
TOC | Previous | Next | Index