# NOT RUN {
df <- createDataFrame(mtcars)
# Partition by am (transmission) and order by hp (horsepower)
ws <- orderBy(windowPartitionBy("am"), "hp")
# Rank on hp within each partition
out <- select(df, over(rank(), ws), df$hp, df$am)
# Lag mpg values by 1 row on the partition-and-ordered table
out <- select(df, over(lead(df$mpg), ws), df$mpg, df$hp, df$am)
# }
Run the code above in your browser using DataLab