3.14 Inter-sequence computations: compare sequences
Select certain records by comparing the sizes of two sequences.
Based on the following Olympic Medal Table, find games when China goes ahead of Russia in terms of medal count.
Game | Nation | Medal |
---|---|---|
30 | USA | 46,29,29 |
30 | China | 38,27,23 |
30 | UK | 29,17,19 |
30 | Russia | 24,26,32 |
30 | Korea | 13,8,7 |
… | … | … |
SPL can use character “>” to compare sequences by aligning members in order:
SPL script:
A | |
---|---|
1 | =T(“Olympic.xlsx”) |
2 | =A1.run(Medal=Medal.split@cq()) |
3 | =A2.group(Game) |
4 | =A3.select(~.select(Nation==“China”).Medal>~.select(Nation==“Russia”).Medal) |
5 | =A4.(Game) |
A1 Import Olympic medal count ranking table.
A2 Split each Medal value by comma.
A3 Group A2’s records by Game.
A4 Use “>” to compare sequence of medal records of China and that of medal records of Russia. The operation compares counts of Gold medals, Silver medals an Bronze medals in order and selects games when China ranks higher than Russia.
A5 List the eligible games.
Execution result:
Game |
---|
23 |
25 |
28 |
29 |
30 |
Other characters for comparing sequences include “<” and “==”.
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL