Remove loops from the graph

remove_loops(x)

Arguments

x

graph of class igraph, network, or matrix

Value

graph with the same class as the input

Details

Remove loops (ie. a tie from a vertex to itself) from the graph object

Examples

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