Skip to content

Clip elements above maximum value

Source code

Description

Replace all values above a maximum value by this maximum value.

Usage

<Expr>$clip_max(max)

Arguments

max Maximum value, Expr returning a numeric.

Examples

library(polars)

pl$DataFrame(foo = c(-50L, 5L, NA_integer_, 50L))$
  with_columns(clipped = pl$col("foo")$clip_max(10))
#> shape: (4, 2)
#> ┌──────┬─────────┐
#> │ foo  ┆ clipped │
#> │ ---  ┆ ---     │
#> │ i32  ┆ i32     │
#> ╞══════╪═════════╡
#> │ -50  ┆ -50     │
#> │ 5    ┆ 5       │
#> │ null ┆ null    │
#> │ 50   ┆ 10      │
#> └──────┴─────────┘