Skip to content

Take values by index

Source code

Description

Take values by index

Usage

<Expr>$gather(indices, ..., null_on_oob = FALSE)

Arguments

indices An expression that leads to a UInt32 dtyped Series.
These dots are for future extensions and must be empty.
null_on_oob If TRUE, return null if an index is out of bounds. Otherwise, raise an error.

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(
  group = c("one", "one", "one", "two", "two", "two"),
  value = c(1, 98, 2, 3, 99, 4)
)
df$group_by("group", .maintain_order = TRUE)$agg(
  pl$col("value")$gather(c(2, 1))
)
#> shape: (2, 2)
#> ┌───────┬─────────────┐
#> │ group ┆ value       │
#> │ ---   ┆ ---         │
#> │ str   ┆ list[f64]   │
#> ╞═══════╪═════════════╡
#> │ one   ┆ [2.0, 98.0] │
#> │ two   ┆ [4.0, 99.0] │
#> └───────┴─────────────┘