Convert non-square weighted adjacency matrix for igraph to R

I use the tf_idf value to determine the similarity between web pages. Now I have my tf_idf matrix, which is not square, as there are many keywords, but only 36 documents. I want to convert this matrix to a graph object so that I can take one for the same projection.

So, I use this    ig <- graph.adjacency(tf_idf,mode="undirected",weighted=TRUE). I want this to be weighted, this is the tf_idf value.

But when I do this, it throws an error,

Error in graph.adjacency.dense (adjmatrix, mode = mode, weighted = weighted ,: not a square matrix

Could you help me decide how to proceed.

I have such a matrix, where x, y, z is the keyword and A, b is the web page

mat = matrix(c(0.1, 0.5, 0.9, 0.4, 0.3, 0.5), nc=3,
           dimnames=list(c("A", "B"), c("x", "y", "z")),
           byrow=TRUE)

      x    y   z
A     0.1 0.5 0.9
B     0.4 0.3 0.5
+4
1

, , , :

expand.matrix <- function(A){
  m <- nrow(A)
  n <- ncol(A)
  B <- matrix(0,nrow = m, ncol = m)
  C <- matrix(0,nrow = n, ncol = n)
  cbind(rbind(B,t(A)),rbind(A,C))
}

:

 A <- rbind(c(0,1,0),c(1,0,1))
> A
     [,1] [,2] [,3]
[1,]    0    1    0
[2,]    1    0    1
> expand.matrix(A)
     [,1] [,2] [,3] [,4] [,5]
[1,]    0    0    0    1    0
[2,]    0    0    1    0    1
[3,]    0    1    0    0    0
[4,]    1    0    0    0    0
[5,]    0    1    0    0    0
+1

Source: https://habr.com/ru/post/1685090/


All Articles