I have a matrix with pairwise comparisons, of which the upper triangle and diagonal was set to 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
, followed by na.omit
, so my desired output would be:
Var1 Var2 Value
a b 1
a c 2
b c 3
However, df$c
is all NA and thus logical, and will be used as a non-measured variable by melt
.
The output of melt(df)
is therefore not what i am looking for.
library(reshape2)
melt(df)
How can I prevent melt from using df$c
as id variable?