rename fields
Description
Rename the fields of the struct. By default base 2.
Usage
<Expr>$struct$rename_fields(names)
Arguments
names
|
char vec or list of strings given in the same order as the struct’s fields. Providing fewer names will drop the latter fields. Providing too many names is ignored. |
Value
Expr: struct-series with new names for the fields
Examples
library(polars)
df = pl$DataFrame(
aaa = 1:2,
bbb = c("ab", "cd"),
ccc = c(TRUE, NA),
ddd = list(1:2, 3L)
)$select(
pl$struct(pl$all())$alias("struct_col")
)$select(
pl$col("struct_col")$struct$rename_fields(c("www", "xxx", "yyy", "zzz"))
)
df$unnest()
#> shape: (2, 4)
#> ┌─────┬─────┬──────┬───────────┐
#> │ www ┆ xxx ┆ yyy ┆ zzz │
#> │ --- ┆ --- ┆ --- ┆ --- │
#> │ i32 ┆ str ┆ bool ┆ list[i32] │
#> ╞═════╪═════╪══════╪═══════════╡
#> │ 1 ┆ ab ┆ true ┆ [1, 2] │
#> │ 2 ┆ cd ┆ null ┆ [3] │
#> └─────┴─────┴──────┴───────────┘