Generate a range of integers
Description
Generate a range of integers
Usage
pl$int_range(start = 0, end = NULL, step = 1, ..., dtype = pl\$Int64)
Arguments
start
|
Start of the range (inclusive). Defaults to 0. |
end
|
End of the range (exclusive). If NULL (default), the value
of start is used and start is set to 0.
|
step
|
Step size of the range. |
…
|
These dots are for future extensions and must be empty. |
dtype
|
Data type of the range. |
Value
A polars expression
Examples
#> shape: (3, 1)
#> ┌─────┐
#> │ int │
#> │ --- │
#> │ i64 │
#> ╞═════╡
#> │ 0 │
#> │ 1 │
#> │ 2 │
#> └─────┘
#> shape: (3, 1)
#> ┌─────┐
#> │ int │
#> │ --- │
#> │ i64 │
#> ╞═════╡
#> │ 0 │
#> │ 1 │
#> │ 2 │
#> └─────┘
# Generate an index column by using int_range in conjunction with len().
df <- pl$DataFrame(a = c(1, 3, 5), b = c(2, 4, 6))
df$select(
index = pl$int_range(pl$len(), dtype = pl$UInt32),
pl$all()
)
#> shape: (3, 3)
#> ┌───────┬─────┬─────┐
#> │ index ┆ a ┆ b │
#> │ --- ┆ --- ┆ --- │
#> │ u32 ┆ f64 ┆ f64 │
#> ╞═══════╪═════╪═════╡
#> │ 0 ┆ 1.0 ┆ 2.0 │
#> │ 1 ┆ 3.0 ┆ 4.0 │
#> │ 2 ┆ 5.0 ┆ 6.0 │
#> └───────┴─────┴─────┘