reshape2 errors on data frame

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

reshape2 errors on data frame

Rich Shepard
   I've successfully reformatted data frames from long to wide with reshape2,
but this time I'm getting errors that I want to understand and resolve.
Here's the data frame structure and the results of the melt() and dcast()
functions:

str(waterchem)
'data.frame': 128412 obs. of  8 variables:
  $ site    : Factor w/ 64 levels "D-1","D-2","D-3",..: 1 1 1 1 1 1 1 ...
  $ sampdate: Date, format: "2007-12-12" "2007-12-12" ...
  $ preeq0  : logi  TRUE TRUE TRUE TRUE TRUE TRUE ...
  $ param   : Factor w/ 37 levels "Ag","Al","Alk_tot",..: 1 2 8 17 3 4 ...
  $ quant   : num  0.005 0.106 1 231 231 0.011 0.001 0.002 0.001 100 ...
  $ ceneq1  : logi  TRUE FALSE TRUE FALSE FALSE FALSE ...
  $ floor   : num  0 0.106 0 231 231 0.011 0 0 0 100 ...
  $ ceiling : num  0.005 0.106 1 231 231 0.011 0.001 0.002 0.001 100 ...
> chem.melt <- melt(waterchem, idvars = c('site', 'sampdate', 'preeq0', 'param', 'ceneq1', 'floor', 'ceiling'))
Using site, preeq0, param, ceneq1 as id variables
> chem.cast <- dcast(chem.melt, site + sampdate + preeq0 + ceneq1 + floor + ceiling ~ param)
Error in eval(expr, envir, enclos) : object 'sampdate' not found

   Because these data have some censored data there is the logical indicator
(ceneq1) to identify censored and uncensored values the the interval ends
(floor and ceiling) for multiply censored values. One factor of analytical
interest whether the sampdate is pre- or post-event; that uses the logical
indicator preeq0.

   Please point out where my melt() and dcast() syntax was incorrect. I will
provide more information if needed.

TIA,

Rich

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: reshape2 errors on data frame

John Kane
It would be very helpful to have some sample data to play with.  str() shows the structure of the data set but it is not the data.

Something like dput(head(100))  would probably be enough.



John Kane
Kingston ON Canada


> -----Original Message-----
> From: [hidden email]
> Sent: Thu, 5 Jul 2012 08:46:31 -0700 (PDT)
> To: [hidden email]
> Subject: [R] reshape2 errors on data frame
>
>    I've successfully reformatted data frames from long to wide with
> reshape2,
> but this time I'm getting errors that I want to understand and resolve.
> Here's the data frame structure and the results of the melt() and dcast()
> functions:
>
> str(waterchem)
> 'data.frame': 128412 obs. of  8 variables:
>   $ site    : Factor w/ 64 levels "D-1","D-2","D-3",..: 1 1 1 1 1 1 1 ...
>   $ sampdate: Date, format: "2007-12-12" "2007-12-12" ...
>   $ preeq0  : logi  TRUE TRUE TRUE TRUE TRUE TRUE ...
>   $ param   : Factor w/ 37 levels "Ag","Al","Alk_tot",..: 1 2 8 17 3 4
> ...
>   $ quant   : num  0.005 0.106 1 231 231 0.011 0.001 0.002 0.001 100 ...
>   $ ceneq1  : logi  TRUE FALSE TRUE FALSE FALSE FALSE ...
>   $ floor   : num  0 0.106 0 231 231 0.011 0 0 0 100 ...
>   $ ceiling : num  0.005 0.106 1 231 231 0.011 0.001 0.002 0.001 100 ...
>> chem.melt <- melt(waterchem, idvars = c('site', 'sampdate', 'preeq0',
>> 'param', 'ceneq1', 'floor', 'ceiling'))
> Using site, preeq0, param, ceneq1 as id variables
>> chem.cast <- dcast(chem.melt, site + sampdate + preeq0 + ceneq1 + floor
>> + ceiling ~ param)
> Error in eval(expr, envir, enclos) : object 'sampdate' not found
>
>    Because these data have some censored data there is the logical
> indicator
> (ceneq1) to identify censored and uncensored values the the interval ends
> (floor and ceiling) for multiply censored values. One factor of
> analytical
> interest whether the sampdate is pre- or post-event; that uses the
> logical
> indicator preeq0.
>
>    Please point out where my melt() and dcast() syntax was incorrect. I
> will
> provide more information if needed.
>
> TIA,
>
> Rich
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

