How do I unpivot data?

If you have a number of columns with values in them, and you want to create separate observations, each with a name and a value, you can do this with flatten_single(). This is especially helpful when shaping a metrics dataset.

Collect all the values into an object, and then flatten that object. Then rename the output columns the way you want them.

You can also look at the unpivot_array() function which takes an object into an array of key/value pairs.