我一直在寻找一种方法来计算给定列表中每个值的百分等级,到目前为止我还没有成功.
org.apache.commons.math3为您提供了一种从值列表中获取第p个百分位数的方法,但我想要的是相反的.我想对列表中的每个值进行排名.是否有人知道一个库或Apache公共数学方法来实现这一目标?
例如:给定一个值列表{1,2,3,4,5},我希望每个值具有百分等级,最大百分位数为99或100,最小值为0或1.
更新的代码:
public class TestPercentile {
public static void main(String args[]) {
double x[] = { 10, 11, 12, 12, 12, 12, 15, 18, 19, 20 };
calculatePercentiles(x);
}
public static void calculatePercentiles(double[] arr) {
for (int i = 0; i < arr.length; i++) {
int count = 0;
int start = i;
if (i > 0) {
while (i > 0 && arr[i] == arr[i - 1]) {
count++;
i++;
}
}
double perc …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用opencsv库来编写csv文件.限制是我不想在磁盘上创建文件甚至是临时文件.有没有办法实现它?
从我看来,CSVWriter的构造函数需要一个FileWriter对象.
谢谢!