Reshape this Expr to a flat Series or a Series of Lists
Description
Reshape this Expr to a flat Series or a Series of Lists
Usage
<Expr>$reshape(dimensions)
Arguments
dimensions
|
A integer vector of length of the dimension size. If -1 is
used in any of the dimensions, that dimension is inferred.
|
Details
If a single dimension is given, results in an expression of the original data type. If a multiple dimensions are given, results in an expression of data type List with shape equal to the dimensions.
Value
A polars expression
Examples
#> shape: (9, 1)
#> ┌─────┐
#> │ foo │
#> │ --- │
#> │ i32 │
#> ╞═════╡
#> │ 1 │
#> │ 2 │
#> │ 3 │
#> │ 4 │
#> │ 5 │
#> │ 6 │
#> │ 7 │
#> │ 8 │
#> │ 9 │
#> └─────┘
#> shape: (3, 1)
#> ┌───────────────┐
#> │ foo │
#> │ --- │
#> │ array[i32, 3] │
#> ╞═══════════════╡
#> │ [1, 2, 3] │
#> │ [4, 5, 6] │
#> │ [7, 8, 9] │
#> └───────────────┘
#> shape: (3, 1)
#> ┌───────────────┐
#> │ foo │
#> │ --- │
#> │ array[i32, 3] │
#> ╞═══════════════╡
#> │ [1, 2, 3] │
#> │ [4, 5, 6] │
#> │ [7, 8, 9] │
#> └───────────────┘
#> shape: (3, 1)
#> ┌───────────────┐
#> │ foo │
#> │ --- │
#> │ array[i32, 3] │
#> ╞═══════════════╡
#> │ [1, 2, 3] │
#> │ [4, 5, 6] │
#> │ [7, 8, 9] │
#> └───────────────┘
# We can have more than 2 dimensions
df <- pl$DataFrame(foo = 1:8)
df$select(pl$col("foo")$reshape(c(2, 2, 2)))
#> shape: (2, 1)
#> ┌────────────────────┐
#> │ foo │
#> │ --- │
#> │ array[i32, (2, 2)] │
#> ╞════════════════════╡
#> │ [[1, 2], [3, 4]] │
#> │ [[5, 6], [7, 8]] │
#> └────────────────────┘