wide data with part of column name as value

22 Views Asked by At

I have the following data structure in R

  DE_GDP DE_INFL US_GDP US_INFL
1      1       1      1       1
2      2       2      2       2
3      3       3      3       3
4      4       4      4       4

and I want to reshape it to this structure:

  GDP INFL COUNTRY
1   1    1      DE
2   2    2      DE
3   3    3      DE
4   4    4      DE
5   1    1      US
6   2    2      US
7   3    3      US
8   4    4      US

How is this possible?

0

There are 0 best solutions below