-1

In my case the given input is like this

Country   1990    1991   1992
 Bolivia    5        6     7
 Cambodia   8        9     10
 Russia     11       12    13

They want me to unpivot like this:

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

Thanks in Advance

Simon MᶜKenzie
  • 8,344
  • 13
  • 50
  • 77
Gowtham SB
  • 332
  • 1
  • 3
  • 16
  • Just a note - "ASAP" is widely regarded as [impolite](https://mobiliversity.wordpress.com/2014/04/10/asap-and-e-mail-politeness/), so I've removed it from your post. – Simon MᶜKenzie Mar 13 '15 at 04:37
  • Also see examples here http://stackoverflow.com/questions/2185252/reshaping-data-frame-from-wide-to-long-format and here http://stackoverflow.com/questions/13867737/reshape-data-from-wide-to-long – LJW Mar 13 '15 at 04:39

1 Answers1

1

You can use melt from reshape2 package. Suppose your data is 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
Jilber Urbina
  • 58,147
  • 10
  • 114
  • 138