Skip to content

Construct a column of length n“ filled with the given value

Description

Construct a column of length n“ filled with the given value

Usage

pl$repeat_(value, n, ..., dtype = NULL)

Arguments

value Value to repeat.
n Length of the resulting column
These dots are for future extensions and must be empty.
dtype Data type of the resulting column. If NULL (default), data type is inferred from the given value. Defaults to Int32 for integer values, unless Int64 is required to fit the given value. Defaults to Float64 for float values.

Details

If you want to construct a column in lazy mode and do not need a pre-determined length, use pl$lit() instead.

Value

A polars expression

Examples

library("polars")

# Construct a column with a repeated value in a lazy context.
pl$select(pl$repeat_("z", n = 3))
#> shape: (3, 1)
#> ┌────────┐
#> │ repeat │
#> │ ---    │
#> │ str    │
#> ╞════════╡
#> │ z      │
#> │ z      │
#> │ z      │
#> └────────┘
# Specify an output dtype
pl$select(pl$repeat_(3, n = 3, dtype = pl$Int8))
#> shape: (3, 1)
#> ┌────────┐
#> │ repeat │
#> │ ---    │
#> │ i8     │
#> ╞════════╡
#> │ 3      │
#> │ 3      │
#> │ 3      │
#> └────────┘