SparkR (version 2.1.2)

ntile: ntile

Description

Window function: returns the ntile group id (from 1 to n inclusive) in an ordered window partition. For example, if n is 4, the first quarter of the rows will get value 1, the second quarter will get 2, the third quarter will get 3, and the last quarter will get 4.

Usage

ntile(x)

# S4 method for numeric ntile(x)

Arguments

x

Number of ntile groups

Details

This is equivalent to the NTILE function in SQL.

See Also

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

Examples

Run this code
# NOT RUN {
  df <- createDataFrame(mtcars)

  # Partition by am (transmission) and order by hp (horsepower)
  ws <- orderBy(windowPartitionBy("am"), "hp")

  # Get ntile group id (1-4) for hp
  out <- select(df, over(ntile(4), ws), df$hp, df$am)
# }

Run the code above in your browser using DataCamp Workspace