Join LazyFrames
Description
This function can do both mutating joins (adding columns based on
matching observations, for example with how = “left”
) and
filtering joins (keeping observations based on matching observations,
for example with how = “inner”
).
Usage
<LazyFrame>$join(
other,
on = NULL,
how = c("inner", "full", "left", "right", "semi", "anti", "cross"),
...,
left_on = NULL,
right_on = NULL,
suffix = "_right",
validate = c("m:m", "1:m", "m:1", "1:1"),
join_nulls = FALSE,
maintain_order = c("none", "left", "right", "left_right", "right_left"),
allow_parallel = TRUE,
force_parallel = FALSE,
coalesce = NULL
)
Arguments
other
|
LazyFrame to join with. |
on
|
Either a vector of column names or a list of expressions and/or strings.
Use left_on and right_on if the column names
to match on are different between the two LazyFrames.
|
how
|
One of the following methods:
|
…
|
These dots are for future extensions and must be empty. |
left_on , right_on
|
Same as on but only for the left or the right DataFrame.
They must have the same length.
|
suffix
|
Suffix to add to duplicated column names. |
validate
|
Checks if join is of specified type:
|
join_nulls
|
Join on null values. By default null values will never produce matches. |
maintain_order
|
Which frame row order to preserve, if any. Do not rely on any observed
ordering without explicitly setting this parameter, as your code may
break in a future release. Not specifying any ordering can improve
performance. Supported for inner, left, right and full joins.
|
allow_parallel
|
Allow the physical plan to optionally evaluate the computation of both LazyFrames up to the join in parallel. |
force_parallel
|
Force the physical plan to evaluate the computation of both LazyFrames up to the join in parallel. |
coalesce
|
Coalescing behavior (merging of join columns).
|
Value
A polars LazyFrame
Examples
library("polars")
lf <- pl$LazyFrame(
foo = 1:3,
bar = c(6, 7, 8),
ham = c("a", "b", "c")
)
other_lf <- pl$LazyFrame(
apple = c("x", "y", "z"),
ham = c("a", "b", "d")
)
lf$join(other_lf, on = "ham")$collect()
#> shape: (2, 4)
#> ┌─────┬─────┬─────┬───────┐
#> │ foo ┆ bar ┆ ham ┆ apple │
#> │ --- ┆ --- ┆ --- ┆ --- │
#> │ i32 ┆ f64 ┆ str ┆ str │
#> ╞═════╪═════╪═════╪═══════╡
#> │ 1 ┆ 6.0 ┆ a ┆ x │
#> │ 2 ┆ 7.0 ┆ b ┆ y │
#> └─────┴─────┴─────┴───────┘
#> shape: (4, 5)
#> ┌──────┬──────┬──────┬───────┬───────────┐
#> │ foo ┆ bar ┆ ham ┆ apple ┆ ham_right │
#> │ --- ┆ --- ┆ --- ┆ --- ┆ --- │
#> │ i32 ┆ f64 ┆ str ┆ str ┆ str │
#> ╞══════╪══════╪══════╪═══════╪═══════════╡
#> │ 1 ┆ 6.0 ┆ a ┆ x ┆ a │
#> │ 2 ┆ 7.0 ┆ b ┆ y ┆ b │
#> │ null ┆ null ┆ null ┆ z ┆ d │
#> │ 3 ┆ 8.0 ┆ c ┆ null ┆ null │
#> └──────┴──────┴──────┴───────┴───────────┘
#> shape: (3, 4)
#> ┌─────┬─────┬─────┬───────┐
#> │ foo ┆ bar ┆ ham ┆ apple │
#> │ --- ┆ --- ┆ --- ┆ --- │
#> │ i32 ┆ f64 ┆ str ┆ str │
#> ╞═════╪═════╪═════╪═══════╡
#> │ 1 ┆ 6.0 ┆ a ┆ x │
#> │ 2 ┆ 7.0 ┆ b ┆ y │
#> │ 3 ┆ 8.0 ┆ c ┆ null │
#> └─────┴─────┴─────┴───────┘
#> shape: (2, 3)
#> ┌─────┬─────┬─────┐
#> │ foo ┆ bar ┆ ham │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ f64 ┆ str │
#> ╞═════╪═════╪═════╡
#> │ 1 ┆ 6.0 ┆ a │
#> │ 2 ┆ 7.0 ┆ b │
#> └─────┴─────┴─────┘
#> shape: (1, 3)
#> ┌─────┬─────┬─────┐
#> │ foo ┆ bar ┆ ham │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ f64 ┆ str │
#> ╞═════╪═════╪═════╡
#> │ 3 ┆ 8.0 ┆ c │
#> └─────┴─────┴─────┘