This is similar to network::get.inducedSubgraph. The main difference is that the resulting object will always be a list of matrices, and it is vectorized.

induced_submat(x, v, ...)

Arguments

x

Either a list or single matrices or network objects.

v

Either a list or a single integer vector of vertices to subset.

...

Currently ignored.

Value

A list of matrices as a result of the subsetting.

Details

Depending on the lengths of x and v, the function can take the following strategies:

  • If both are of the same size, then it will match the networks and the vector of indices.

  • If length(x) == 1, then it will use that single network as a baseline for generating the subgraphs.

  • If length(v) == 1, then it will generate the subgraph using the same set of vertices for each network.

  • If both have more than one element, but different sizes, then the function returns with an error.

Examples

x <- rbernoulli(100) induced_submat(x, c(1, 10, 30:50))
#> [[1]] #> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] #> [1,] 0 0 0 1 1 0 1 1 1 1 0 1 1 #> [2,] 1 0 0 0 0 1 1 0 0 0 1 0 1 #> [3,] 0 0 0 0 1 1 0 0 1 1 1 1 1 #> [4,] 1 1 1 0 1 0 1 0 0 0 1 1 1 #> [5,] 1 0 1 1 0 1 1 0 1 1 1 0 0 #> [6,] 0 1 1 1 1 0 0 0 0 1 0 0 0 #> [7,] 0 0 1 0 1 0 0 1 1 0 1 1 0 #> [8,] 0 1 1 1 0 0 1 0 1 1 0 0 0 #> [9,] 0 0 0 0 1 1 0 1 0 1 0 1 1 #> [10,] 0 0 0 0 1 0 0 1 1 0 1 1 0 #> [11,] 0 0 1 1 0 1 0 1 1 1 0 0 1 #> [12,] 0 1 0 0 1 1 1 0 0 1 1 0 1 #> [13,] 0 1 1 0 1 1 0 0 1 1 1 0 0 #> [14,] 1 1 1 0 0 0 0 0 1 0 1 0 1 #> [15,] 1 1 0 1 1 1 1 0 1 0 0 1 1 #> [16,] 0 1 1 1 1 1 1 1 1 1 0 1 1 #> [17,] 1 0 1 0 0 1 1 0 0 1 0 0 0 #> [18,] 0 1 0 1 0 0 0 1 0 1 1 0 1 #> [19,] 1 0 1 0 1 1 0 0 1 1 1 1 1 #> [20,] 1 0 1 1 0 1 1 0 0 0 0 0 1 #> [21,] 1 0 1 0 1 1 1 0 1 1 0 0 1 #> [22,] 1 0 1 0 1 0 0 1 1 0 0 1 0 #> [23,] 1 0 0 0 0 1 0 1 0 1 0 0 1 #> [,14] [,15] [,16] [,17] [,18] [,19] [,20] [,21] [,22] [,23] #> [1,] 1 0 1 0 0 0 0 0 0 0 #> [2,] 1 1 0 1 1 0 1 1 1 1 #> [3,] 0 1 0 1 1 0 0 0 1 0 #> [4,] 0 1 1 1 0 0 1 0 1 1 #> [5,] 1 1 0 0 0 1 0 0 0 0 #> [6,] 0 0 1 0 0 0 1 1 0 1 #> [7,] 1 0 0 0 0 0 1 1 1 1 #> [8,] 1 0 0 0 0 1 1 1 1 0 #> [9,] 1 1 1 0 1 1 0 1 1 1 #> [10,] 0 1 0 0 1 1 1 0 1 1 #> [11,] 1 1 0 1 1 1 0 1 1 1 #> [12,] 1 0 1 0 0 1 1 1 1 0 #> [13,] 1 1 0 0 1 1 0 0 0 0 #> [14,] 0 1 0 1 0 1 0 1 0 1 #> [15,] 1 0 0 1 0 0 0 0 1 0 #> [16,] 0 1 0 1 1 1 0 0 0 1 #> [17,] 1 0 1 0 0 0 1 1 1 1 #> [18,] 1 0 1 1 0 0 0 0 0 1 #> [19,] 1 1 1 1 1 0 0 0 0 1 #> [20,] 1 0 0 1 1 0 0 0 0 1 #> [21,] 0 1 0 0 1 0 1 0 0 0 #> [22,] 1 0 1 1 0 1 0 1 0 1 #> [23,] 0 1 1 0 0 0 0 0 0 0 #>
x <- rbernoulli(c(20, 20)) induced_submat(x, c(1:10))
#> [[1]] #> [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] #> [1,] 0 1 0 1 1 0 0 1 1 0 #> [2,] 0 0 1 0 0 0 0 1 0 1 #> [3,] 0 0 0 0 1 0 0 1 1 0 #> [4,] 1 1 1 0 1 1 1 0 0 0 #> [5,] 0 1 0 0 0 0 1 1 0 1 #> [6,] 1 1 0 0 1 0 0 1 1 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