简体   繁体   English

数字百分比分布的区间查询

[英]Interval Query for a Percent Distribution of Numbers

Lets say we have the following series of values假设我们有以下一系列值

10,10,10,10,10,10,14,14,14,22,22,28

According to the histogram we have the following number of values from the given series in the four bins, as:根据直方图,我们在四个箱中具有以下数量的给定系列的值,如:

9:[10,15)
0:[15,20)
2:[20,25)
1:[25,30)

As it is evident that 9/12(75%) of value lie in the interval [10,15);很明显,9/12(75%) 的价值位于区间 [10,15); 11/12(91%) of values lie in interval [10,25) . 11/12(91%) 的值位于区间[10,25)中。 I am interested to come up with a function that takes a series and percentage and returns the range of interval in which those asked percentage lie.我有兴趣想出一个 function ,它采用一系列和百分比并返回这些要求百分比所在的区间范围。

For example: query(Series=c(10,10,10,10,10,10,14,14,14,22,22,28), Pct=91) should return c(10,25) .例如: query(Series=c(10,10,10,10,10,10,14,14,14,22,22,28), Pct=91)应该返回c(10,25) I am somewhat new to R and if anyone can point me to either a builtin function for this task or provide me an implementation will be helpful.我对 R 有点陌生,如果有人可以为我指出一个内置的 function 来完成这项任务,或者为我提供一个实现将会很有帮助。 Thanks in advance提前致谢

quantile(c(10,10,10,10,10,10,14,14,14,22,22,28),c(0,0.91))

This doesn't quite produce your desired output, where you've either found the mid point between 22 and 28 or you've rounded it to an appropriate bucket size for plotting.这并不能完全产生您想要的 output,您要么找到了 22 到 28 之间的中点,要么将其四舍五入到合适的桶大小以进行绘图。 This is doing a linear interpolation for the quantile between those two points, ie 22 is the 10/11th quantile (90.9090...%) and 28 is the 100%.这是对这两个点之间的分位数进行线性插值,即 22 是第 10/11 个分位数 (90.9090...%),而 28 是 100%。 91% comes out at 22.06. 91% 出现在 22.06。

If you have binning width of 5 , maybe this would be close to your goal (similar to the answer by @pseudospin )如果您的分箱宽度为5 ,也许这将接近您的目标(类似于@pseudospin的答案)

> 5*ceiling(quantile(c(10,10,10,10,10,10,14,14,14,22,22,28),c(0,0.91))/5)
 0% 91%
 10  25

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

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