Averageif

Description

This function is used to calculate the mean of values that satisfies a specified condition.

Syntax

 double Averageif(vector vd, string con$)

Parameters

vd

is a vector within which you want to calculate the mean of values that satisfy the condition.

con$

is the condition you use to filter vector vd (i.e. a string that contains some conditional expression). Double quotation ("") must be used for literal conditions.

Return

Return the mean of values that satisfy the condition vcon.

Example

newbook;
col(A) = data(1,15);
// Based on the literal condition "col(A) > 5 && col(A) < 10"
// this should return the average of {6,7,8,9} or 7.5
averageif(col(A),"col(A) > 5 && col(A) < 10")=;
// We can also pass the condition as a string variable
string strCond$ = "col(A) < 6 || col(A) > 9";
AveVal = averageif(col(A),strCond$);
ty $(AveVal);
//simpler condition
averageif(col(A), "<10")=;

See Also

Sumif, Countif