我正在尝试编写一个 VBA 函数,它可以给出数据分位数的平均值和标准差(假设总共有 5 个分位数)。数据可以是行向量或列向量。到目前为止我已经写下了以下内容:
Function AverageFractile(ret As Range, fractile As Integer) As Variant
Dim lenRange As Integer
Dim startIndex As Integer
Dim endIndex As Integer
Dim subRange As Variant
'Arrange the range object in ascending Order, doesn't work
' ret = Sort(ret, XlSortOrder = xlAscending)
'Getting the indices that would be used to slice the input range to get the relevant fractile
lenRange = Application.WorksheetFunction.Max(ret.Rows.Count, ret.Columns.Count)
startIndex = (lenRange * (fractile - 1)) \ 5 + 1
endIndex = …Run Code Online (Sandbox Code Playgroud)