Skip to contents

Append multiple Data/LazyFrames next to each other

Usage

bind_cols_polars(..., .name_repair = "unique")

Arguments

...

Polars DataFrames or LazyFrames to combine. Each argument can either be a Data/LazyFrame, or a list of Data/LazyFrames. Columns are matched by name. All Data/LazyFrames must have the same number of rows and there mustn't be duplicated column names.

.name_repair

Can be "unique", "universal", "check_unique", "minimal". See vctrs::vec_as_names() for the explanations for each value.

Examples

p1 <- polars::pl$DataFrame(
  x = sample(letters, 20),
  y = sample(1:100, 20)
)
p2 <- polars::pl$DataFrame(
  z = sample(letters, 20),
  w = sample(1:100, 20)
)

bind_cols_polars(p1, p2)
#> shape: (20, 4)
#> ┌─────┬─────┬─────┬─────┐
#> │ x   ┆ y   ┆ z   ┆ w   │
#> │ --- ┆ --- ┆ --- ┆ --- │
#> │ str ┆ i32 ┆ str ┆ i32 │
#> ╞═════╪═════╪═════╪═════╡
#> │ i   ┆ 32  ┆ h   ┆ 64  │
#> │ e   ┆ 53  ┆ a   ┆ 40  │
#> │ y   ┆ 70  ┆ l   ┆ 65  │
#> │ o   ┆ 9   ┆ s   ┆ 28  │
#> │ m   ┆ 22  ┆ p   ┆ 71  │
#> │ …   ┆ …   ┆ …   ┆ …   │
#> │ c   ┆ 51  ┆ v   ┆ 17  │
#> │ z   ┆ 46  ┆ u   ┆ 13  │
#> │ n   ┆ 65  ┆ q   ┆ 33  │
#> │ s   ┆ 25  ┆ m   ┆ 77  │
#> │ g   ┆ 37  ┆ w   ┆ 32  │
#> └─────┴─────┴─────┴─────┘
bind_cols_polars(list(p1, p2))
#> shape: (20, 4)
#> ┌─────┬─────┬─────┬─────┐
#> │ x   ┆ y   ┆ z   ┆ w   │
#> │ --- ┆ --- ┆ --- ┆ --- │
#> │ str ┆ i32 ┆ str ┆ i32 │
#> ╞═════╪═════╪═════╪═════╡
#> │ i   ┆ 32  ┆ h   ┆ 64  │
#> │ e   ┆ 53  ┆ a   ┆ 40  │
#> │ y   ┆ 70  ┆ l   ┆ 65  │
#> │ o   ┆ 9   ┆ s   ┆ 28  │
#> │ m   ┆ 22  ┆ p   ┆ 71  │
#> │ …   ┆ …   ┆ …   ┆ …   │
#> │ c   ┆ 51  ┆ v   ┆ 17  │
#> │ z   ┆ 46  ┆ u   ┆ 13  │
#> │ n   ┆ 65  ┆ q   ┆ 33  │
#> │ s   ┆ 25  ┆ m   ┆ 77  │
#> │ g   ┆ 37  ┆ w   ┆ 32  │
#> └─────┴─────┴─────┴─────┘