____________________________________________________________
FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: reshape2 errors on data frame

Rich Shepard
On Thu, 5 Jul 2012, John Kane wrote:

> It would be very helpful to have some sample data to play with.

John,

   dput() doesn't want to cooperate so here are 100 rows from the raw data
file that can be input with read.table("sample.dat", header = T, sep = "|"):

'site'|'sampdate'|'preeq0'|'param'|'quant'|'ceneq1'|'floor'|'ceiling'
'A'|'2007-12-12'|1|'Ag'|0.005|1|0|0.005
'A'|'2007-12-12'|1|'Al'|0.106|0|0.106|0.106
'A'|'2007-12-12'|1|'CO3'|1|1|0|1
'A'|'2007-12-12'|1|'HCO3'|231.000|0|231.000|231.000
'A'|'2007-12-12'|1|'Alk_tot'|231.000|0|231.000|231.000
'A'|'2007-12-12'|1|'As'|0.011|0|0.011|0.011
'A'|'2007-12-12'|1|'Ba'|0.001|1|0|0.001
'A'|'2007-12-12'|1|'Be'|0.002|1|0|0.002
'A'|'2007-12-12'|1|'Bi'|0.001|1|0|0.001
'A'|'2007-12-12'|1|'Ca'|100.000|0|100.000|100.000
'A'|'2007-12-12'|1|'Cd'|0.001|1|0|0.001
'A'|'2007-12-12'|1|'Cl'|1.430|0|1.430|1.430
'A'|'2007-12-12'|1|'Co'|0.001|1|0|0.001
'A'|'2007-12-12'|1|'Cr'|0.006|1|0|0.006
'A'|'2007-12-12'|1|'Cu'|0.024|0|0.024|0.024
'A'|'2007-12-12'|1|'DO'|4.960|0|4.960|4.960
'A'|'2007-12-12'|1|'Fe'|4.110|0|4.110|4.110
'A'|'2007-12-12'|1|'K'|0.001|1|0|0.001
'A'|'2007-12-12'|1|'Mg'|9.560|0|9.560|9.560
'A'|'2007-12-12'|1|'Mn'|0.035|0|0.035|0.035
'A'|'2007-12-12'|1|'Mo'|0.001|1|0|0.001
'A'|'2007-12-12'|1|'Na'|0.970|0|0.970|0.970
'A'|'2007-12-12'|1|'NH4'|0.01|1|0|0.01
'A'|'2007-12-12'|1|'NO3-NO2'|0.293|0|0.293|0.293
'A'|'2007-12-12'|1|'Pb'|0.025|0|0.025|0.025
'A'|'2007-12-12'|1|'pH'|7.800|0|7.800|7.800
'A'|'2007-12-12'|1|'Sb'|0.001|1|0|0.001
'A'|'2007-12-12'|1|'SC'|630.000|0|630.000|630.000
'A'|'2007-12-12'|1|'Se'|0.001|0|0.001|0.001
'A'|'2007-12-12'|1|'SO4'|65.800|0|65.800|65.800
'A'|'2007-12-12'|1|'Sr'|0.001|1|0|0.001
'A'|'2007-12-12'|1|'TDS'|320.000|0|320.000|320.000
'A'|'2007-12-12'|1|'Tl'|0.001|1|0|0.001
'A'|'2007-12-12'|1|'V'|0.001|1|0|0.001
'A'|'2007-12-12'|1|'Zn'|11.400|0|11.400|11.400
'A'|'2008-03-15'|1|'Ag'|0.005|1|0|0.005
'A'|'2008-03-15'|1|'Al'|0.08|1|0|0.08
'A'|'2008-03-15'|1|'CO3'|1|1|0|1
'A'|'2008-03-15'|1|'HCO3'|228.000|0|228.000|228.000
'A'|'2008-03-15'|1|'Alk_tot'|228.000|0|228.000|228.000
'A'|'2008-03-15'|1|'As'|0.001|0|0.001|0.001
'A'|'2008-03-15'|1|'Ba'|0.001|1|0|0.001
'A'|'2008-03-15'|1|'Be'|0.002|1|0|0.002
'A'|'2008-03-15'|1|'Bi'|0.001|1|0|0.001
'A'|'2008-03-15'|1|'Ca'|88.400|0|88.400|88.400
'A'|'2008-03-15'|1|'Cd'|0.001|1|0|0.001
'A'|'2008-03-15'|1|'Cl'|1.340|0|1.340|1.340
'A'|'2008-03-15'|1|'Co'|0.001|1|0|0.001
'A'|'2008-03-15'|1|'Cr'|0.006|1|0|0.006
'A'|'2008-03-15'|1|'Cu'|0.014|0|0.014|0.014
'A'|'2008-03-15'|1|'DO'|9.910|0|9.910|9.910
'A'|'2008-03-15'|1|'Fe'|0.309|0|0.309|0.309
'A'|'2008-03-15'|1|'Hg'|0.001|1|0|0.001
'A'|'2008-03-15'|1|'K'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Ag'|0.005|1|0|0.005
'B-2'|'1992-02-29'|0|'Al'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'As'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Ba'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Be'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Bi'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Ca'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Cd'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Cl'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Co'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Cr'|0.03|1|0|0.03
'B-2'|'1992-02-29'|0|'Cu'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Fe'|1.2|1|0|1.2
'B-2'|'1992-02-29'|0|'Hg'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'K'|19.800|0|19.800|19.800
'B-2'|'1992-02-29'|0|'Mg'|1|1|0|1
'B-2'|'1992-02-29'|0|'Mn'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Mo'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Na'|0.03|1|0|0.03
'B-2'|'1992-02-29'|0|'NH4'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Pb'|0.025|0|0.025|0.025
'B-2'|'1992-02-29'|0|'pH'|8.480|0|8.480|8.480
'B-2'|'1992-02-29'|0|'Sb'|0.01|1|0|0.01
'B-2'|'1992-02-29'|0|'Se'|0.003|1|0|0.003
'B-2'|'1992-02-29'|0|'Sr'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'TDS'|15|1|0|15
'B-2'|'1992-02-29'|0|'Tl'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'V'|0.001|1|0|0.001
'B-2'|'1992-02-29'|0|'Zn'|0.001|1|0|0.001
'B-2'|'1992-04-02'|0|'Ag'|0.005|1|0|0.005
'B-2'|'1992-04-02'|0|'Al'|0.001|1|0|0.001
'B-2'|'1992-04-02'|0|'As'|0.001|1|0|0.001
'B-2'|'1992-04-02'|0|'Ba'|0.001|1|0|0.001
'B-2'|'1992-04-02'|0|'Be'|0.001|1|0|0.001
'B-2'|'1992-04-02'|0|'Bi'|0.001|1|0|0.001
'B-2'|'1992-04-02'|0|'Ca'|0.001|1|0|0.001
'B-2'|'1992-04-02'|0|'Cd'|0.001|1|0|0.001
'B-2'|'1992-04-02'|0|'Cl'|0.001|1|0|0.001
'B-2'|'1992-04-02'|0|'Co'|0.001|1|0|0.001
'B-2'|'1992-04-02'|0|'Cr'|0.03|1|0|0.03
'B-2'|'1992-04-02'|0|'Cu'|0.001|1|0|0.001
'B-2'|'1992-04-02'|0|'Fe'|1.2|1|0|1.2
'B-2'|'1992-04-02'|0|'Hg'|0.001|1|0|0.001
'B-2'|'1992-04-02'|0|'K'|0.001|1|0|0.001
'B-2'|'1992-04-02'|0|'Mg'|1|1|0|1
'B-2'|'1992-04-02'|0|'Mn'|0.001|1|0|0.001

