Select all array columns
Description
Usage
cs__array(inner = NULL, ..., width = NULL)
Arguments
inner
|
An optional inner selector to select columns having specific inner data
types. If NULL , all inner types are selected.
|
…
|
These dots are for future extensions and must be empty. |
width
|
An optional integer specifying the width of the array columns to select.
If NULL , all widths are selected.
|
Value
A Polars selector
See Also
- cs for the documentation on operators supported by selectors.
-
cs$by_dtype()
: Select all columns matching the given dtype(s). -
cs$list()
: Select all list columns. -
cs$nested()
: Select all nested columns.
Examples
library("polars")
df <- pl$DataFrame(
foo = list(c("xx", "yy"), c("x", "y")),
bar = list(123, 456),
baz = c(2.0, 5.5),
.schema_overrides = list(
foo = pl$Array(pl$String, 2),
bar = pl$Array(pl$Int64, 1)
)
)
# Select all array columns:
df$select(cs$array())
#> shape: (2, 2)
#> ┌───────────────┬───────────────┐
#> │ foo ┆ bar │
#> │ --- ┆ --- │
#> │ array[str, 2] ┆ array[i64, 1] │
#> ╞═══════════════╪═══════════════╡
#> │ ["xx", "yy"] ┆ [123] │
#> │ ["x", "y"] ┆ [456] │
#> └───────────────┴───────────────┘
#> shape: (2, 1)
#> ┌─────┐
#> │ baz │
#> │ --- │
#> │ f64 │
#> ╞═════╡
#> │ 2.0 │
#> │ 5.5 │
#> └─────┘
# If you want to select specific array columns,
# you can specify the inner data type and/or width:
df$select(cs$array(cs$string()))
#> shape: (2, 1)
#> ┌───────────────┐
#> │ foo │
#> │ --- │
#> │ array[str, 2] │
#> ╞═══════════════╡
#> │ ["xx", "yy"] │
#> │ ["x", "y"] │
#> └───────────────┘
#> shape: (2, 1)
#> ┌───────────────┐
#> │ bar │
#> │ --- │
#> │ array[i64, 1] │
#> ╞═══════════════╡
#> │ [123] │
#> │ [456] │
#> └───────────────┘
#> shape: (2, 1)
#> ┌───────────────┐
#> │ foo │
#> │ --- │
#> │ array[str, 2] │
#> ╞═══════════════╡
#> │ ["xx", "yy"] │
#> │ ["x", "y"] │
#> └───────────────┘