ntile {SparkR}R Documentation

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

## S4 method for signature 'numeric'
ntile(x)

ntile(x)

Arguments

x

Number of ntile groups

Details

This is equivalent to the NTILE function in SQL.

Note

ntile since 1.6.0

See Also

Other window_funcs: cume_dist, cume_dist, cume_dist,missing-method; dense_rank, dense_rank, dense_rank,missing-method; lag, lag, lag,characterOrColumn-method; lead, lead, lead,characterOrColumn,numeric-method; percent_rank, percent_rank, percent_rank,missing-method; rank, rank, rank, rank,ANY-method, rank,missing-method; row_number, row_number, row_number,missing-method

Examples

## Not run: 
##D   df <- createDataFrame(mtcars)
##D 
##D   # Partition by am (transmission) and order by hp (horsepower)
##D   ws <- orderBy(windowPartitionBy("am"), "hp")
##D 
##D   # Get ntile group id (1-4) for hp
##D   out <- select(df, over(ntile(4), ws), df$hp, df$am)
## End(Not run)

[Package SparkR version 2.2.0 Index]