Select all columns with alphanumeric names (e.g. only letters and the digits 0-9)
Description
Select all columns with alphanumeric names (e.g. only letters and the digits 0-9)
Usage
cs__alphanumeric(ascii_only = FALSE, ..., ignore_spaces = FALSE)
Arguments
ascii_only
|
Indicate whether to consider only ASCII alphabetic characters, or the full Unicode range of valid letters (accented, idiographic, etc). |
…
|
These dots are for future extensions and must be empty. |
ignore_spaces
|
Indicate whether to ignore the presence of spaces in column names; if so, only the other (non-space) characters are considered. |
Details
Matching column names cannot contain any non-alphabetic characters. Note
that the definition of “alphabetic” consists of all valid Unicode
alphabetic characters
(p{Alphabetic}
) and digit
characters (d
) by default; this can be changed by setting
ascii_only = TRUE
.
Value
A Polars selector
See Also
cs for the documentation on operators supported by Polars selectors.
Examples
library("polars")
df <- pl$DataFrame(
`1st_col` = c(100, 200, 300),
flagged = c(TRUE, FALSE, TRUE),
`00prefix` = c("01:aa", "02:bb", "03:cc"),
`last col` = c("x", "y", "z")
)
# Select columns with alphanumeric names:
df$select(cs$alphanumeric())
#> shape: (3, 2)
#> ┌─────────┬──────────┐
#> │ flagged ┆ 00prefix │
#> │ --- ┆ --- │
#> │ bool ┆ str │
#> ╞═════════╪══════════╡
#> │ true ┆ 01:aa │
#> │ false ┆ 02:bb │
#> │ true ┆ 03:cc │
#> └─────────┴──────────┘
#> shape: (3, 3)
#> ┌─────────┬──────────┬──────────┐
#> │ flagged ┆ 00prefix ┆ last col │
#> │ --- ┆ --- ┆ --- │
#> │ bool ┆ str ┆ str │
#> ╞═════════╪══════════╪══════════╡
#> │ true ┆ 01:aa ┆ x │
#> │ false ┆ 02:bb ┆ y │
#> │ true ┆ 03:cc ┆ z │
#> └─────────┴──────────┴──────────┘
#> shape: (3, 2)
#> ┌─────────┬──────────┐
#> │ 1st_col ┆ last col │
#> │ --- ┆ --- │
#> │ f64 ┆ str │
#> ╞═════════╪══════════╡
#> │ 100.0 ┆ x │
#> │ 200.0 ┆ y │
#> │ 300.0 ┆ z │
#> └─────────┴──────────┘
#> shape: (3, 1)
#> ┌─────────┐
#> │ 1st_col │
#> │ --- │
#> │ f64 │
#> ╞═════════╡
#> │ 100.0 │
#> │ 200.0 │
#> │ 300.0 │
#> └─────────┘