Skip to content

Select all boolean columns

Description

Select all boolean columns

Usage

cs__boolean()

Value

A Polars selector

See Also

cs for the documentation on operators supported by Polars selectors.

Examples

library("polars")

df <- pl$DataFrame(
  a = 1:4,
  b = c(FALSE, TRUE, FALSE, TRUE)
)

# Select and invert boolean columns:
df$with_columns(inverted = cs$boolean()$not())
#> shape: (4, 3)
#> ┌─────┬───────┬──────────┐
#> │ a   ┆ b     ┆ inverted │
#> │ --- ┆ ---   ┆ ---      │
#> │ i32 ┆ bool  ┆ bool     │
#> ╞═════╪═══════╪══════════╡
#> │ 1   ┆ false ┆ true     │
#> │ 2   ┆ true  ┆ false    │
#> │ 3   ┆ false ┆ true     │
#> │ 4   ┆ true  ┆ false    │
#> └─────┴───────┴──────────┘
# Select all columns except for those that are boolean:
df$select(!cs$boolean())
#> shape: (4, 1)
#> ┌─────┐
#> │ a   │
#> │ --- │
#> │ i32 │
#> ╞═════╡
#> │ 1   │
#> │ 2   │
#> │ 3   │
#> │ 4   │
#> └─────┘