R: Convert COO format matrix to regular matrix format -


i have square matrix in coo (coordinate list) format.

for example:

from    value 1     1     1 1     2     1 2     1     0 2     2     1 

i want convert regular r matrix format. this:

      [,1] [,2] [1,]   1    1 [2,]   0    1 

please advise how it.

here way found:

using matrix package.

first, table example:

> coo_mat <- rbind(c(1,1,1), c(1,2,1), c(2,1,0), c(2,2,1)) > coo_mat      [,1] [,2] [,3] [1,]    1    1    1 [2,]    1    2    1 [3,]    2    1    0 [4,]    2    2    1 

now, make regular format matrix:

> as.matrix(matrix::sparsematrix(i=coo_mat[,1], j=coo_mat[,2], x=coo_mat[,3]))       [,1] [,2] [1,]    1    1 [2,]    0    1 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -