介绍
本工具根据 excel 中 percentile 算法计算百分位数值
如果你是需要求数据中最接近所给百分位的值的话可以使用percentile
而非@iusername/percentile
安装
npm i @iusername/percentile
// 或者
yarn add @iusername/percentile
使用
const Percentile = require('@iusername/percentile')
import Percentile from '@iusername/percentile'
只求值一次的情况
var percentile = new Percentile()
const data = [2, 3, 5, 5, 5, 7, 20, 21]
var res = percentile.incsOnce(data, [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
var res = percentile.incOnce(data, 90)
需要多次求值时,可以通过初始化时传入 data 或者 init(data) 来缓存处理好的 data 数据减少每次求值所耗时间
const data = [2, 3, 5, 5, 5, 7, 20, 21]
var percentile = new Percentile(data)
var res = percentile.incValue(90)
var res = percentile.incValues([80, 90, 100])
var res = percentile.excValue(90)
var res = percentile.incValues([80, 90, 100])
实例方法
- data: 用于计算的原数组
- P:百分位值 1~100, inc时为闭区间,exc时为开区间
- PList: 需要一次求得的多个百分位值得数组
- accuracy:结果的小数位数精度值,默认为 1 表示一位小数
初始化 percentile对象数据,后续则不需要再传入相同数据进行计算了
- incValue(P: number, accuracy?: number)
根据 PERCENTILE.INC 获取结果
- incValues(PList: number[], accuracy?: number)
根据 PERCENTILE.INC 获取多个对应结果
- excValue(P: number, accuracy?: number)
根据 PERCENTILE.EXC 获取结果
- excValues(PList: number[], accuracy?: number)
根据 PERCENTILE.EXC 获取多个对应结果
- incOnce(data: number[], P: number, accuracy?: number)
根据 PERCENTILE.INC 获取结果,data 不会被缓存,适用于只计算一次即可的情况,用完后实例对象会恢复原先缓存data
- incsOnce(data: number[], PList: number[], accuracy?: number)
incOnce 的多值用法
- excOnce(data: number[], P: number, accuracy?: number)
根据 PERCENTILE.EXC 获取结果,data 不会被缓存,适用于只计算一次即可的情况,用完后实例对象会恢复原先缓存data
- excsOnce(data: number[], PList: number[], accuracy?: number)
excOnce 的多值用法
静态方法
查看计算说明
!注意
计算说明
Percentile.help()
Microsoft Office 中 PERCENTILE 函数说明
PERCENTILE 函数
License
MIT