Skip to content
Prev 275708 / 398506 Next

Syntax Check: rshape2 melt()

Rich,

I read in the sample data that you put in an earlier post.
site   sampdate param quant
1    UDS-O 2006-12-06   TDS 10800
4   STC-FS 1996-06-14  Cond   280
7    UDS-O 2007-10-04    Mg  1620
9    UDS-O 2007-10-04   SO4  7580
19 JCM-10B 2007-06-21    Ca    79
20 JCM-10B 2007-06-21    Cl   114

Then ran the following code
Using site, sampdate, param as id variables
     site   sampdate param variable value
1   UDS-O 2006-12-06   TDS    quant 10800
2  STC-FS 1996-06-14  Cond    quant   280
3   UDS-O 2007-10-04    Mg    quant  1620
4   UDS-O 2007-10-04   SO4    quant  7580
5 JCM-10B 2007-06-21    Ca    quant    79
6 JCM-10B 2007-06-21    Cl    quant   114
Using site, sampdate, param as id variables
     site   sampdate Ca  Cl Cond   Mg  SO4   TDS
1 JCM-10B 2007-06-21 79 114   NA   NA   NA    NA
2  STC-FS 1996-06-14 NA  NA  280   NA   NA    NA
3   UDS-O 2006-12-06 NA  NA   NA   NA   NA 10800
4   UDS-O 2007-10-04 NA  NA   NA 1620 7580    NA
So you can see that at least it worked for me.  Can you show us the actual output you get when running the melt and dcast functions on a sample of your data?  I am not sure why sampdate is not found since it appears to be in your original sample data.

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204