0

I'm pulling data from a database into R. I end up with a data frame containing three data series (A,B,C). It looks something like this:

month       series  value
2012-12     A       10.45
2012-11     A       11.20
2012-10     A       11.04
2012-12     B       8.24
2012-11     B       8.89
2012-10     B       9.74
2012-12     C       25.01
2012-11     C       29.87
2012-10     C       26.74

I'm trying to chart the three series on a line chart. I think the easiest way to do that would be to put it in a format like this:

month       A       B       C
2012-12     10.45   8.24    25.01
2012-11     11.20   8.89    29.87
2012-10     11.04   9.74    26.74

Is there a slick way to do this?

A5C1D2H2I1M1N2O1R2T1
  • 190,393
  • 28
  • 405
  • 485
  • 2
    This is called going from long to wide format - there are piles of examples on SO, you just need to know what to search for. http://stackoverflow.com/questions/5890584/reshape-data-from-long-to-wide-format-r – alexwhan Sep 03 '13 at 02:55

1 Answers1

1

You can change the format using the reshape function. Or with more flexibility the reshape2 package.

However, with the original long format that you have you can plot the data, probably easiest will be with the ggplot2 or lattice packages.

Greg Snow
  • 48,497
  • 6
  • 83
  • 110