Skip to content

Clip elements

Source code

Description

Clip (limit) the values in an array to a min and max boundary. This only works for numerical types.

Usage

<Expr>$clip(min, max)

Arguments

min Minimum value, Expr returning a numeric.
max Maximum value, Expr returning a numeric.

Value

Expr

Examples

library(polars)

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