Skip to contents

Convert matrix to data.table

Usage

matrix_to_dt(x, row = "row", col = "col", val = "val")

Arguments

x

The matrix

row

Name for row variable (default: 'row')

col

Name for col variable (default: 'col')

val

Name for val variable (default: 'val')

Examples

x <- matrix(runif(9), 3, 3)
rownames(x) <- letters[1:3]
colnames(x) <- letters[4:6]
matrix_to_dt(x)
#>       row    col        val
#>    <char> <char>      <num>
#> 1:      a      d 0.64964580
#> 2:      b      d 0.45305071
#> 3:      c      d 0.16083224
#> 4:      a      e 0.41465647
#> 5:      b      e 0.52798959
#> 6:      c      e 0.15063055
#> 7:      a      f 0.30036994
#> 8:      b      f 0.67204673
#> 9:      c      f 0.08181922
matrix_to_dt(x, 'sample', 'gene', 'expression')
#>    sample   gene expression
#>    <char> <char>      <num>
#> 1:      a      d 0.64964580
#> 2:      b      d 0.45305071
#> 3:      c      d 0.16083224
#> 4:      a      e 0.41465647
#> 5:      b      e 0.52798959
#> 6:      c      e 0.15063055
#> 7:      a      f 0.30036994
#> 8:      b      f 0.67204673
#> 9:      c      f 0.08181922