I have the following table:
country | country code | variable | 1990 | 1991 | 1992 | 1993 | ...
-----------|--------------|-----------------|------|------|------|------|-----
Argentina | ARG | employment in a | .40 | .35 | .37 | .43 | ...
Argentina | ARG | employment in b | .35 | .30 | .32 | .29 | ...
Argentina | ARG | employment in c | .25 | .35 | .31 | .28 | ...
-
Brazil | BRA | employment in a | .45 | .35 | .33 | .44 | ...
Brazil | BRA | employment in b | .30 | .33 | .34 | .27 | ...
Brazil | BRA | employment in c | .25 | .32 | .33 | .29 | ...
... | ... | ... | ... | ... | ... | ... | ...
but I need to change it to this format:
country | country code | year | employment in a | employment in b | employment in c
-----------|--------------|------|-----------------|-----------------|-----------------
Argentina | ARG | 1990 | .40 | .35 | .25
Argentina | ARG | 1991 | .35 | .30 | .35
Argentina | ARG | 1992 | .37 | .32 | .31
Argentina | ARG | 1993 | .43 | .29 | .28
Argentina | ARG | ... | ... | ... | ...
-
Brazil | BRA | 1990 | .45 | .30 | .25
Brazil | BRA | 1991 | .35 | .33 | .32
Brazil | BRA | 1992 | .33 | .34 | .33
Brazil | BRA | 1993 | .44 | .27 | .29
Brazil | BRA | ... | ... | ... | ...
... | ... | ... | ... | ... | ...
I have more variables, countries and years but the tables should illustrate the problem sufficiently.
I tried gather()
and reshape()
but was not able to solve my problem.
Could someone help me with this problem?