Skip to content

Reverse values in every sub-array

Description

Reverse values in every sub-array

Usage

<Expr>$arr$reverse()

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(
  values = list(c(1, 2), c(3, 4), c(NA, 6))
)$cast(pl$Array(pl$Float64, 2))
df$with_columns(reverse = pl$col("values")$arr$reverse())
#> shape: (3, 2)
#> ┌───────────────┬───────────────┐
#> │ values        ┆ reverse       │
#> │ ---           ┆ ---           │
#> │ array[f64, 2] ┆ array[f64, 2] │
#> ╞═══════════════╪═══════════════╡
#> │ [1.0, 2.0]    ┆ [2.0, 1.0]    │
#> │ [3.0, 4.0]    ┆ [4.0, 3.0]    │
#> │ [null, 6.0]   ┆ [6.0, null]   │
#> └───────────────┴───────────────┘