# Create a matrix
mat <- matrix(data = 1:9,
nrow = 3,
ncol = 3,
dimnames = list(c("A", "B", "C"),
c("X", "Y", "Z")))
long_format <- matrix2long(mat)
long_format
# Using correlation matrix
matrix2long(cor(mtcars))
Run the code above in your browser using DataLab