convert a matrix to a tidy data frame (from wide to long format as described in the tidyverse concept)

mat2df(x)

Arguments

x

the input matrix

Value

a data.frame in long format with the 'value' column stores the original values and 'row' and 'col' columns stored in row and column index as in x

Author

Guangchuang Yu

Examples

x <- matrix(1:15, nrow = 3)
mat2df(x)
#>    value row col
#> 1      1   1   1
#> 2      2   2   1
#> 3      3   3   1
#> 4      4   1   2
#> 5      5   2   2
#> 6      6   3   2
#> 7      7   1   3
#> 8      8   2   3
#> 9      9   3   3
#> 10    10   1   4
#> 11    11   2   4
#> 12    12   3   4
#> 13    13   1   5
#> 14    14   2   5
#> 15    15   3   5