本章主要展示关于排序与定位的代码参考,比如取出奇数位置的成员、计算排名、前10名第3名倒数第2名中位数、针对前3名计算比上期、前20%的成员中50%的成员、随机取10个成员、计算最大连续区间、对序表做排序、按事先规定的次序排序、为排列建立二分查找索引等。
|
A |
|
1 |
[1,2,3,4,5,6,7,8,9,10] |
|
3 |
=A1.step(2,1) |
[1,3,5,7,9] |
|
A |
|
1 |
=demo.query("select NAME,EVENT,SCORE from GYMSCORE") |
|
2 |
=A1.ranks@z(SCORE) |
所有成绩的排名 |
3 |
=A1.rank@z(16, SCORE) |
16分排第几名 |
4 |
=[99,98,97,96,93,87,99,95].rank@z(98) |
98在序列中排第几 |
5 |
=[99,98,97,96,93,87,99,95].rank@sz(98) |
重复成员算均值98排名 |
6 |
=demo.query("select * from SCORES ") |
|
7 |
=A6.pivot(CLASS,STUDENTID;SUBJECT,SCORE) |
列转行 |
8 |
=A7.sort(CLASS,-English) |
按班级和英语倒序排序 |
9 |
=A8.derive(rank(English;CLASS):RANK) |
增加英语成绩排名 |
|
A |
|
1 |
=demo.query("select NAME,EVENT,SCORE from GYMSCORE") |
|
2 |
=A1.sort(-SCORE) |
|
3 |
=A2(to(10)) |
前十名 |
4 |
=A2.m([3,-2]) |
第三名,倒数第二名 |
5 |
=round(A2.len()/2) |
|
6 |
=A2(A5) |
中位数 |
|
A |
|
1 |
=demo.query("select * from STOCKRECORDS where STOCKID=?","000062") |
|
2 |
=A1.sort(DATE) |
按DATE排序 |
3 |
=A2.psort(-CLOSING) |
按CLOSING排序 |
4 |
=A3(to(3)) |
获得最高三天的记录序号 |
5 |
=A4.(A2.calc(A4.~, CLOSING- CLOSING[-1])) |
计算这三天的涨幅 |
|
A |
|
1 |
=demo.query("select NAME,EVENT,SCORE from GYMSCORE") |
|
2 |
=A1.sort(-SCORE) |
|
3 |
=A2.len() |
总人数 |
4 |
=round(A3*0.2) |
前20%的人数 |
5 |
=A2(to(A4)) |
前20%的成员 |
6 |
=round(A3*0.25) |
中部前25%的名次 |
7 |
=round(A3*0.75) |
中部后25%的名次 |
8 |
=A2(to(A6,A7)) |
中部50%的记录 |
9 |
=A8(1) |
中部最高分 |
10 |
=A8.m(-1) |
中部最低分 |
|
A |
|
1 |
=demo.query("select NAME,EVENT,SCORE from GYMSCORE") |
|
2 |
=A1.sort(rand())(to(10)) |
|
|
A |
|
1 |
=demo.query("select * from STOCKRECORDS where STOCKID=?","000062") |
|
2 |
=A1.sort(DATE) |
|
3 |
=A2.max(a=if(CLOSING/CLOSING[-1]>=1.05,a+1,0)) |
连续涨幅超过5%的最大天数 |
|
A |
|
1 |
=demo.query("select * from SCORES").sort(-SCORE) |
|
2 |
=demo.query("select * from SCORES").psort(-SCORE) |
|
|
A |
|
1 |
[CA,IL,KY,CO,NY] |
|
2 |
=demo.query("select NAME,ABBR,CAPITAL,POPULATION from STATES") |
|
3 |
=A2.align(A1,ABBR) |
|
|
A |
|
1 |
=demo.query("select NAME,EVENT,SCORE from GYMSCORE") |
|
2 |
=A1.sort(SCORE) |
建立二分查找索引 |
3 |
=A2.select@b(SCORE:14.175) |
二分查找返回记录 |
4 |
=A1.psort(SCORE) |
建立索引 |
5 |
=A1(A4).pselect@b(SCORE:14.175) |
|
6 |
=A4(A5) |
二分查找返回记录序号 |