First, to make things unambiguous, I change
colnames(x) <- LETTERS[6:10]
Use expand.grid to get row and column names like this
rowCol <- expand.grid(rownames(x), colnames(x))
To get the correct rows from this data frame, take
labs <- rowCol[as.vector(upper.tri(x,diag=F)),] df <- cbind(labs, x[upper.tri(x,diag=F)]) colnames(df) <- c("Row","Col","Val") df[,c(2,1,3)] ## Col Row Val ## 6 GA 6 ## 11 HA 11 ## ...
source share