Add a column for row indices
Description
Add a new column at index 0 that counts the rows
Usage
<LazyFrame>$with_row_index(name, offset = NULL)
Arguments
name
|
string name of the created column |
offset
|
positive integer offset for the start of the counter |
Value
A new LazyFrame with a counter column in front
Examples
library("polars")
df = as_polars_lf(mtcars)
# by default, the index starts at 0 (to mimic the behavior of Python Polars)
df$with_row_index("idx")
#> polars LazyFrame
#> $explain(): Show the optimized query plan.
#>
#> Naive plan:
#> ROW_INDEX
#> DF ["mpg", "cyl", "disp", "hp"]; PROJECT */11 COLUMNS; SELECTION: None
#> polars LazyFrame
#> $explain(): Show the optimized query plan.
#>
#> Naive plan:
#> ROW_INDEX
#> DF ["mpg", "cyl", "disp", "hp"]; PROJECT */11 COLUMNS; SELECTION: None