-
Notifications
You must be signed in to change notification settings - Fork 0
Rank
The rank operation adds a column with an ascending or descending order based on some value.
rankedAltitudes #= Aircraft[>>Lrank:^-Altitude]
The resulting table includes all of the Aircraft attributes with an added column named Lrank filled with an integer rank value for each Altitude value. The rank values start at 1 for the lowest altitude and increasing for higher altitudes.
The : and ^- symbols have a different meaning in the context of a projection expression than they do in the restriction expression. Specifically, : serves as a delimiter and ^- and ^+ mean descending and ascending, respectively.
The operation can be useful when you want to find the n highest or lowest aircraft. For example:
ranked by altitude #= Aircraft[>>Hrank:^+Altitude]
n highest rows #= ranked by altitude(Hrank < n)
n highest aircraft #= n highest rows.(-Hrank)
First we add the Hrank column with altitudes ranked with 1 representing the highest altitude. Then we grab all Aircraft with a ranking less than n. Finally, we drop the Hrank column.
We can dispense with the intermediate variables and use a single expression to produce the same result:
N highest aircraft #= Aircraft[>>Hrank:^+Altitude](Hrank < n).(-Hrank)
In fact, we could go further and convert the table back into an instance set value like so:
High fliers::Aircraft ..= N highest aircraft.Tail number
This eliminates the need for dropping the Hrank column, so the expression yielding an instance set becomes:
High fliers::Aircraft ..= Aircraft[>>Hrank:^+Altitude](Hrank < n).Tail number
Copyright 2020, 2021, 2022, 2023, 2025 © Leon Starr under MIT Open Source License
- Why they are problematic
- Instance attribute creation values
- Boolean values
- Special values
- Enumerated values
- Action block
- Statement
- Single line action
- Multiple dependent actions on a single line
- An action spread across multiple lines
- A conditional group of single line actions
- Comments
- Finding instances
- Attribute access
- Creation and deletion
- Subclass migration
- Creating a table from a class
- Creating a table with a definition
- Converting a table into a class
- Set operations on tables
- Set comparisons on tables
- Join
- Rename
- Extend
- Aggregation
- Rank
- Image
- Input values
- Signatures and name doubling
- Output values
- Execution order
- Sequential execution
- Conditional execution
- Signals
- Scrall has no for_each action
- Iteration