Skip to content

Add a prefix to a column name

Source code

Description

Add a prefix to a column name

Usage

<Expr>$name$prefix(prefix)

Arguments

prefix Prefix to be added to column name(s)

Value

Expr

See Also

$suffix() to add a suffix

Examples

library(polars)

dat = pl$DataFrame(mtcars)

dat$select(
  pl$col("mpg"),
  pl$col("mpg")$name$prefix("name_"),
  pl$col("cyl", "drat")$name$prefix("bar_")
)
#> shape: (32, 4)
#> ┌──────┬──────────┬─────────┬──────────┐
#> │ mpg  ┆ name_mpg ┆ bar_cyl ┆ bar_drat │
#> │ ---  ┆ ---      ┆ ---     ┆ ---      │
#> │ f64  ┆ f64      ┆ f64     ┆ f64      │
#> ╞══════╪══════════╪═════════╪══════════╡
#> │ 21.0 ┆ 21.0     ┆ 6.0     ┆ 3.9      │
#> │ 21.0 ┆ 21.0     ┆ 6.0     ┆ 3.9      │
#> │ 22.8 ┆ 22.8     ┆ 4.0     ┆ 3.85     │
#> │ 21.4 ┆ 21.4     ┆ 6.0     ┆ 3.08     │
#> │ 18.7 ┆ 18.7     ┆ 8.0     ┆ 3.15     │
#> │ …    ┆ …        ┆ …       ┆ …        │
#> │ 30.4 ┆ 30.4     ┆ 4.0     ┆ 3.77     │
#> │ 15.8 ┆ 15.8     ┆ 8.0     ┆ 4.22     │
#> │ 19.7 ┆ 19.7     ┆ 6.0     ┆ 3.62     │
#> │ 15.0 ┆ 15.0     ┆ 8.0     ┆ 3.54     │
#> │ 21.4 ┆ 21.4     ┆ 4.0     ┆ 4.11     │
#> └──────┴──────────┴─────────┴──────────┘