Create a new graph, by permuting vertex ids.
Details
This function creates a new graph from the input graph by permuting its
vertices according to the specified mapping. Call this function with the
output of canonical_permutation() to create the canonical form
of a graph.
permute() keeps all graph, vertex and edge attributes of the graph.
See also
Other functions for manipulating graph structure:
+.igraph(),
add_edges(),
add_vertices(),
complementer(),
compose(),
connect(),
contract(),
delete_edges(),
delete_vertices(),
difference(),
difference.igraph(),
disjoint_union(),
edge(),
igraph-minus,
intersection(),
intersection.igraph(),
path(),
rep.igraph(),
reverse_edges(),
simplify(),
transitive_closure(),
union(),
union.igraph(),
vertex()
Author
Gabor Csardi csardi.gabor@gmail.com
Examples
# Random permutation of a random graph
g <- sample_gnm(20, 50)
g2 <- permute(g, sample(vcount(g)))
isomorphic(g, g2)
#> [1] TRUE
# Permutation keeps all attributes
g$name <- "Random graph, Gnm, 20, 50"
V(g)$name <- letters[1:vcount(g)]
E(g)$weight <- sample(1:5, ecount(g), replace = TRUE)
g2 <- permute(g, sample(vcount(g)))
isomorphic(g, g2)
#> [1] TRUE
g2$name
#> [1] "Random graph, Gnm, 20, 50"
V(g2)$name
#> [1] "a" "f" "q" "l" "h" "i" "r" "k" "j" "e" "n" "o" "t" "m" "p" "b" "c" "d" "s"
#> [20] "g"
E(g2)$weight
#> [1] 2 4 5 4 5 1 5 1 1 2 1 4 1 2 5 5 4 1 1 5 5 5 2 2 1 3 4 2 1 5 1 4 4 5 3 4 3 4
#> [39] 4 4 5 5 5 3 2 4 3 5 2 5
all(sort(E(g2)$weight) == sort(E(g)$weight))
#> [1] TRUE
