[R] reshape2: Lost Values Between melt() and dcast()

Rich Shepard rshepard at appl-ecosys.com
Mon Oct 31 17:32:29 CET 2011


   Working with 5 subset streams from my source data frame, three of them
successfully call dcast(), but two fail:

jerritt.cast <- dcast(jerritt.melt, site + sampdate ~ param)
Aggregation function missing: defaulting to length

and

winters.cast <- dcast(winters.melt, site + sampdate ~ param)
Aggregation function missing: defaulting to length

   Yet both data frames have the values in their .melt data frames:

summary(jerritt.melt)
       site         sampdate              param       variable
  JCM-1  :2178   Min.   :1978-03-28   pH     : 292   quant:7519
  JCM-20A:2149   1st Qu.:1996-05-24   As     : 286
  JC-E   : 476   Median :2000-05-31   SO4    : 271
  JC     : 400   Mean   :2001-02-04   TDS    : 271
  GD-1   : 395   3rd Qu.:2006-05-31   Cl     : 253
  JC-2   : 349   Max.   :2009-12-30   Zn     : 250
  (Other):1572                        (Other):5896
      value
  Min.   :    0.000
  1st Qu.:    0.005
  Median :    0.650
  Mean   :  317.588
  3rd Qu.:   27.000
  Max.   :20450.000
  NA's   : 2134.000

and

summary(winters.melt)
       site        sampdate              param      variable
  WC     :601   Min.   :1987-07-23   As     : 96   quant:1189
  WC-2   :327   1st Qu.:1994-06-15   TDS    : 79
  WC-1   :261   Median :1995-07-27   NO3-N  : 74
  BC-0.5 :  0   Mean   :1997-05-15   pH     : 72
  BC-1   :  0   3rd Qu.:1996-07-29   SO4    : 69
  BC-1.5 :  0   Max.   :2011-06-06   Cl     : 64
  (Other):  0                        (Other):735
      value
  Min.   :   0.00
  1st Qu.:   0.05
  Median :   7.59
  Mean   :  79.20
  3rd Qu.:  75.00
  Max.   :2587.00
  NA's   : 252.00

   What might be causing dcast() to fail with these two data frames while it
succeeds with three others processed using the same syntax? If additional
information would help, let me know and I'll provide it.

Puzzled,

Rich



More information about the R-help mailing list