Skip to contents

Given a matrix, returns a dataframe with three columns, where the first column is the row index of the original matrix, the second column is the column index of the original matrix, and the third column is the value of the original matrix element.

Usage

pileMatrix(mat, subset = "full")

Arguments

mat

numeric matrix

subset

character indicating which array elements to take. The possible choices are:

  • "full": the whole matrix (default),

  • "u": upper triangular matrix without diagonal,

  • "ud": upper trinagular matrix with diagonal,

  • "l": lower triangular matrix without diagonal,

  • "ld": lower triangular matrix with diagonal,

  • "d": only the diagonal

Value

A dataframe with three columns: row index (row), col index (col) and matrix element value (value)

Examples

mat <- matrix(1:9, nrow = 3)
mat
#>      [,1] [,2] [,3]
#> [1,]    1    4    7
#> [2,]    2    5    8
#> [3,]    3    6    9

pileMatrix(mat)
#>   row col value
#> 1   1   1     1
#> 2   2   1     2
#> 3   3   1     3
#> 4   1   2     4
#> 5   2   2     5
#> 6   3   2     6
#> 7   1   3     7
#> 8   2   3     8
#> 9   3   3     9

pileMatrix(mat, subset = "u")
#>   row col value
#> 1   1   2     4
#> 2   1   3     7
#> 3   2   3     8