简体   繁体   English

Excel的VBA代码以我的方式找到四分之一和四分之一

[英]VBA code for excel to find quartile one and quartile three my way

Say I had the data 1,2,3,4,5. 假设我有数据1,2,3,4,5。 I need VBA code or some clever excel work to find the median (3) and then find the medians for either one and two, or four and five depending on the parameter. 我需要VBA代码或一些聪明的excel工作来找到中位数(3),然后根据参数找到1和2或4和5的中位数。

If the data was 1,2,3,3,4,5 I would want to find the medians of 1,2,3, and 3,4,5. 如果数据是1,2,3,3,4,5,我想找到1,2,3和3,4,5的中位数。 But if the data was 1,2,3,4,5 I want it to ignore the 3 and find the medians of the data on either side of the 3. depending on the parameter. 但是,如果数据是1,2,3,4,5,我希望它忽略3,并根据参数在3的任一侧找到数据的中位数。

I hope that makes sense, I know some C# but vba and excel are new to me. 我希望这是有道理的,我知道一些C#,但是vba和excel对我来说是新的。 Thanks. 谢谢。

My first thought was that you could use the quartile, but that doesn't always give the same answer. 我首先想到的是您可以使用四分位数,但这并不总是给出相同的答案。

If you wanted to ignore the middle value (for an odd number of points) and the middle two values (even number of points) you could try finding the median of a subrange something like this:- 如果您想忽略中间值(点数为奇数)和中间两个值(点数为偶数),则可以尝试查找子范围的中位数,如下所示:-

=MEDIAN(INDEX(A2:A10,1):INDEX(A2:A10,INT((COUNT(A2:A10)-1)/2)))

to get the lower median 得到较低的中位数

=MEDIAN(INDEX(A2:A10,COUNT(A2:A10)-INT((COUNT(A2:A10)-1)/2)+1):INDEX(A2:A10,COUNT(A2:A10)))

to get the upper median. 得到较高的中位数。

Assumes the data are in ascending order. 假设数据按升序排列。

To ignore the middle value but include the middle two values:- 要忽略中间值,但要包括中间两个值:-

=MEDIAN(INDEX(A2:A10,1):INDEX(A2:A10,INT(COUNT(A2:A10)/2))) 

and

=MEDIAN(INDEX(A2:A10,COUNT(A2:A10)-INT(COUNT(A2:A10)/2)+1):INDEX(A2:A10,COUNT(A2:A10)))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM