Pivot API
#
pivotLongerLengthens data by increasing the number of rows (items) and decreasing the number of columns (keys) in a collection. The inverse transformation is pivotWider.
Note this functionality is similar to what is achieved with the tidyr function gather that has been superceded by pivot_longer.
#
Parametersoptions
#
cols
: The list of keys to pivot to the longer format. Takes the same style as in select::selectKeysnamesTo
: Map the keys in the input to these output columns. If multiple values are provided via an array, the keys will be split pernamesSep
.valuesTo
: Map the values in the input to these output columns. If multiple values are provided via an array, the keys will be split pernamesSep
expecting the name of the value output column as a prefix.
#
Usage#
pivotWiderWidens data by increasing the number of columns (keys) and decreasing the number of rows (items) in a collection. The inverse transformation is pivotLonger.
Note this functionality is similar to what is achieved with the tidyr function spread that has been superceded by pivot_wider.
#
Parametersoptions
#
namesFrom
: Used in combination withvaluesFrom
to get the name of the output key and the value respectively. IfvaluesFrom
contains multiple values, the value key will be prefixed to the output keys, usingnameSep
.valuesFill
: any values missing after widening will be filled with this value if specified. Ignored ifvaluesFillMap
is provided.valuesFillMap
: a map from pre-pivot keys to their default value when a value is not present in the widened item. See also replaceNully as a way to set defaults for keys after widening.