Skip to content

Take every n-th value in the Series and return as a new Series

Description

Take every n-th value in the Series and return as a new Series

Usage

<Expr>$gather_every(n, offset = 0)

Arguments

n Gather every n-th row.
offset Starting index.

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(foo = 1:9)
df$select(pl$col("foo")$gather_every(3))
#> shape: (3, 1)
#> ┌─────┐
#> │ foo │
#> │ --- │
#> │ i32 │
#> ╞═════╡
#> │ 1   │
#> │ 4   │
#> │ 7   │
#> └─────┘
df$select(pl$col("foo")$gather_every(3, offset = 1))
#> shape: (3, 1)
#> ┌─────┐
#> │ foo │
#> │ --- │
#> │ i32 │
#> ╞═════╡
#> │ 2   │
#> │ 5   │
#> │ 8   │
#> └─────┘