Skip to content

Negate a boolean expression

Description

Negate a boolean expression

Usage

<Expr>$not()

Value

A polars expression

Examples

library("polars")

df <- pl$DataFrame(a = c(TRUE, FALSE, FALSE, NA))

df$with_columns(a_not = pl$col("a")$not())
#> shape: (4, 2)
#> ┌───────┬───────┐
#> │ a     ┆ a_not │
#> │ ---   ┆ ---   │
#> │ bool  ┆ bool  │
#> ╞═══════╪═══════╡
#> │ true  ┆ false │
#> │ false ┆ true  │
#> │ false ┆ true  │
#> │ null  ┆ null  │
#> └───────┴───────┘
# Same result with "!"
df$with_columns(a_not = !pl$col("a"))
#> shape: (4, 2)
#> ┌───────┬───────┐
#> │ a     ┆ a_not │
#> │ ---   ┆ ---   │
#> │ bool  ┆ bool  │
#> ╞═══════╪═══════╡
#> │ true  ┆ false │
#> │ false ┆ true  │
#> │ false ┆ true  │
#> │ null  ┆ null  │
#> └───────┴───────┘