I want to write function outliers_std(table, std) which replace outliers with zeroes.
Let's define outlier as a variable that satisfies following inequality :
So I want to go through whole table and if any element satisfies inequality above I want to replace it by 0.
My work so far
Function outliers_std(table As Variant, std As Double)
Dim row As Range
For Each row In [table].Rows
If Abs(table(row) - Application.WorksheetFunction.Average(table)) / Application.WorksheetFunction.StDev(table) > std Then
table(row) = 0
End If
Next
outliers_std = table
End Function
But when trying to run
outliers_std(E10:E14,1)
where E10:E14
is data below
I get error #ARG!
Do you have any idea where is the problem ?
EDIT
I ran code
Function outliers_std(table As Variant, std As Double) As Variant
Dim row As Range
For Each row In [table].Rows
If Abs(row - Application.WorksheetFunction.Average(table)) / Application.WorksheetFunction.StDev(table) > std Then
table(row) = 0
End If
Next
outliers_std = table
End Function
And still error stays the same. Did I write something incorrectly ?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…