/// <summary> /// The standard deviation is a measure of how widely values are dispersed from the average value (the mean). /// Logical values and text representations of numbers that you type directly into the list of arguments are counted. /// If an argument is an array or reference, only numbers in that array or reference are counted.Empty cells, logical values, text, or error values in the array or reference are ignored. /// </summary> /// <param name="arguments">Up to 254 individual arguments.</param> /// <param name="context">Unused, this is information about where the function is being executed.</param> /// <returns>The standard deviation based on the entire population.</returns> public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context) { if (this.ArgumentsAreValid(arguments, 1, out eErrorType argumentError) == false) { return(new CompileResult(argumentError)); } //Note: This follows the Functionality of excel which is diffrent from the excel documentation. //If you pass in a null Stdev.P(1,1,1,,) it will treat those emtpy spaces as zeros insted of ignoring them. List <double> listToDoStandardDeviationOn = new List <double>(); bool onlyStringInputsGiven = true; foreach (var item in arguments) { if (item.ValueAsRangeInfo != null) { foreach (var cell in item.ValueAsRangeInfo) { if (StatisticsFunctionHelper.TryToParseValuesFromInputArgumentByRefrenceOrRange(this.IgnoreHiddenValues, cell, context, false, out double numberToAddToList, out bool onlyStringInputsGiven1)) { listToDoStandardDeviationOn.Add(numberToAddToList); } onlyStringInputsGiven = onlyStringInputsGiven1; } } else { if (StatisticsFunctionHelper.TryToParseValuesFromInputArgument(this.IgnoreHiddenValues, item, context, out double numberToAddToList, out bool onlyStringInputsGiven2)) { listToDoStandardDeviationOn.Add(numberToAddToList); } onlyStringInputsGiven = onlyStringInputsGiven2; if (item.ValueFirst == null) { listToDoStandardDeviationOn.Add(0.0); } } } if (onlyStringInputsGiven) { return(new CompileResult(eErrorType.Value)); } if (listToDoStandardDeviationOn.Count() == 0) { return(new CompileResult(eErrorType.Div0)); } if (!StatisticsFunctionHelper.TryStandardDeviationEntirePopulation(listToDoStandardDeviationOn, out double standardDeviation)) { return(new CompileResult(eErrorType.Value)); } return(this.CreateResult(standardDeviation, DataType.Decimal)); }
public override CompileResult Execute(IEnumerable <FunctionArgument> arguments, ParsingContext context) { if (this.ArgumentsAreValid(arguments, 1, out eErrorType argumentError) == false) { return(new CompileResult(argumentError)); } List <double> listToDoVarianceOn = new List <double>(); foreach (var item in arguments) { if (item.ValueAsRangeInfo != null) { foreach (var cell in item.ValueAsRangeInfo) { if (StatisticsFunctionHelper.TryToParseValuesFromInputArgumentByRefrenceOrRange(this.IgnoreHiddenValues, cell, context, false, out double numberToAddToList, out bool onlyStringInputsGiven1)) { listToDoVarianceOn.Add(numberToAddToList); } } } else { if (StatisticsFunctionHelper.TryToParseValuesFromInputArgument(this.IgnoreHiddenValues, item, context, out double numberToAddToList, out bool onlyStringInputsGiven2)) { listToDoVarianceOn.Add(numberToAddToList); } if (item.ValueFirst == null) { listToDoVarianceOn.Add(0.0); } } } if (listToDoVarianceOn.Count() == 0) { return(new CompileResult(eErrorType.Div0)); } if (!StatisticsFunctionHelper.TryVarSamplePopulationForAValueErrorCheck(listToDoVarianceOn, out double variance)) { return(new CompileResult(eErrorType.Value)); } return(new CompileResult(variance, DataType.Decimal)); }