Skip to content

Generate a range of integers for each row of the input columns

Source code

Description

Generate a range of integers for each row of the input columns

Usage

pl$int_ranges(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.
Not used.
dtype Data type of the range.

Value

An Expr with the data type List(dtype) (with Int64 as default of dtype).

See Also

pl$int_range() to generate a single range of integers.

Examples

library("polars")

df = pl$DataFrame(start = c(1, -1), end = c(3, 2))

df$with_columns(int_range = pl$int_ranges("start", "end"))
#> shape: (2, 3)
#> ┌───────┬─────┬────────────┐
#> │ start ┆ end ┆ int_range  │
#> │ ---   ┆ --- ┆ ---        │
#> │ f64   ┆ f64 ┆ list[i64]  │
#> ╞═══════╪═════╪════════════╡
#> │ 1.0   ┆ 3.0 ┆ [1, 2]     │
#> │ -1.0  ┆ 2.0 ┆ [-1, 0, 1] │
#> └───────┴─────┴────────────┘
df$with_columns(int_range = pl$int_ranges("start", "end", dtype = pl$Int16))
#> shape: (2, 3)
#> ┌───────┬─────┬────────────┐
#> │ start ┆ end ┆ int_range  │
#> │ ---   ┆ --- ┆ ---        │
#> │ f64   ┆ f64 ┆ list[i16]  │
#> ╞═══════╪═════╪════════════╡
#> │ 1.0   ┆ 3.0 ┆ [1, 2]     │
#> │ -1.0  ┆ 2.0 ┆ [-1, 0, 1] │
#> └───────┴─────┴────────────┘