Reputation: 203
g <- make_ring(10) %>%
set_vertex_attr("smoke", value = 1) %>%
add_vertices(10, color = 4, "a" = 2)
g
plot(g)
if("a" == 2) {
set_vertex_attr("a", value = 1)
}
V(g)$a
With igraph, whenever I run this code nothing happens to the the attribute values of the 10 unconnected nodes with the attribute value of 2. How would I change this code so that the if statement runs for each of these nodes and changes each one separately (dependent on the initial value of "a")?
Upvotes: 1
Views: 75
Reputation: 37661
Your if statement makes no sense because
I think what you want is something like
V(g)$a[V(g)$a == 2] = 1
V(g)$a
[1] NA NA NA NA NA NA NA NA NA NA 1 1 1 1 1 1 1 1 1 1
Upvotes: 1