Skip to content

Find local minima

Source code

Description

A local minimum is the point that marks the transition between a decrease and an increase in a Series. The first and last values of the Series can never be a peak.

Usage

<Expr>$peak_min()

Value

Expr

See Also

$peak_max()

Examples

library(polars)

df = pl$DataFrame(x = c(1, 2, 3, 2, 3, 4, 5, 2))
df
#> shape: (8, 1)
#> ┌─────┐
#> │ x   │
#> │ --- │
#> │ f64 │
#> ╞═════╡
#> │ 1.0 │
#> │ 2.0 │
#> │ 3.0 │
#> │ 2.0 │
#> │ 3.0 │
#> │ 4.0 │
#> │ 5.0 │
#> │ 2.0 │
#> └─────┘
df$with_columns(peak_min = pl$col("x")$peak_min())
#> shape: (8, 2)
#> ┌─────┬──────────┐
#> │ x   ┆ peak_min │
#> │ --- ┆ ---      │
#> │ f64 ┆ bool     │
#> ╞═════╪══════════╡
#> │ 1.0 ┆ false    │
#> │ 2.0 ┆ false    │
#> │ 3.0 ┆ false    │
#> │ 2.0 ┆ true     │
#> │ 3.0 ┆ false    │
#> │ 4.0 ┆ false    │
#> │ 5.0 ┆ false    │
#> │ 2.0 ┆ false    │
#> └─────┴──────────┘