Rich

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: reshape2 errors on data frame

Nordlund, Dan (DSHS/RDA)
> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Rich Shepard
> Sent: Thursday, July 05, 2012 10:36 AM
> To: [hidden email]
> Subject: Re: [R] reshape2 errors on data frame
>
> On Thu, 5 Jul 2012, John Kane wrote:
>
> > It would be very helpful to have some sample data to play with.
>
> John,
>
>    dput() doesn't want to cooperate so here are 100 rows from the raw
> data
> file that can be input with read.table("sample.dat", header = T, sep =
> "|"):
>
> 'site'|'sampdate'|'preeq0'|'param'|'quant'|'ceneq1'|'floor'|'ceiling'
> 'A'|'2007-12-12'|1|'Ag'|0.005|1|0|0.005

<<<snip>>>


> 'B-2'|'1992-04-02'|0|'Mn'|0.001|1|0|0.001
>
> Rich
>

Rich,

The melt syntax you provided in a previous email runs without error on the data that you just supplied.  So, your comment that "dput() doesn't want to cooperate" suggests that maybe there is a problem with your waterchem data frame.  Maybe someone else will have more insight into the problem.

Sorry I can't be of more help,

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


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: reshape2 errors on data frame

Rich Shepard
On Thu, 5 Jul 2012, Nordlund, Dan (DSHS/RDA) wrote:

