Skip to content

Select and modify columns of a LazyFrame

Source code

Description

Similar to dplyr::mutate(). However, it discards unmentioned columns (like .() in data.table).

Usage

<LazyFrame>$select(...)

Arguments

Columns to keep. Those can be expressions (e.g pl$col(“a”)), column names (e.g “a”), or list containing expressions or column names (e.g list(pl$col(“a”))).

Value

A LazyFrame

Examples

library(polars)

pl$LazyFrame(iris)$select(
  pl$col("Sepal.Length")$abs()$alias("abs_SL"),
  (pl$col("Sepal.Length") + 2)$alias("add_2_SL")
)
#> polars LazyFrame
#>  $describe_optimized_plan() : Show the optimized query plan.
#> 
#> Naive plan:
#>  SELECT [col("Sepal.Length").abs().alias("abs_SL"), [(col("Sepal.Length")) + (2.0)].alias("add_2_SL")] FROM
#>   DF ["Sepal.Length", "Sepal.Width", "Petal.Length", "Petal.Width"]; PROJECT */5 COLUMNS; SELECTION: "None"