The number of elements of vec are the number of non-zero elements in the adjacency matrix. It performs the opposite operation of `mat2vec_ix`.

vec2mat(vec, directed, selfloops, n)

Arguments

vec

vector to be put in matrix form

directed

a boolean argument specifying whether object is directed or not.

selfloops

a boolean argument specifying whether the model should incorporate selfloops.

n

vector. if length(n)==1, n is the number of vertices. If length(n)==3 first element is number of vertices, second and third elements are number of vertices for row and column of bipartite matrix.

Value

matrix nxn generated from vector.

Examples

el <- data.frame(from= c('a','b','b','c','d','d'), to = c('b','c','d','a','b','a'), attr= c( 12, 6, 12 , 6 , 6 , 6 )) adj <- el2adj(el) ix <- mat2vec_ix(adj, FALSE, FALSE) vec <- adj[ix] vec2mat(vec, FALSE, FALSE, nrow(adj))
#> [,1] [,2] [,3] [,4] #> [1,] 0 12 0 0 #> [2,] 12 0 6 12 #> [3,] 0 6 0 0 #> [4,] 0 12 0 0