Shift values by the given number of indices
Description
Shift values by the given number of indices
Usage
<LazyFrame>$shift(n = 1, ..., fill_value = NULL)
Arguments
n
|
Number of indices to shift forward. If a negative value is passed, values are shifted in the opposite direction instead. |
…
|
These dots are for future extensions and must be empty. |
fill_value
|
Fill the resulting null values with this value. Accepts expression input. Non-expression inputs are parsed as literals. |
Value
A polars LazyFrame
Examples
library("polars")
lf <- pl$LazyFrame(a = 1:4, b = 5:8)
# By default, values are shifted forward by one index.
lf$shift()$collect()
#> shape: (4, 2)
#> ┌──────┬──────┐
#> │ a ┆ b │
#> │ --- ┆ --- │
#> │ i32 ┆ i32 │
#> ╞══════╪══════╡
#> │ null ┆ null │
#> │ 1 ┆ 5 │
#> │ 2 ┆ 6 │
#> │ 3 ┆ 7 │
#> └──────┴──────┘
#> shape: (4, 2)
#> ┌──────┬──────┐
#> │ a ┆ b │
#> │ --- ┆ --- │
#> │ i32 ┆ i32 │
#> ╞══════╪══════╡
#> │ 3 ┆ 7 │
#> │ 4 ┆ 8 │
#> │ null ┆ null │
#> │ null ┆ null │
#> └──────┴──────┘
#> shape: (4, 2)
#> ┌───────┬───────┐
#> │ a ┆ b │
#> │ --- ┆ --- │
#> │ f64 ┆ f64 │
#> ╞═══════╪═══════╡
#> │ 3.0 ┆ 7.0 │
#> │ 4.0 ┆ 8.0 │
#> │ 100.0 ┆ 100.0 │
#> │ 100.0 ┆ 100.0 │
#> └───────┴───────┘