Select and modify columns of a DataFrame
Description
Select and perform operations on a subset of columns only. This discards
unmentioned columns (like .()
in data.table
and contrarily to dplyr::mutate()
).
One cannot use new variables in subsequent expressions in the same
$select()
call. For instance, if
you create a variable x
, you will only be able to use it in
another $select()
or
$with_columns()
call.
Usage
<DataFrame>$select(...)
Arguments
…
|
\<dynamic-dots \> Name-value pairs of objects to be
converted to polars expressions by the as_polars_expr()
function. Characters are parsed as column names, other non-expression
inputs are parsed as literals. Each name will be used as the expression
name.
|
Value
A polars DataFrame
Examples
library("polars")
as_polars_df(iris)$select(
abs_SL = pl$col("Sepal.Length")$abs(),
add_2_SL = pl$col("Sepal.Length") + 2
)
#> shape: (150, 2)
#> ┌────────┬──────────┐
#> │ abs_SL ┆ add_2_SL │
#> │ --- ┆ --- │
#> │ f64 ┆ f64 │
#> ╞════════╪══════════╡
#> │ 5.1 ┆ 7.1 │
#> │ 4.9 ┆ 6.9 │
#> │ 4.7 ┆ 6.7 │
#> │ 4.6 ┆ 6.6 │
#> │ 5.0 ┆ 7.0 │
#> │ … ┆ … │
#> │ 6.7 ┆ 8.7 │
#> │ 6.3 ┆ 8.3 │
#> │ 6.5 ┆ 8.5 │
#> │ 6.2 ┆ 8.2 │
#> │ 5.9 ┆ 7.9 │
#> └────────┴──────────┘