> The melt syntax you provided in a previous email runs without error on the
> data that you just supplied.  So, your comment that "dput() doesn't want
> to cooperate" suggests that maybe there is a problem with your waterchem
> data frame.  Maybe someone else will have more insight into the problem.

Dan,

   Huh! Isn't that interesting? I'll re-read the data into a data frame and
see if that makes a difference.

   I wonder if the issue is with the logical columns; I've not used them
before, only dates, factors, and numerals. I'll try without the logicals and
see if there's a difference.

Thanks for the insight,

Rich

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: reshape2 errors on data frame

Rich Shepard
On Thu, 5 Jul 2012, Rich Shepard wrote:

>  I wonder if the issue is with the logical columns; I've not used them
> before, only dates, factors, and numerals. I'll try without the logicals
> and see if there's a difference.

   Nope. Same problem as before.

   Someone, please provide a process I can apply to figure out the error in
the data frame.

Rich

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: reshape2 errors on data frame

Michael Weylandt


On Jul 5, 2012, at 1:28 PM, Rich Shepard <[hidden email]> wrote:

> On Thu, 5 Jul 2012, Rich Shepard wrote:
>
>> I wonder if the issue is with the logical columns; I've not used them
>> before, only dates, factors, and numerals. I'll try without the logicals
>> and see if there's a difference.
>
>  Nope. Same problem as before.
>
>  Someone, please provide a process I can apply to figure out the error in
> the data frame.
>

What do you mean it won't cooperate? Error message?

Michael

> Rich
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: reshape2 errors on data frame

Rui Barradas
In reply to this post by Rich Shepard
Hello,

Just to give it a try, you've written 'idvars' when it's 'id.vars'.
After correction I no longer have the error. But, as expected, the
result 'chem.cast' has lots and lots of NAs.


chem.cast <- dcast(chem.melt,
        site + sampdate + preeq0 + ceneq1 + floor + ceiling ~ param)

# First 6 rows
head(chem.cast)
   site   sampdate preeq0 ceneq1 floor ceiling Ag    Al Alk_tot    As Ba
Be Bi Ca Cd
1    A 2007-12-12   TRUE  FALSE 0.001   0.001 NA    NA      NA    NA NA
NA NA NA NA
2    A 2007-12-12   TRUE  FALSE 0.011   0.011 NA    NA      NA 0.011 NA
NA NA NA NA
3    A 2007-12-12   TRUE  FALSE 0.024   0.024 NA    NA      NA    NA NA
NA NA NA NA
4    A 2007-12-12   TRUE  FALSE 0.025   0.025 NA    NA      NA    NA NA
NA NA NA NA
5    A 2007-12-12   TRUE  FALSE 0.035   0.035 NA    NA      NA    NA NA
NA NA NA NA
6    A 2007-12-12   TRUE  FALSE 0.106   0.106 NA 0.106      NA    NA NA
NA NA NA NA
   Cl Co CO3 Cr    Cu DO Fe HCO3 Hg  K Mg    Mn Mo Na NH4 NO3-NO2    Pb
