lead {SparkR}R Documentation

lead

Description

Window function: returns the value that is offset rows after the current row, and defaultValue if there is less than offset rows after the current row. For example, an offset of one will return the next row at any given point in the window partition.

Usage

lead(x, offset, defaultValue = NULL)

## S4 method for signature 'characterOrColumn,numeric'
lead(x, offset = 1,
  defaultValue = NULL)

Arguments

x

the column as a character string or a Column to compute on.

offset

the number of rows after the current row from which to obtain a value. If not specified, the default is 1.

defaultValue

(optional) default to use when the offset row does not exist.

Details

This is equivalent to the LEAD function in SQL.

Note

lead since 1.6.0

See Also

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

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   # Lead mpg values by 1 row on the partition-and-ordered table
##D   out <- select(df, over(lead(df$mpg), ws), df$mpg, df$hp, df$am)
## End(Not run)

[Package SparkR version 2.2.1 Index]