Skip to content

Take every nth row in the DataFrame

Source code

Description

Take every nth row in the DataFrame

Usage

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

Arguments

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

Value

A DataFrame

Examples

library("polars")

df = pl$DataFrame(a = 1:4, b = 5:8)
df$gather_every(2)
#> shape: (2, 2)
#> ┌─────┬─────┐
#> │ a   ┆ b   │
#> │ --- ┆ --- │
#> │ i32 ┆ i32 │
#> ╞═════╪═════╡
#> │ 1   ┆ 5   │
#> │ 3   ┆ 7   │
#> └─────┴─────┘
df$gather_every(2, offset = 1)
#> shape: (2, 2)
#> ┌─────┬─────┐
#> │ a   ┆ b   │
#> │ --- ┆ --- │
#> │ i32 ┆ i32 │
#> ╞═════╪═════╡
#> │ 2   ┆ 6   │
#> │ 4   ┆ 8   │
#> └─────┴─────┘