We can construct a sparse matrix from an index and value of non-zero element with the sparseMatrix or spMatrix. Is there any function convert a spa
sparseMatrix
spMatrix
Use which with arr.ind:
which
arr.ind
idx <- which(A != 0, arr.ind=TRUE) cbind(idx, A[idx]) # [,1] [,2] [,3] # [1,] 1 1 1 # [2,] 3 3 2 # [3,] 5 4 3