Skip to content

Remove columns

Source code

Description

Remove columns

Usage

<DataFrame>$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 DataFrame

Examples

library("polars")

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