C#求一个double数组的平均值,最大值,最小值、中位数以及上下四分位数
public void DoAct(List<double> numlist) { double max = numlist.Max(); double min = numlist.Min(); double avg = numlist.Average(); double middle = 0; double q1 = 0;//下四分位数 double q3 = 0;//上四分位数 numlist = numlist.OrderBy(a => a).ToList();//将数组从小到大排列 int count = numlist.Count(); //求中位数 if (count / 2 == 0) { //偶数 var mindex = count / 2; middle = (numlist[mindex - 1] + numlist[mindex]) / 2; } else { //奇数 var mindex = (count + 1) / 2; middle = numlist[mindex - 1]; } int q1_index = (count + 1) / 4; int q3_index = (3 * (count + 1)) / 4; q1 = numlist[q1_index - 1]; q3 = numlist[q3_index - 1]; }