Compute the sign
Description
This returns -1 if x is lower than 0, 0 if x == 0, and 1 if x is greater than 0.
Usage
<Expr>$sign()
Value
A polars expression
Examples
library("polars")
df <- pl$DataFrame(a = c(-9, 0, 0, 4, NA))
df$with_columns(sign = pl$col("a")$sign())
#> shape: (5, 2)
#> ┌──────┬──────┐
#> │ a ┆ sign │
#> │ --- ┆ --- │
#> │ f64 ┆ f64 │
#> ╞══════╪══════╡
#> │ -9.0 ┆ -1.0 │
#> │ 0.0 ┆ 0.0 │
#> │ 0.0 ┆ 0.0 │
#> │ 4.0 ┆ 1.0 │
#> │ null ┆ null │
#> └──────┴──────┘