我正在尝试编写一个 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 = (lenRange * fractile) \ 5
' subRange = ret(Cells(startIndex,1),Cells(endIndex,1))
' This is not working
End Function
Run Code Online (Sandbox Code Playgroud)
到目前为止,我被困在两个地方:-a)我正在尝试对数据进行排序,但排序功能不起作用,如何按升序对作为输入的范围对象进行排序?
b) 如何从范围对象中选择一个子范围,以便计算其平均值和标准差?
感谢您的帮助,我已经尝试了几个小时但未能解决。
正如我在评论中所说,你的问题中有“太多问题”。然而,这是我对你的“标题”问题的回答:
Function subRange(r As Range, startPos As Integer, endPos As Integer) as Range
Set subRange = r.Parent.Range(r.Cells(startPos), r.Cells(endPos))
End Function
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21561 次 |
| 最近记录: |