Suppose I have a dataframe with the following structure:
|id | segment1 | segment 2|
|----|----------|----------|
|1 | 1 | 0 |
|2 | 1 | 0 |
|3 | 0 | 1 |
|4 | 1 | 0 |
|5 | 0 | 1 |
How do I pivot the data such that, instead of having the 2 "segment" columns, I just have 1 column that says "segment1" or "segment2"? I was thinking about pivot_longer but I don't think we're actually making the data frame any longer. It seems like there is definitely a quicker way than using mutate with an if_else or creating a new column and manually assigning the values.
Note: This transformation should not yield a longer dataframe though, as we're just collapsing columns