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

data('adj_karate')
ix <- mat2vec.ix(adj_karate, FALSE, FALSE)
vec <- adj_karate[ix]
vec2mat(vec, FALSE, FALSE, nrow(adj_karate))
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
#>  [1,]    0    4    5    3    3    3    3    2    2     0     2     3     1
#>  [2,]    4    0    6    3    0    0    0    4    0     0     0     0     0
#>  [3,]    5    6    0    3    0    0    0    4    5     1     0     0     0
#>  [4,]    3    3    3    0    0    0    0    3    0     0     0     0     3
#>  [5,]    3    0    0    0    0    0    2    0    0     0     3     0     0
#>  [6,]    3    0    0    0    0    0    5    0    0     0     3     0     0
#>  [7,]    3    0    0    0    2    5    0    0    0     0     0     0     0
#>  [8,]    2    4    4    3    0    0    0    0    0     0     0     0     0
#>  [9,]    2    0    5    0    0    0    0    0    0     0     0     0     0
#> [10,]    0    0    1    0    0    0    0    0    0     0     0     0     0
#> [11,]    2    0    0    0    3    3    0    0    0     0     0     0     0
#> [12,]    3    0    0    0    0    0    0    0    0     0     0     0     0
#> [13,]    1    0    0    3    0    0    0    0    0     0     0     0     0
#> [14,]    3    5    3    3    0    0    0    0    0     0     0     0     0
#> [15,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [16,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [17,]    0    0    0    0    0    3    3    0    0     0     0     0     0
#> [18,]    2    1    0    0    0    0    0    0    0     0     0     0     0
#> [19,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [20,]    2    2    0    0    0    0    0    0    0     0     0     0     0
#> [21,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [22,]    2    2    0    0    0    0    0    0    0     0     0     0     0
#> [23,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [24,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [25,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [26,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [27,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [28,]    0    0    2    0    0    0    0    0    0     0     0     0     0
#> [29,]    0    0    2    0    0    0    0    0    0     0     0     0     0
#> [30,]    0    0    0    0    0    0    0    0    0     0     0     0     0
#> [31,]    0    2    0    0    0    0    0    0    3     0     0     0     0
#> [32,]    2    0    0    0    0    0    0    0    0     0     0     0     0
#> [33,]    0    0    2    0    0    0    0    0    3     0     0     0     0
#> [34,]    0    0    0    0    0    0    0    0    4     2     0     0     0
#>       [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] [,24] [,25]
#>  [1,]     3     0     0     0     2     0     2     0     2     0     0     0
#>  [2,]     5     0     0     0     1     0     2     0     2     0     0     0
#>  [3,]     3     0     0     0     0     0     0     0     0     0     0     0
#>  [4,]     3     0     0     0     0     0     0     0     0     0     0     0
#>  [5,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [6,]     0     0     0     3     0     0     0     0     0     0     0     0
#>  [7,]     0     0     0     3     0     0     0     0     0     0     0     0
#>  [8,]     0     0     0     0     0     0     0     0     0     0     0     0
#>  [9,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [10,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [11,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [12,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [13,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [14,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [15,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [16,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [17,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [18,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [19,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [20,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [21,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [22,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [23,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [24,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [25,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [26,]     0     0     0     0     0     0     0     0     0     0     5     2
#> [27,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [28,]     0     0     0     0     0     0     0     0     0     0     4     3
#> [29,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [30,]     0     0     0     0     0     0     0     0     0     0     3     0
#> [31,]     0     0     0     0     0     0     0     0     0     0     0     0
#> [32,]     0     0     0     0     0     0     0     0     0     0     0     2
#> [33,]     0     3     3     0     0     1     0     3     0     2     5     0
#> [34,]     3     2     4     0     0     2     1     1     0     3     4     0
#>       [,26] [,27] [,28] [,29] [,30] [,31] [,32] [,33] [,34]
#>  [1,]     0     0     0     0     0     0     2     0     0
#>  [2,]     0     0     0     0     0     2     0     0     0
#>  [3,]     0     0     2     2     0     0     0     2     0
#>  [4,]     0     0     0     0     0     0     0     0     0
#>  [5,]     0     0     0     0     0     0     0     0     0
#>  [6,]     0     0     0     0     0     0     0     0     0
#>  [7,]     0     0     0     0     0     0     0     0     0
#>  [8,]     0     0     0     0     0     0     0     0     0
#>  [9,]     0     0     0     0     0     3     0     3     4
#> [10,]     0     0     0     0     0     0     0     0     2
#> [11,]     0     0     0     0     0     0     0     0     0
#> [12,]     0     0     0     0     0     0     0     0     0
#> [13,]     0     0     0     0     0     0     0     0     0
#> [14,]     0     0     0     0     0     0     0     0     3
#> [15,]     0     0     0     0     0     0     0     3     2
#> [16,]     0     0     0     0     0     0     0     3     4
#> [17,]     0     0     0     0     0     0     0     0     0
#> [18,]     0     0     0     0     0     0     0     0     0
#> [19,]     0     0     0     0     0     0     0     1     2
#> [20,]     0     0     0     0     0     0     0     0     1
#> [21,]     0     0     0     0     0     0     0     3     1
#> [22,]     0     0     0     0     0     0     0     0     0
#> [23,]     0     0     0     0     0     0     0     2     3
#> [24,]     5     0     4     0     3     0     0     5     4
#> [25,]     2     0     3     0     0     0     2     0     0
#> [26,]     0     0     0     0     0     0     7     0     0
#> [27,]     0     0     0     0     4     0     0     0     2
#> [28,]     0     0     0     0     0     0     0     0     4
#> [29,]     0     0     0     0     0     0     2     0     2
#> [30,]     0     4     0     0     0     0     0     4     2
#> [31,]     0     0     0     0     0     0     0     3     3
#> [32,]     7     0     0     2     0     0     0     4     4
#> [33,]     0     0     0     0     4     3     4     0     5
#> [34,]     0     2     4     2     2     3     4     5     0