Skip to content

Perform a join based on one or multiple (in)equality predicates

Source code

Description

[Experimental]

By default, this performs an inner join, so only rows where all predicates are true are included in the result, and a row from either DataFrame may be included multiple times in the result.

Note that the row order of the input DataFrames is not preserved.

Usage

<DataFrame>$join_where(
  other,
  ...,
  how = c("inner", "left", "right"),
  suffix = "_right"
)

Arguments

other DataFrame to join with.
\<dynamic-dots\> (In)Equality condition to join the two tables on. When a column name occurs in both tables, the proper suffix must be applied in the predicate. For example, if both tables have a column “x” that you want to use in the conditions, you must refer to the column of the right table as “x\.
how Join strategy, one of “inner” (default), “left” or “right”.
suffix Suffix to append to columns with a duplicate name.

Value

A polars DataFrame

Examples

library("polars")

east <- pl$DataFrame(
  id = c(100, 101, 102),
  dur = c(120, 140, 160),
  rev = c(12, 14, 16),
  cores = c(2, 8, 4)
)

west <- pl$DataFrame(
  t_id = c(404, 498, 676, 742),
  time = c(90, 130, 150, 170),
  cost = c(9, 13, 15, 16),
  cores = c(4, 2, 1, 4)
)

east$join_where(
  west,
  pl$col("dur") < pl$col("time"),
  pl$col("rev") < pl$col("cost")
)
#> shape: (5, 8)
#> ┌───────┬───────┬──────┬───────┬───────┬───────┬──────┬─────────────┐
#> │ id    ┆ dur   ┆ rev  ┆ cores ┆ t_id  ┆ time  ┆ cost ┆ cores_right │
#> │ ---   ┆ ---   ┆ ---  ┆ ---   ┆ ---   ┆ ---   ┆ ---  ┆ ---         │
#> │ f64   ┆ f64   ┆ f64  ┆ f64   ┆ f64   ┆ f64   ┆ f64  ┆ f64         │
#> ╞═══════╪═══════╪══════╪═══════╪═══════╪═══════╪══════╪═════════════╡
#> │ 100.0 ┆ 120.0 ┆ 12.0 ┆ 2.0   ┆ 498.0 ┆ 130.0 ┆ 13.0 ┆ 2.0         │
#> │ 100.0 ┆ 120.0 ┆ 12.0 ┆ 2.0   ┆ 676.0 ┆ 150.0 ┆ 15.0 ┆ 1.0         │
#> │ 100.0 ┆ 120.0 ┆ 12.0 ┆ 2.0   ┆ 742.0 ┆ 170.0 ┆ 16.0 ┆ 4.0         │
#> │ 101.0 ┆ 140.0 ┆ 14.0 ┆ 8.0   ┆ 676.0 ┆ 150.0 ┆ 15.0 ┆ 1.0         │
#> │ 101.0 ┆ 140.0 ┆ 14.0 ┆ 8.0   ┆ 742.0 ┆ 170.0 ┆ 16.0 ┆ 4.0         │
#> └───────┴───────┴──────┴───────┴───────┴───────┴──────┴─────────────┘