Skip to content

Repeat a Series

Source code

Description

This expression takes input and repeats it n times and append chunk.

Usage

<Expr>$rep(n, rechunk = TRUE)

Arguments

n The number of times to repeat, must be non-negative and finite.
rechunk If TRUE (default), memory layout will be rewritten.

Details

If the input has length 1, this uses a special faster implementation that doesn’t require rechunking (so rechunk = TRUE has no effect).

Value

Expr

Examples

library("polars")

pl$select(pl$lit("alice")$rep(n = 3))
#> shape: (3, 1)
#> ┌─────────┐
#> │ literal │
#> │ ---     │
#> │ str     │
#> ╞═════════╡
#> │ alice   │
#> │ alice   │
#> │ alice   │
#> └─────────┘
pl$select(pl$lit(1:3)$rep(n = 2))
#> shape: (6, 1)
#> ┌─────┐
#> │     │
#> │ --- │
#> │ i32 │
#> ╞═════╡
#> │ 1   │
#> │ 2   │
#> │ 3   │
#> │ 1   │
#> │ 2   │
#> │ 3   │
#> └─────┘