Skip to content

Remove columns

Source code

Description

Remove columns

Usage

<LazyFrame>$drop(..., strict = TRUE)

Arguments

\<dynamic-dots\> Column names or selectors that should be removed.
strict Validate that all column names exist in the current schema, and throw an exception if any do not.

Value

A polars LazyFrame

Examples

library("polars")

# Drop columns by passing the name of those columns
lf <- pl$LazyFrame(
  foo = 1:3,
  bar = c(6, 7, 8),
  ham = c("a", "b", "c")
)
lf$drop("ham")$collect()
#> shape: (3, 2)
#> ┌─────┬─────┐
#> │ foo ┆ bar │
#> │ --- ┆ --- │
#> │ i32 ┆ f64 │
#> ╞═════╪═════╡
#> │ 1   ┆ 6.0 │
#> │ 2   ┆ 7.0 │
#> │ 3   ┆ 8.0 │
#> └─────┴─────┘
lf$drop("ham", "bar")$collect()
#> shape: (3, 1)
#> ┌─────┐
#> │ foo │
#> │ --- │
#> │ i32 │
#> ╞═════╡
#> │ 1   │
#> │ 2   │
#> │ 3   │
#> └─────┘
# Drop multiple columns by passing a selector
lf$drop(cs$all())$collect()
#> shape: (0, 0)
#> ┌┐
#> ╞╡
#> └┘