Skip to content
Prev 275737 / 398506 Next

Syntax Check: rshape2 melt()

On Thu, 27 Oct 2011, Nordlund, Dan (DSHS/RDA) wrote:

            
Dan,

   It's been that sort of a day when that might well have been what I did. So
I checked and re-melted the data with similar lack of results.
OK. This yields:

head(m.tds.anal)
      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
I still get this error:

wanted <- dcast(m.tds.anal, site + sampdate ~ param)
Aggregation function missing: defaulting to length

and the values are replaced by lengths in the output:

head(wanted)
     site   sampdate Ca Cl Cond Mg Na SO4 TDS
1 BC-0.5 1996-04-19  1  1    1  1  0   1   1
2 BC-0.5 1996-05-21  0  0    1  0  0   1   1
3 BC-0.5 1996-06-02  0  0    1  0  0   1   1
4   BC-1 1994-05-24  1  1    1  1  1   1   1
5   BC-1 1994-06-02  1  1    1  1  1   1   1
6   BC-1 1994-06-10  1  1    1  1  1   1   1

   This is what happens each time I try. That's why I thought that sampdate
needed to be a factor rather than a date. I certainly have no idea why I'm
not getting valid results, but appreciate the help that you and others
provide so I can learn to do this correctly.

Thanks again,

Rich