2017-11-27 20 views
0

나는 다음과 같은 코드가있는 경우 : 내가 속성 속성을 "A"가 임의의 노드에 0의 "A"값으로 하나 개의 노드를 연결하는 임의의 가장자리를 생성 할 수있는 방법R에서 igraph의 노드 속성 값을 기반으로 노드간에 에지를 생성하려면 어떻게해야합니까?

g <- erdos.renyi.game(20, 50 , type = "gnm" , directed = F , loops = F) %>% 
    set_vertex_attr("a", value = 0) 

total <- vcount(g) 

V(g)$a <- sample(rep(0:2, c(1, total -5, 4)), total) 

을 1의 값?

답변

0

이 시도하십시오 add_edgesigraph에서.

g <- erdos.renyi.game(20, 50 , type = "gnm" , directed = F , loops = F) %>% set_vertex_attr("a", value = 0) 
total <- vcount(g) 
V(g)$a <- c(2L, 1L, 1L, 1L, 1L, 1L, 2L, 1L, 2L, 2L, 2L, 1L, 0L, 1L, 1L, 1L, 1L, 2L, 1L, 0L) 
# generate a random edge that connects the one node with an attribute "a" value of 0 to a random node that has an attribute "a" value of 1 
g <- add_edges(g, c(sample(V(g)[V(g)$a == 0], 1), sample(V(g)[V(g)$a == 1], 1))) 
+0

단지 add_edges 부분을 추가하려고하면 오류가 발생합니다. "첫 번째 인수가 잘못되었습니다"어떻게 해결할 수 있습니까? – Bill