[R] melt stumbles over deleted columns

Titus von der Malsburg malsburg at gmail.com
Thu Jan 22 15:01:46 CET 2009


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

Or:

    > tinfos2 <- tinfos[,-match("variable",names(tinfos))]
    > melt(tinfos2)
    Error in `rownames<-`(`*tmp*`, value = character(0)) :
      attempt to set rownames on object with no dimensions
    In addition: Warning messages:
    1: In `[<-.factor`(`*tmp*`, ri, value = c(8471L, 4072L, 7040L, 4370L,  :
      invalid factor level, NAs generated
    2: In `[<-.factor`(`*tmp*`, ri, value = c(0L, 0L, 1L, 0L, 0L, 0L, 0L,  :
      invalid factor level, NAs generated

I figure there must be some internal inconsistency in the data frame
after deletion.  Does anybody have an idea how to fix that?

Thanks!

  Titus




More information about the R-help mailing list