This function takes in an igraph
network object and returns and igraph
object
of the largest connected component.
Value
An igraph
object which is the largest connected component of the network.
If the network is already connected, the function returns the input network unchanged.
Examples
library(igraph)
#unconnected network
data("hamster")
is.connected(hamster)
#> [1] FALSE
get_largest_component(hamster)
#> IGRAPH 78b5066 UN-- 1 0 --
#> + attr: name (v/c)
#> + edges from 78b5066 (vertex names):
#connected network
data("karate")
is.connected(karate)
#> This graph was created by an old(er) igraph version.
#> Call upgrade_graph() on it to use with the current igraph version
#> For now we convert it on the fly...
#> [1] TRUE
get_largest_component(karate)
#> IGRAPH 4b458a1 UNW- 34 78 -- Zachary's karate club network
#> + attr: name (g/c), Citation (g/c), Author (g/c), Faction (v/n), name
#> | (v/c), label (v/c), color (v/n), weight (e/n)
#> + edges from 4b458a1 (vertex names):
#> [1] Mr Hi --Actor 2 Mr Hi --Actor 3 Mr Hi --Actor 4 Mr Hi --Actor 5
#> [5] Mr Hi --Actor 6 Mr Hi --Actor 7 Mr Hi --Actor 8 Mr Hi --Actor 9
#> [9] Mr Hi --Actor 11 Mr Hi --Actor 12 Mr Hi --Actor 13 Mr Hi --Actor 14
#> [13] Mr Hi --Actor 18 Mr Hi --Actor 20 Mr Hi --Actor 22 Mr Hi --Actor 32
#> [17] Actor 2--Actor 3 Actor 2--Actor 4 Actor 2--Actor 8 Actor 2--Actor 14
#> [21] Actor 2--Actor 18 Actor 2--Actor 20 Actor 2--Actor 22 Actor 2--Actor 31
#> [25] Actor 3--Actor 4 Actor 3--Actor 8 Actor 3--Actor 9 Actor 3--Actor 10
#> + ... omitted several edges