pivot-longer
Melt several columns into a single name/value column pair (wide to long).
NoteExperimental
This function is experimental; its interface may change without notice.
Since 0.6.0.
cols (a column name or an array of names) are the columns to melt; every other column is kept as an identifier. Each input row becomes one output row per melted column: the kept columns, then names-to holding the melted column’s name, then values-to holding its cell value.
Usage
pivot-longer(
data,
cols,
names-to: "name",
values-to: "value",
)Parameters
| Parameter | Default | Description |
|---|---|---|
data |
Row-store (array of dicts) or column-store (dict of arrays). | |
cols |
Columns to melt, as a string or an array of strings. | |
names-to |
"name" |
Name of the output column holding the melted column names. |
values-to |
"value" |
Name of the output column holding the melted cell values. |
Returns
A long row-store array.
Examples
Melt city and highway economy into one measurement column.
#let long = pivot-longer(mpg, ("cty", "hwy"), names-to: "metric", values-to: "mpg")