Select columns whose names contain the given literal substring(s)
Description
Select columns whose names contain the given literal substring(s)
Usage
cs__contains(...)
Arguments
…
|
\<dynamic-dots \> Substring(s) that matching column names
should contain.
|
Value
A Polars selector
See Also
cs for the documentation on operators supported by Polars selectors.
Examples
library("polars")
df <- pl$DataFrame(
foo = c("x", "y"),
bar = c(123, 456),
baz = c(2.0, 5.5),
zap = c(FALSE, TRUE)
)
# Select columns that contain the substring "ba":
df$select(cs$contains("ba"))
#> shape: (2, 2)
#> ┌───────┬─────┐
#> │ bar ┆ baz │
#> │ --- ┆ --- │
#> │ f64 ┆ f64 │
#> ╞═══════╪═════╡
#> │ 123.0 ┆ 2.0 │
#> │ 456.0 ┆ 5.5 │
#> └───────┴─────┘
# Select columns that contain the substring "ba" or the letter "z":
df$select(cs$contains("ba", "z"))
#> shape: (2, 3)
#> ┌───────┬─────┬───────┐
#> │ bar ┆ baz ┆ zap │
#> │ --- ┆ --- ┆ --- │
#> │ f64 ┆ f64 ┆ bool │
#> ╞═══════╪═════╪═══════╡
#> │ 123.0 ┆ 2.0 ┆ false │
#> │ 456.0 ┆ 5.5 ┆ true │
#> └───────┴─────┴───────┘
# Select all columns except for those that contain the substring "ba":
df$select(!cs$contains("ba"))
#> shape: (2, 2)
#> ┌─────┬───────┐
#> │ foo ┆ zap │
#> │ --- ┆ --- │
#> │ str ┆ bool │
#> ╞═════╪═══════╡
#> │ x ┆ false │
#> │ y ┆ true │
#> └─────┴───────┘