Remove loops from the graph
remove_loops(x)
graph with the same class as the input
Remove loops (ie. a tie from a vertex to itself) from the graph object
x <- matrix(c(1, 1, 0, 0, 0, 1, 1, 0, 1), ncol = 3, byrow = TRUE)
remove_loops(x)
#> [,1] [,2] [,3]
#> [1,] 0 1 0
#> [2,] 0 0 1
#> [3,] 1 0 0
g_n <- snafun::to_network(x)
snafun::to_matrix(g_n)
#> 1 2 3
#> 1 1 1 0
#> 2 0 0 1
#> 3 1 0 1
remove_loops(g_n) |> snafun::to_matrix()
#> 1 2 3
#> 1 0 1 0
#> 2 0 0 1
#> 3 1 0 0
remove_loops(snafun::to_igraph(x)) |> snafun::to_matrix()
#> [,1] [,2] [,3]
#> [1,] 0 1 0
#> [2,] 0 0 1
#> [3,] 1 0 0