Pivotlongercols
Pivotlongercols is an informal term used in data tidying to describe the set of column names chosen for a pivot_longer operation. It is not a standalone function in the tidyr package; rather, it refers to the collection of columns supplied to the cols argument of pivot_longer. In practice, pivotlongercols are selected with tidyselect helpers such as starts_with, ends_with, contains, matches, or with a direct vector of column names.
The concept helps document and discuss which wide-format columns are being transformed into a long format.
Pivot_longer in tidyr is invoked with a cols parameter that determines which columns to pivot. Examples of
- cols = starts_with("score_")
- cols = contains("measurement")
Suppose a data frame has columns like A_2018, A_2019, B_2018, B_2019. A typical long format transformation would
pivot_longer(df, cols = matches("^(A|B)_"), names_to = c("group", "year"), names_sep = "_", values_to = "value")
Here, the pivotlongercols are the columns matched by the selector, gathered into two new keys.
Pivotlongercols is distinct from a built-in function; it is a descriptive label for the columns selected