Get the first value.
Description
This function has different behavior depending on arguments:
- Missing -\> Takes first column of a context.
-
Character vectors -\> Syntactic sugar for
pl$col(…)$first()
.
Usage
pl$first(...)
Arguments
…
|
Characters indicating the column names (passed to pl$col() ,
see ?pl_col for details), or empty. If empty (default),
returns an expression to take the first column of the context instead.
|
Value
Expr
See Also
-
\
$first()
Examples
library("polars")
df = pl$DataFrame(
a = c(1, 8, 3),
b = c(4, 5, 2),
c = c("foo", "bar", "foo")
)
df$select(pl$first())
#> shape: (3, 1)
#> ┌─────┐
#> │ a │
#> │ --- │
#> │ f64 │
#> ╞═════╡
#> │ 1.0 │
#> │ 8.0 │
#> │ 3.0 │
#> └─────┘
#> shape: (1, 1)
#> ┌─────┐
#> │ b │
#> │ --- │
#> │ f64 │
#> ╞═════╡
#> │ 4.0 │
#> └─────┘
#> shape: (1, 2)
#> ┌─────┬─────┐
#> │ a ┆ c │
#> │ --- ┆ --- │
#> │ f64 ┆ str │
#> ╞═════╪═════╡
#> │ 1.0 ┆ foo │
#> └─────┴─────┘