# how to put data in a matrix form

#### marwah

##### New Member
I have the following data:
Code:
       date          pcp
1    20010101 1.051627e+01
2    20010102 9.139277e-02
3    20010103 2.826194e+00
4    20010104 2.115948e+00
5    20010105 6.152151e-01
6    20010106 9.994188e-01
7    20010107 1.130322e-01
8    20010108 5.135144e-01
9    20010109 8.858852e-20
10   20010110 7.527586e-19
11   20010111 2.173860e-01
12   20010112 1.664218e-01
13   20010113 2.221383e-02
14   20010114 4.113533e+00
15   20010115 2.045578e+01
16   20010116 3.061036e+00
and I want to put it in a matrix form that looks like the following:
Code:
Months  2005  2006  2007  2008  2009  2010
Jan        28.1  5.8  22.9  64.2  70.1  85.9
Feb        41.4  85.1  149.2  31.0  142.1  36.9
Mar        153.2  145.9  101.6  308.8  171.8  57.5
Apr         57.0  212.4  170.3  244.5  278.9  132.9
May        154.9  119.9  57.8  128.8  212.7  55.6
jun         158.6  81.3  160.8  94.0  115.3  63.3
Jul         22.6  27.2  29.4  80.9  82.7  30.9
how can I do that?

#### marwah

##### New Member
I have tried matrix function but couldn't get it right, I really have tried to code it but didn't give me the answer that is why I have asked

#### trinker

##### ggplot2orBust
It's impossible to turn the top data set into the lower data set as they are different data. The top all come from the same year (2001).

hear's how to do this problem and you get no further help from me unless I see sincere effort.

Use the following functions/steps:

as.POSIXlt with strptime
make a months column with months function and figure out with google how to extract year into another column.

Use melt from the reshape2 package with dcast

#### marwah

##### New Member
It's impossible to turn the top data set into the lower data set as they are different data. The top all come from the same year (2001).

hear's how to do this problem and you get no further help from me unless I see sincere effort.

Use the following functions/steps:

as.POSIXlt with strptime
make a months column with months function and figure out with google how to extract year into another column.

Use melt from the reshape2 package with dcast
I really trying my best , second the data I want is just a format that I wanted to look like , I know you can't have 2001 and make it 2005. it is just the look of that matrix that I want from the given data.