pH Sb SC    Se
1 NA NA  NA NA    NA NA NA   NA NA NA NA    NA NA NA  NA      NA    NA
NA NA NA 0.001
2 NA NA  NA NA    NA NA NA   NA NA NA NA    NA NA NA  NA      NA    NA
NA NA NA    NA
3 NA NA  NA NA 0.024 NA NA   NA NA NA NA    NA NA NA  NA      NA    NA
NA NA NA    NA
4 NA NA  NA NA    NA NA NA   NA NA NA NA    NA NA NA  NA      NA 0.025
NA NA NA    NA
5 NA NA  NA NA    NA NA NA   NA NA NA NA 0.035 NA NA  NA      NA    NA
NA NA NA    NA
6 NA NA  NA NA    NA NA NA   NA NA NA NA    NA NA NA  NA      NA    NA
NA NA NA    NA
   SO4 Sr TDS Tl  V Zn
1  NA NA  NA NA NA NA
2  NA NA  NA NA NA NA
3  NA NA  NA NA NA NA
4  NA NA  NA NA NA NA
5  NA NA  NA NA NA NA
6  NA NA  NA NA NA NA

# Now the last 6 rows
tail(chem.cast)
    site   sampdate preeq0 ceneq1 floor ceiling    Ag    Al Alk_tot
As    Ba    Be
49  B-2 1992-02-29  FALSE   TRUE     0  15.000    NA    NA      NA    NA
    NA    NA
50  B-2 1992-04-02  FALSE   TRUE     0   0.001    NA 0.001      NA 0.001
0.001 0.001
51  B-2 1992-04-02  FALSE   TRUE     0   0.005 0.005    NA      NA    NA
    NA    NA
52  B-2 1992-04-02  FALSE   TRUE     0   0.030    NA    NA      NA    NA
    NA    NA
53  B-2 1992-04-02  FALSE   TRUE     0   1.000    NA    NA      NA    NA
    NA    NA
54  B-2 1992-04-02  FALSE   TRUE     0   1.200    NA    NA      NA    NA
    NA    NA
       Bi    Ca    Cd    Cl    Co CO3   Cr    Cu DO  Fe HCO3    Hg     K
Mg    Mn Mo
49    NA    NA    NA    NA    NA  NA   NA    NA NA  NA   NA    NA    NA
NA    NA NA
50 0.001 0.001 0.001 0.001 0.001  NA   NA 0.001 NA  NA   NA 0.001 0.001
NA 0.001 NA
51    NA    NA    NA    NA    NA  NA   NA    NA NA  NA   NA    NA    NA
NA    NA NA
52    NA    NA    NA    NA    NA  NA 0.03    NA NA  NA   NA    NA    NA
NA    NA NA
53    NA    NA    NA    NA    NA  NA   NA    NA NA  NA   NA    NA    NA
  1    NA NA
54    NA    NA    NA    NA    NA  NA   NA    NA NA 1.2   NA    NA    NA
NA    NA NA
    Na NH4 NO3-NO2 Pb pH Sb SC Se SO4 Sr TDS Tl  V Zn
49 NA  NA      NA NA NA NA NA NA  NA NA  15 NA NA NA
50 NA  NA      NA NA NA NA NA NA  NA NA  NA NA NA NA
51 NA  NA      NA NA NA NA NA NA  NA NA  NA NA NA NA
52 NA  NA      NA NA NA NA NA NA  NA NA  NA NA NA NA
53 NA  NA      NA NA NA NA NA NA  NA NA  NA NA NA NA
54 NA  NA      NA NA NA NA NA NA  NA NA  NA NA NA NA


Hope this helps,

Rui Barradas

Em 05-07-2012 19:28, Rich Shepard escreveu:

> On Thu, 5 Jul 2012, Rich Shepard wrote:
>
>>  I wonder if the issue is with the logical columns; I've not used them
>> before, only dates, factors, and numerals. I'll try without the logicals
>> and see if there's a difference.
>
>    Nope. Same problem as before.
>
>    Someone, please provide a process I can apply to figure out the error in
> the data frame.
>
> Rich
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: reshape2 errors on data frame

Rich Shepard
In reply to this post by Michael Weylandt
On Thu, 5 Jul 2012, R. Michael Weylandt <[hidden email]> wrote:

