You are here

public static function PHPExcel_Calculation_Statistical::TRIMMEAN in Loft Data Grids 7.2

Same name and namespace in other branches
  1. 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Statistical.php \PHPExcel_Calculation_Statistical::TRIMMEAN()

* TRIMMEAN * * Returns the mean of the interior of a data set. TRIMMEAN calculates the mean * taken by excluding a percentage of data points from the top and bottom tails * of a data set. * * Excel Function: * TRIMEAN(value1[,value2[, ...]],$discard) * * @access public * @category Statistical Functions *

Parameters

mixed $arg,... Data values: * @param float $discard Percentage to discard * @return float

File

vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Statistical.php, line 3372

Class

PHPExcel_Calculation_Statistical
PHPExcel_Calculation_Statistical

Code

public static function TRIMMEAN() {
  $aArgs = PHPExcel_Calculation_Functions::flattenArray(func_get_args());

  // Calculate
  $percent = array_pop($aArgs);
  if (is_numeric($percent) && !is_string($percent)) {
    if ($percent < 0 || $percent > 1) {
      return PHPExcel_Calculation_Functions::NaN();
    }
    $mArgs = array();
    foreach ($aArgs as $arg) {

      // Is it a numeric value?
      if (is_numeric($arg) && !is_string($arg)) {
        $mArgs[] = $arg;
      }
    }
    $discard = floor(self::COUNT($mArgs) * $percent / 2);
    sort($mArgs);
    for ($i = 0; $i < $discard; ++$i) {
      array_pop($mArgs);
      array_shift($mArgs);
    }
    return self::AVERAGE($mArgs);
  }
  return PHPExcel_Calculation_Functions::VALUE();
}