Skip to content
Prev 205410 / 398506 Next

Tranpose and Aggregate Data - now Reshape - cast

library(reshape)

names(harvest.dat) = c("CROP_ID", "CROPTYPE", "PERIOD","CUT_AGE")

harvest <-cast(harvest.dat, CROP_ID + CROPTYPE ~ PERIOD)

It seems that I am getting the frequencies instead of the individual values.

Output
~~~~~~~~~
   CROP_ID CROPTYPE 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
1         1      OTO 2 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
2         1     SORI 4 0 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
3         2      OTO 0 6 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
4         2     SORI 0 3 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
5         2     SORM 0 1 0 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
6         3      OTO 0 0 2 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
7         3     OTRM 0 0 1 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
8         3     SORI 0 0 1 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
9         3     SORM 0 0 1 0 0 0 0 0 0  0  0  0  0  0  0  0  0  0  0  0  0  0
~~~~~~~~~


Desired table

CROP_ID CROPTYPE P1        P2        P3        P4       P5        P6
 P7  P8        P9        P10
How do I do this properly.

Thanks in advance. Noli