Why reshape2's Melt cannot capture rownames in the transformation?

后端 未结 1 401
离开以前
离开以前 2021-02-01 03:50

I have the following data:

Cubn    3.71455160837536    0.237454645363458
Gm9779  2.56051657980096    0.20850752817264
Apod    3.51796703048962    0.1959992144858         


        
1条回答
  •  天涯浪人
    2021-02-01 04:17

    I don't know the why part, but I do know that you can get the row names by melting a matrix instead of a data.frame:

    melt(as.matrix(dat))
    #     Var1 Var2     value
    # 1   Cubn  FOO 3.7145516
    # 2 Gm9779  FOO 2.5605166
    # 3   Apod  FOO 3.5179670
    # 4   Cubn  BAR 0.2374546
    # 5 Gm9779  BAR 0.2085075
    # 6   Apod  BAR 0.1959992
    

    You'll have to look at the code to the melt function to know why it behaves this way. In particular, the code for reshape2:::melt.matrix has the following lines which will create the first two columns in the example above:

    labels <- expand.grid(lapply(dn, var.convert), KEEP.OUT.ATTRS = FALSE, 
        stringsAsFactors = FALSE)
    

    0 讨论(0)
提交回复
热议问题