[R] Syntax Check: rshape2 melt()

Rich Shepard rshepard at appl-ecosys.com
Fri Oct 28 02:34:46 CEST 2011


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

> I will be leaving work shortly, and won't be able to look at this again
> until tomorrow some time.  However, I went back and reread the help page
> on dcast.  Here is part of that page.
>
> fun.aggregate
>
> aggregation function needed if variables do not identify a single
> observation for each output cell. Defaults to length (with a message) if
> needed but not specified.

   I read that, too, Dan. But did not see how that applies to these data.

> It looks like your data may be slightly different than I expected.  The
> fact that dcast is looking for an aggregation function suggests that you
> have more than one record for some combination of site|sampdate|param.  No
> param value ('TDS', 'SO4', ...) should occur more than once for any
> combination of site and sampdate (i.e. no multiple measures of the same
> parameter on the same day in the same site).  So, you might want to check
> your data to make sure you have no more than 1 measurement per param per
> sampdate per site.

   Nope. Can't. In the database table site, date, param are the compound
primary key. Besides, it makes no sense to have two concentration
measurements of the same chemical on the same day from the same location. I
spent a lot of time getting rid of duplicate records because the same site
was listed with two spellings (one with a hyphen, one without) or some
records were listed as "TDS" while others from the same day and location
were entered in their spreadsheet as "Total Dissolved Solids". That table is
clean, and the .csv copy didn't change any values on its way into R.

> If that isn't the problem, then I would start thinking about restarting R
> and then re-installing reshape2.  Good luck.

   I'll do that tomorrow. It's sorta' a Microsoft solution: shut down
computer, spin around it your chair three times, restart computer.

   Too bad there is not more detailed diagnostic information about the source
of the error, or a way to stick a stub of code in the function call to
illucidate just what dcast() thinks it sees.

Thanks,

Rich



More information about the R-help mailing list