[R] recognizing variable-names of cast() (package: reshape)

hadley wickham h.wickham at gmail.com
Mon Nov 23 04:54:29 CET 2009


Hi David,

The variable names of mma are sp, dentro, variable and value - area is
not a variable in that data frame.

Hadley

On Sun, Nov 22, 2009 at 9:48 PM, David Douterlungne
<daviddouter at hotmail.com> wrote:
>
>
>
> Dear R Users,
>
>
>
>
> Reshape seems to be very useful for data-manipulation, but I am struggling with
> the function "cast".
>
> My variable-names are not being recognized by cast()
>
>
>
>      cca<-a-cast(mma,sp~area,mean)
>
>            Error:
> Casting formula contains variables not found in molten data: "area"
>
>
>
>      cca<-a-cast(mma,sp~"area",mean)
>
>            Error:
> Casting formula contains variables not found in molten data: "area"
>
>
>
>
>
> it does works with "..."
>
>
>
>      cca<-cast(mma,sp~...,mean)
>
>
>
> I  tried many things, including
> transforming my names with to.lower.
>
>       names(mma)<-tolower(names(mma))
>
>
>
> What am I doing wrong?
>
>
>
>
>
>
>
> Beneath is a more detailed outprints of the simplified scripts & results (original data.frame has more variables).
>
>
>
>
> str(ma)
>     'data.frame':   102860 obs. of  3 variables:
>      $ sp    : Factor w/ 12 levels "Abronia","caoba",..: 3 3 3 3 3 3 3 3 3 3 ...
>      $ area  : num  49786 6924 21083 27451 1984 ...
>      $ dentro: Factor w/ 2 levels "dentro","fuera": 1 1 1 1 1 1 1 1 1 1 ...
>
> mma<-melt(ma,id=c("sp","dentro"),na.rm=T)
>
> str(mma)
>      'data.frame':   102860 obs. of  4 variables:
>       $ sp      : Factor w/ 12 levels "Abronia","caoba",..: 3 3 3 3 3 3 3 3 3 3 ...
>       $ dentro  : Factor w/ 2 levels "dentro","fuera": 1 1 1 1 1 1 1 1 1 1 ...
>       $ variable: Factor w/ 1 level "area": 1 1 1 1 1 1 1 1 1 1 ...
>       $ value   : num  49786 6924 21083 27451 1984 ...
>
> cca<-a-cast(mma,sp~"area",mean)
>      Error: Casting formula contains variables not found in molten data: "area"
>
> cca<-cast(mma,sp~...,mean)
> str(cca)
>       List of 3
>       $ sp         : Factor w/ 12 levels "Abronia","caoba",..: 1 2 3 4 5 6 7 8 9 10 ...
>       $ dentro_area: num [1:12] 58755 26464 32139 31494 36731 ...
>       $ fuera_area : num [1:12] 61836 29872 33819 36396 42831 ...
>       - attr(*, "row.names")= int [1:12] 1 2 3 4 5 6 7 8 9 10 ...
>       - attr(*, "idvars")= chr "sp"
>       - attr(*, "rdimnames")=List of 2
>       ..$ :'data.frame':    12 obs. of  1 variable:
>       .. ..$ sp: Factor w/ 12 levels "Abronia","caoba",..: 1 2 3 4 5 6 7 8 9 10 ...
>       ..$ :'data.frame':    2 obs. of  2 variables:
>       .. ..$ dentro  : Factor w/ 2 levels "dentro","fuera": 1 2
>       .. ..$ variable: Factor w/ 1 level "area": 1 1
>
> David Douterlungne
>
> _________________________________________________________________
>
>  Facebook.
>
> cial-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_2:092
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org 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.
>



-- 
http://had.co.nz/




More information about the R-help mailing list