








Dear R forum

I have just started my venture with R. While I am trying to learn R through the tutorials, I think the current problem I need to address to is beyond my knowledge about R.

I have a dataframe as defined below -


rat_dat = data.frame(name = c("A", "A", "A", "B", "B", "B", "C", "C", "C", "D", "D", "D"),
                              period = c("31-Mar-11", "30-Mar-11", "29-Mar-11", "31-Mar-11", "30-Mar-11", "29-Mar-11",  "31-Mar-11", "30-Mar-11", "29-Mar-11", "31-Mar-11", "30-Mar-11", "29-Mar-11"),
cy_date = c("31-May-11","31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11", "31-May-11"),  
values = c(10.42, 10.46, 10.37, 12.62, 12.65, 12.61, 14.10, 14.12, 14.08, 11.11, 11.15, 11.17))  


> rat_dat
   name    period   cy_date values
1     A 31-Mar-11 31-May-11  10.42
2     A 30-Mar-11 31-May-11  10.46
3     A 29-Mar-11 31-May-11  10.37
4     B 31-Mar-11 31-May-11  12.62
5     B 30-Mar-11 31-May-11  12.65
6     B 29-Mar-11 31-May-11  12.61
7     C 31-Mar-11 31-May-11  14.10
8     C 30-Mar-11 31-May-11  14.12
9     C 29-Mar-11 31-May-11  14.08
10    D 31-Mar-11 31-May-11  11.11
11    D 30-Mar-11 31-May-11  11.15
12    D 29-Mar-11 31-May-11  11.17

My actual data is too large. I need to 

(1) rearrange this input as 









period  
  cy_date
          A
      B
    C
    D

31-Mar-11
 31-May-11 
10.42
  12.62
14.10
11.11

30-Mar-11
 31-May-11 
10.46
  12.65
14.12
11.15

29-Mar-11
 31-May-11 
10.37
  12.61
14.08
11.17

(2) Also, I need to find the difference between (rat_dat$cy_date) - (rat_dat$period)

I hope I am able to put forward my requirement properly. If not, please forgive me.

Sandeepa

	[[alternative HTML version deleted]]

