如果你对使用 JS 感兴趣,我已经开发了一个解决方案:
var
withThis = (obj, cb) => cb(obj),
sort = array => array.sort((a, b) => a - b),
fractile = (array, parts, nth) => withThis(
(nth * (array.length + 1) / parts),
decimal => withThis(Math.floor(decimal),
even => withThis(sort(array),
sorted => sorted[even - 1] + (
(decimal - even) * (
sorted[even] - sorted[even - 1]
)
)
)
)
),
data = [
78, 72, 74, 79, 74, 71, 75, 74, 72, 68,
72, 73, 72, 74, 75, 74, 73, 74, 65, 72,
66, 75, 80, 69, 82, 73, 74, 72, 79, 71,
70, 75, 71, 70, 70, 70, 75, 76, 77, 67
]
fractile(data, 4, 1) // 1st Quartile is 71
fractile(data, 10, 3) // 3rd Decile is 71.3
fractile(data, 100, 82) // 82nd Percentile is 75.62
您只需将代码复制粘贴到浏览器中即可获得准确的结果。
更多关于 'Statistics with JS' 的信息可以在https://gist.github.com/rikyperdana/a7349c790cf5b034a1b77db64415e73c/edit找到。