Rank function
A rank function assigns ordinal positions according to an ordering, giving tied values equal ranks and applying a defined tie-handling rule to subsequent positions.
Statistics Slam Dunk
The base R rank() function assigns ordinal ranks to elements of a vector according to their values and tie-handling rules.
- How it is used
- Uses grouped ordinal ranking to select a fixed number of high-salary or high-win-share players for inequality analysis.
- How deep it goes
- Explains descending order, grouping, tie handling, filtering, and integrity checks, but does not develop rank() internals or alternative tie methods.
- Examples
- Demonstrates rankings for NBA salaries and win shares, including tied Atlanta win shares and team-specific validation queries.
- What you can do after
- Apply it via R and dplyr to rank observations within groups and retain a controlled top-N subset.
Just Use Postgres!
A rank function assigns ordinal rankings to rows according to an ordering and gives tied rows the same rank.
- How it is used
- Ranks grouped songs by total play duration while preserving the aggregate result for each song.
- How deep it goes
- Explains the RANK() query pattern and output, but does not develop ranking internals or extensive tie behavior.
- Examples
- Uses a music-streaming dataset to rank songs by their total play duration.
- What you can do after
- Apply it via SQL to produce ordered ranks alongside grouped aggregate results.
Related concepts
- window functionkind of · A window function is an SQL operation that computes a value over related rows while preserving each individual row in the result.
- derived variableproduces · A derived variable is a data field computed from one or more existing variables through a calculation, rule, or transformation.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

