[R] melt stumbles over deleted columns

hadley wickham h.wickham at gmail.com
Thu Jan 22 15:18:22 CET 2009


On Thu, Jan 22, 2009 at 8:01 AM, Titus von der Malsburg
<malsburg at gmail.com> wrote:
> I have a data frame that is the result of a cast (reshape) operation.  I
> deleted the variable column and tried to melt the resulting data frame.
> Depending on which method I use to delete the column I get different
> error messages when melting:
>
>    > head(tinfos)
>      vpn group trial_no item relation trial_type   rt variable  #
>    1 102     2        1 4351    diag1 distractor 8471    fix_d 27
>    2 102     2        2 1214       id     target 4072    fix_d 17
>    3 102     2        3 4213    diag1 distractor 7040    fix_d 27
>    4 102     2        4 1314       id     target 4370    fix_d 15
>    5 102     2        5 2655     vert distractor 4397    fix_d 17
>    6 102     2        6 3322    horiz distractor 6132    fix_d 26
>    > tinfos$variable <- NULL
>    > melt(tinfos)
>    Error: id variables not found in data: variable

Cast stores some extra information in the data frame that makes future
melting a bit easier, provided that you don't delete any of the
columns.  Since you have, you need to throw away the extra info with:

tinfos <- as.data.frame(tinfos)

Regards,

Hadley

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




More information about the R-help mailing list