【发布时间】:2019-07-01 11:07:07
【问题描述】:
我有一个成对比较的矩阵,其中上三角和对角线设置为NA。
df <- data.frame(a=c(NA,1,2), b=c(NA,NA,3), c=c(NA,NA,NA))
row.names(df) <- names(df)
I want to transform the matrix to long format, for which the standard procedure is to use reshape2's melt,然后是na.omit,所以我想要的输出是:
Var1 Var2 Value
a b 1
a c 2
b c 3
但是,df$c 全部为 NA,因此是合乎逻辑的,并且将被melt 用作非测量变量。
因此,melt(df) 的输出不是我想要的。
library(reshape2)
melt(df)
如何防止melt使用df$c作为id变量?
【问题讨论】: