Alias for an element being evaluated in an eval expression
Description
Alias for an element being evaluated in an eval expression
Usage
pl$element()
Value
A polars expression
Examples
library("polars")
# A horizontal rank computation by taking the elements of a list:
df <- pl$DataFrame(
a = c(1, 8, 3),
b = c(4, 5, 2)
)
df$with_columns(
rank = pl$concat_list(c("a", "b"))$list$eval(pl$element()$rank())
)
#> shape: (3, 3)
#> ┌─────┬─────┬────────────┐
#> │ a ┆ b ┆ rank │
#> │ --- ┆ --- ┆ --- │
#> │ f64 ┆ f64 ┆ list[f64] │
#> ╞═════╪═════╪════════════╡
#> │ 1.0 ┆ 4.0 ┆ [1.0, 2.0] │
#> │ 8.0 ┆ 5.0 ┆ [2.0, 1.0] │
#> │ 3.0 ┆ 2.0 ┆ [2.0, 1.0] │
#> └─────┴─────┴────────────┘
# A mathematical operation on array elements:
df <- pl$DataFrame(
a = c(1, 8, 3),
b = c(4, 5, 2)
)
df$with_columns(
a_b_doubled = pl$concat_list(c("a", "b"))$list$eval(pl$element() * 2)
)
#> shape: (3, 3)
#> ┌─────┬─────┬──────────────┐
#> │ a ┆ b ┆ a_b_doubled │
#> │ --- ┆ --- ┆ --- │
#> │ f64 ┆ f64 ┆ list[f64] │
#> ╞═════╪═════╪══════════════╡
#> │ 1.0 ┆ 4.0 ┆ [2.0, 8.0] │
#> │ 8.0 ┆ 5.0 ┆ [16.0, 10.0] │
#> │ 3.0 ┆ 2.0 ┆ [6.0, 4.0] │
#> └─────┴─────┴──────────────┘