Convert the series of type List to a series of type Struct
Description
Convert the series of type List to a series of type Struct
Usage
series_list_to_struct(
n_field_strategy = c("first_non_null", "max_width"),
fields = NULL
)
Arguments
Value
A polars Series
Examples
library("polars")
# Convert list to struct with default field name assignment:
s1 <- as_polars_series(list(0:2, 0:1))
s2 <- s1$list$to_struct()
s2
#> shape: (2, 1)
#> ┌────────────┐
#> │ │
#> │ --- │
#> │ struct[3] │
#> ╞════════════╡
#> │ {0,1,2} │
#> │ {0,1,null} │
#> └────────────┘
#> [1] "field_0" "field_1" "field_2"
# Convert list to struct with field name assignment by
# index from a list of names:
s1$list$to_struct(fields = c("one", "two", "three"))$struct$unnest()
#> shape: (2, 3)
#> ┌─────┬─────┬───────┐
#> │ one ┆ two ┆ three │
#> │ --- ┆ --- ┆ --- │
#> │ i32 ┆ i32 ┆ i32 │
#> ╞═════╪═════╪═══════╡
#> │ 0 ┆ 1 ┆ 2 │
#> │ 0 ┆ 1 ┆ null │
#> └─────┴─────┴───────┘