Skip to content

Modulo two expressions

Source code

Description

Method equivalent of modulus operator expr %% other.

Usage

<Expr>$mod(other)

Arguments

other Numeric literal or expression value.

Value

Expr

See Also

  • Arithmetic operators
  • \$floor_div()

Examples

library("polars")

df = pl$DataFrame(x = -5L:5L)

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