Select columns that end with the given substring(s)
Description
Select columns that end with the given substring(s)
Usage
cs__ends_with(...)
Arguments
…
|
\<dynamic-dots \> Substring(s) that matching column names
should end with.
|
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 end with the substring "z":
df$select(cs$ends_with("z"))
#> shape: (2, 1)
#> ┌─────┐
#> │ baz │
#> │ --- │
#> │ f64 │
#> ╞═════╡
#> │ 2.0 │
#> │ 5.5 │
#> └─────┘
#> shape: (2, 2)
#> ┌───────┬─────┐
#> │ bar ┆ baz │
#> │ --- ┆ --- │
#> │ f64 ┆ f64 │
#> ╞═══════╪═════╡
#> │ 123.0 ┆ 2.0 │
#> │ 456.0 ┆ 5.5 │
#> └───────┴─────┘
# Select all columns except for those that end with the substring "z":
df$select(!cs$ends_with("z"))
#> shape: (2, 3)
#> ┌─────┬───────┬───────┐
#> │ foo ┆ bar ┆ zap │
#> │ --- ┆ --- ┆ --- │
#> │ str ┆ f64 ┆ bool │
#> ╞═════╪═══════╪═══════╡
#> │ x ┆ 123.0 ┆ false │
#> │ y ┆ 456.0 ┆ true │
#> └─────┴───────┴───────┘