[R] reshape() problems

Robin Hankin rksh1 at cam.ac.uk
Thu Jan 22 10:51:32 CET 2009


Hi

I have a data frame with timeseries information like this:

year   cell   Q1    Q2     Q3     Q4
1940   1      1.2   1.4     1.4    1.9
1941   1      2.9   2.1     3.4       2.4
1942   1      2.7   3.2     1.5    2.6
1940   2      1.4   2.1     2.6    2.4
1941   2      2.4   1.4     1.4    3.4
1942   2      1.4   2.4     2.5    4.4

where the Qs mean 'quarter'.  I want to extract from this
a dataframe with a timeseries for each cell:


year     quarter  cell1      cell2
1940     1      1.2         1.4
1940     2      1.4         2.1
1940     3      1.4         2.6
1940     4      1.9         2.4
1941     1      2.9         2.4
1941     2      2.1         1.4
1941     3      3.4         1.4
1942     4      2.4         3.4
1942     1      2.7         1.4
1942     2      3.2         2.4
1942     3      1.5         2.5
1942     4      2.6         4.4

Thus the third and fourth columns are the timeserieses for
cell 1 and cell 2.

Is there a nice vectorized way to do this?

I can't quite make reshape() do what I want.

[the real dataset is months, not quarters, has ~2000 cells
and ~60 years]



-- 
Robin K. S. Hankin
Uncertainty Analyst
University of Cambridge
19 Silver Street
Cambridge CB3 9EP
01223-764877




More information about the R-help mailing list