Skip to content

Floor divide using two expressions

Description

Method equivalent of floor division operator expr %/% other. $floordiv() is an alias for $floor_div(), which exists for compatibility with Python Polars.

Usage

<Expr>$floor_div(other)

expr__floordiv(other)

Arguments

other Numeric literal or expression value.

Value

A polars expression

See Also

  • Arithmetic operators
  • \$true_div()
  • \$mod()

Examples

library("polars")

df <- pl$DataFrame(x = 1:5)

df$with_columns(
  `x/2` = pl$col("x")$true_div(2),
  `x%/%2` = pl$col("x")$floor_div(2)
)
#> shape: (5, 3)
#> ┌─────┬─────┬───────┐
#> │ x   ┆ x/2 ┆ x%/%2 │
#> │ --- ┆ --- ┆ ---   │
#> │ i32 ┆ f64 ┆ f64   │
#> ╞═════╪═════╪═══════╡
#> │ 1   ┆ 0.5 ┆ 0.0   │
#> │ 2   ┆ 1.0 ┆ 1.0   │
#> │ 3   ┆ 1.5 ┆ 1.0   │
#> │ 4   ┆ 2.0 ┆ 2.0   │
#> │ 5   ┆ 2.5 ┆ 2.0   │
#> └─────┴─────┴───────┘