> What do you mean it won't cooperate? Error message?

Michael,

   I get the command echoed rather than results.

Rich

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: reshape2 errors on data frame

Nordlund, Dan (DSHS/RDA)
In reply to this post by Rich Shepard
> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Rich Shepard
> Sent: Thursday, July 05, 2012 11:29 AM
> To: [hidden email]
> Subject: Re: [R] reshape2 errors on data frame
>
> On Thu, 5 Jul 2012, Rich Shepard wrote:
>
> >  I wonder if the issue is with the logical columns; I've not used
> them
> > before, only dates, factors, and numerals. I'll try without the
> logicals
> > and see if there's a difference.
>
>    Nope. Same problem as before.
>
>    Someone, please provide a process I can apply to figure out the
> error in
> the data frame.
>
> Rich
>

Rich,

I apologize that I did not read your original post carefully enough.  I missed that your problem was with the dcast() function.  I am not very familiar with the reshape package, but maybe I can give you some ideas of how to proceed.  When I ran your melt syntax there was no error message, however there was a messages saying "Using site, sampdate, param as id variables".  That is, not all of the ID variables specified were used. So the chem.melt data frame did not have all the ID variables in it.  Therefore, when I tried to run the dcast() syntax that you gave, it could not find some of variables specified.  In your case, the error message stated that it could not find sampdate.  If you run

str(chem.melt)

do you see the variable sampdate?  I am not sure how you are wanting to re-shape your data, but when you specify a variable in dcast(), it needs to be in the dataframe you are working with.


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


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: reshape2 errors on data frame

Rui Barradas
Hello,

Inline

Em 05-07-2012 20:21, Nordlund, Dan (DSHS/RDA) escreveu:

>> -----Original Message-----
>> From: [hidden email] [mailto:r-help-bounces@r-
>> project.org] On Behalf Of Rich Shepard
>> Sent: Thursday, July 05, 2012 11:29 AM
>> To: [hidden email]
>> Subject: Re: [R] reshape2 errors on data frame
>>
>> On Thu, 5 Jul 2012, Rich Shepard wrote:
>>
>>>   I wonder if the issue is with the logical columns; I've not used
>> them
>>> before, only dates, factors, and numerals. I'll try without the
>> logicals
>>> and see if there's a difference.
>>
>>     Nope. Same problem as before.
>>
>>     Someone, please provide a process I can apply to figure out the
>> error in
>> the data frame.
>>
>> Rich
>>
>
> Rich,
>
> I apologize that I did not read your original post carefully enough.  I missed that your problem was with the dcast() function.  I am not very familiar with the reshape package, but maybe I can give you some ideas of how to proceed.  When I ran your melt syntax there was no error message, however there was a messages saying "Using site, sampdate, param as id variables".  That is, not all of the ID variables specified were used. So the chem.melt data frame did not have all the ID variables in it.  Therefore, when I tried to run the dcast() syntax that you gave, it could not find some of variables specified.  In your case, the error message stated that it could not find sampdate.  If you run
>

I should have said that in my earlier post. It's implicit in the
misspeling of the argument 'id.vars', an argument of melt() not of
dcast(). Therefore, melt() issues a warning, the warning in the OP.

I'll reproduce it here:


 > chem.melt <- melt(waterchem,
+ idvars = c('site', 'sampdate', 'preeq0', 'param', 'ceneq1', 'floor',
'ceiling'))
Using site, preeq0, param, ceneq1 as id variables


Hope this helps,

Rui Barradas

> str(chem.melt)
>
> do you see the variable sampdate?  I am not sure how you are wanting to re-shape your data, but when you specify a variable in dcast(), it needs to be in the dataframe you are working with.
>
>
> 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
>
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Reply | Threaded
Open this post in threaded view
|

Re: reshape2 errors on data frame [RESOLVED]

Rich Shepard
In reply to this post by Rui Barradas
On Thu, 5 Jul 2012, Rui Barradas wrote:

> Just to give it a try, you've written 'idvars' when it's 'id.vars'.

Rui,

   Oops! That was the problem. No matter how often I looked at the syntax I
kept missing that.

> Hope this helps,

   Most definitely!

Thanks for spotting it,

Rich

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.