0

Possible Duplicate:
how to pivot/unpivot (cast/melt) data frame?

I have this data frame

idx A  B  C  D
1   12 23 33 4
2   33 22 23 6

which I would like to convert to the following format (which ggplot2 seems to prefer)

idx col value
1   A   12
1   B   23
1   C   33
1   D   4
2   A   33
2   B   22
2   C   23
2   D   6

Is there any way to do it with standard R code (or a ggplot2 function that I am missing)?

Community
  • 1
  • 1
Georgios Gousios
  • 2,405
  • 1
  • 24
  • 34
  • 7
    You are looking for `reshape2::melt`. – Roland Dec 30 '12 at 18:12
  • 2
    see [this question](http://stackoverflow.com/questions/7980030/how-to-pivot-unpivot-cast-melt-data-frame) as one of many duplicates. – Roland Dec 30 '12 at 18:14
  • 1
    Adapted from an answer to that question, here is the exact code that you need: `melt(x, id='idx', variable_name='col')` – Matthew Lundberg Dec 30 '12 at 18:22
  • Thanks, as an R newbie I am not exactly familiar with the terminology, hence the duplicate... – Georgios Gousios Dec 30 '12 at 20:22
  • @GeorgiosGousios: R-newb or not, you have a responsibility to search before posting. True that terminology can vary, but if you post your search strategies, people will probably be less quick to close and more inclined to offer explanations. – IRTFM Dec 31 '12 at 00:30

0 Answers0