Sparse matrix to a data frame in R

前端 未结 2 434
长情又很酷
长情又很酷 2020-11-30 06:56

I have a sparse matrix

Formal class \'dgCMatrix\' [package \"Matrix\"] with 6 slots
  ..@ i       : int [1:37674] 1836 2297 108 472 1735 1899 2129 2131 5 67         


        
2条回答
  •  情深已故
    2020-11-30 07:26

    df <- as.data.frame(as.matrix(mat))

    as.matrix will turn the sparse matrix to a dense matrix, if it is not too large:-) Then you can convert it to a data frame.

    (mat is the example dgCMatrix from @flodel 's answer)

提交回复
热议问题