在我的情况下,给定的输入就像这样
Country 1990 1991 1992
Bolivia 5 6 7
Cambodia 8 9 10
Russia 11 12 13
他们要我这样忽略:
Country Variable of Interest Year
Bolivia 5 1990
Bolivia 6 1991
Bolivia 7 1992
Cambodia 8 1990
Cambodia 9 1991
Cambodia 10 1992
Russia 11 1990
Russia 12 1991
Russia 13 1992
先谢谢
答案 0 :(得分:1)
您可以使用reshape2包中的melt
。假设您的数据为dat
> melt(dat)
Using Country as id variables
Country variable value
1 Bolivia 1990 5
2 Cambodia 1990 8
3 Russia 1990 11
4 Bolivia 1991 6
5 Cambodia 1991 9
6 Russia 1991 12
7 Bolivia 1992 7
8 Cambodia 1992 10
9 Russia 1992 13