I'm trying to melt a dataframe
Year | Baseline_low | Baseline_high | Overall_low | Overall_high
================================================================
2022 | 1 | 2 | 3 | 4
2023 | 5 | 6 | 7 | 8
to this:
2022 | Baseline | low | 1
2022 | Baseline | high | 2
There are a lot more columns that end with _low
or _high
than I've listed so I would like to use a pattern to split the column.
Is it possible to do this with melt?
I've seen this similar question but it has a slightly different structure to my dataframe.