Take two sorted DataFrames and merge them by the sorted key
Description
The output of this operation will also be sorted. It is the callers responsibility that the frames are sorted by that key, otherwise the output will not make sense. The schemas of both DataFrames must be equal.
Usage
<DataFrame>$merge_sorted(other, key, ..., maintain_order = FALSE)
Arguments
other
|
Other DataFrame that must be merged. |
key
|
Key that is sorted. |
…
|
These dots are for future extensions and must be empty. |
maintain_order
|
If TRUE, the output is guaranteed to have left-biased
ordering for equal keys: rows from the left frame appear before rows
from the right frame when their keys are equal.
|
Value
A polars DataFrame
Examples
library("polars")
df1 <- pl$DataFrame(
name = c("steve", "elise", "bob"),
age = c(42, 44, 18)
)$sort("age")
df2 <- pl$DataFrame(
name = c("anna", "megan", "steve", "thomas"),
age = c(21, 33, 42, 20)
)$sort("age")
df1$merge_sorted(df2, key = "age")
#> shape: (7, 2)
#> ┌────────┬──────┐
#> │ name ┆ age │
#> │ --- ┆ --- │
#> │ str ┆ f64 │
#> ╞════════╪══════╡
#> │ bob ┆ 18.0 │
#> │ thomas ┆ 20.0 │
#> │ anna ┆ 21.0 │
#> │ megan ┆ 33.0 │
#> │ steve ┆ 42.0 │
#> │ steve ┆ 42.0 │
#> │ elise ┆ 44.0 │
#> └────────┴──────┘