SparkR (version 2.1.2)

rank: rank

Description

Window function: returns the rank of rows within a window partition.

Usage

rank(x, ...)

# S4 method for missing rank()

# S4 method for ANY rank(x, ...)

Arguments

x

a numeric, complex, character or logical vector.

...

additional argument(s) passed to the method.

Details

The difference between rank and dense_rank is that dense_rank leaves no gaps in ranking sequence when there are ties. That is, if you were ranking a competition using dense_rank and had three people tie for second place, you would say that all three were in second place and that the next person came in third. Rank would give me sequential numbers, making the person that came in third place (after the ties) would register as coming in fifth.

This is equivalent to the RANK function in SQL.

See Also

Other window_funcs: cume_dist, dense_rank, lag, lead, ntile, percent_rank, row_number

Examples

Run this code
# NOT RUN {
  df <- createDataFrame(mtcars)
  ws <- orderBy(windowPartitionBy("am"), "hp")
  out <- select(df, over(rank(), ws), df$hp, df$am)
# }

Run the code above in your browser using DataCamp Workspace