4.17 组内排名
计算学生的数学成绩在班里的排名:
Class | Name | Maths |
---|---|---|
1 | Tom | 85 |
2 | John | 92 |
2 | Joan | 86 |
1 | Rocky | 95 |
2 | Ham | 92 |
1 | Kate | 83 |
1 | Rose | 95 |
2 | Nomy | 78 |
1 | Neil | 92 |
2 | Jack | 86 |
1 | Joe | 98 |
脚本:
A | |
---|---|
1 | =T(“score.xlsx”).derive(:RankInClass) |
2 | =A1.group(Class).run(a=.ranks@z(Maths),.run(RankInClass=a(#))) |
A1 读数,并增加 RankInClass 列
A2 先按班级分组,在组内计算排名,并将值赋给 RankInClass
运行结果:
Class | Name | Maths | RankInClass |
---|---|---|---|
1 | Tom | 85 | 5 |
2 | John | 92 | 1 |
2 | Joan | 86 | 3 |
1 | Rocky | 95 | 2 |
2 | Ham | 92 | 1 |
1 | Kate | 83 | 6 |
1 | Rose | 95 | 2 |
2 | Nomy | 78 | 5 |
1 | Neil | 92 | 4 |
2 | Jack | 86 | 3 |
1 | Joe | 98 | 1 |