Skip to content

Create an empty or n-row null-filled copy of the DataFrame

Source code

Description

Returns a n-row null-filled DataFrame with an identical schema. n can be greater than the current number of rows in the DataFrame.

Usage

<DataFrame>$clear(n = 0)

Arguments

n Number of (null-filled) rows to return in the cleared frame.

Value

A n-row null-filled DataFrame with an identical schema

Examples

library(polars)

df = pl$DataFrame(
  a = c(NA, 2, 3, 4),
  b = c(0.5, NA, 2.5, 13),
  c = c(TRUE, TRUE, FALSE, NA)
)

df$clear()
#> shape: (0, 3)
#> ┌─────┬─────┬──────┐
#> │ a   ┆ b   ┆ c    │
#> │ --- ┆ --- ┆ ---  │
#> │ f64 ┆ f64 ┆ bool │
#> ╞═════╪═════╪══════╡
#> └─────┴─────┴──────┘
df$clear(n = 5)
#> shape: (5, 3)
#> ┌──────┬──────┬──────┐
#> │ a    ┆ b    ┆ c    │
#> │ ---  ┆ ---  ┆ ---  │
#> │ f64  ┆ f64  ┆ bool │
#> ╞══════╪══════╪══════╡
#> │ null ┆ null ┆ null │
#> │ null ┆ null ┆ null │
#> │ null ┆ null ┆ null │
#> │ null ┆ null ┆ null │
#> │ null ┆ null ┆ null │
#> └──────┴──────┴──────┘