2016-11-11 7 views
0

친애 유래 커뮤니티, 나는 현재 노드가 회사/우산 조직하고 관계가 "회원"으로 정의된다 제휴 네트워크를 컴파일 R을 사용하고R/네트워크 분석 - 노드의 속성에 의해

을 가장자리를 만드는 방법. 순간, 내 목록은 여전히 ​​작고 나는 (내가 igraph 사용) 노드의 위치에 따라, 다음과 같은 에지를 만들 수 있습니다 : 나는 새로운 노드를 추가하고, 그러나

g <- igraph::add_edges(g, c(1,51, 
          1,52, 
          1,53, 
          1,54)) 

를 최종 네트워크가 포함됩니다 적어도 500 개의 조직. 즉, 새 노드를 추가 할 때마다 노드의 위치가 변경 될 수 있습니다. 새 노드를 추가 할 때마다 가장자리를 다시 처리 할 수 ​​없으므로 노드의 이름을 모르는 가장자리를 추가 할 수있는 방법이 있습니까? 위치는 달리 - - 노드의

이름은 속성으로 취급, 나는 이름을 포함하여 위와 동일한 명령을 사용하여 시도했지만 작동하지 않았다 :

g <- igraph::add_edges(g, c(V(g)$name=="Company1", V(g)$name == "Umbrella2")) 

I 방법에 대한 제안 위치가 아닌 이름을 지정하여 가장자리를 만들 수 있습니까?

답변

0

나는 당신이 as.numeric(V(g)["Company1"])을 찾고 있다고 생각합니다.

에 대해에 대해 R 스크립트를 작성하는 것이 좋습니다. 소규모 네트워크의 경우에도 데이터를 Excel 파일에 입력하고 가장자리 목록으로 데이터를 읽고 Rig 스크립트에서 igraph를 만드는 R 스크립트를 만듭니다. 그런 식으로 기업과 조직을 추가 할 수 있습니다. 실제로 데이터가 네트워크에 실제로 들어 갔는지를 더 잘 감시 할 수 있습니다. 처음에 찾고있는 것입니다. 그래도이 질문을하는 것은 불가능할 것입니다.

추가 노드 이름에 관해서는이 예제를 교육적이라고 썼습니다.

library(igraph) 

# Make an empty Bipartite graph 
g <- make_bipartite_graph(0, NULL, directed=TRUE) 
g <- delete_vertices(g, 1) 


# Create vertices of two different types: companies and umbrellas 
g <- add_vertices(g, 5, color = "red", type=TRUE, name=paste("Company", 1:5, sep="_")) 
g <- add_vertices(g, 2, color = "blue", type=FALSE, name=paste("Umbrella", 1:2, sep="_")) 

# In a bipartate graph edges may only appear BETWEEN verticies of different types. Companies 
# can belong to umbrellas, but not to each other. 

# Look at the types: 
ifelse(V(g)$type, 'Company', 'Umbrella') # true for companies, false for umbrellas 

# Lets add some edges one by one. This is what I believe you're asking for in the question: 
g <- add_edges(g, c(as.numeric(V(g)["Company_1"]), as.numeric(V(g)["Umbrella_1"]))) 
g <- add_edges(g, c(as.numeric(V(g)["Company_1"]), as.numeric(V(g)["Umbrella_2"]))) 
g <- add_edges(g, c(as.numeric(V(g)["Company_2"]), as.numeric(V(g)["Umbrella_1"]))) 
g <- add_edges(g, c(as.numeric(V(g)["Company_3"]), as.numeric(V(g)["Umbrella_1"]))) 
g <- add_edges(g, c(as.numeric(V(g)["Company_4"]), as.numeric(V(g)["Umbrella_2"]))) 
g <- add_edges(g, c(as.numeric(V(g)["Company_5"]), as.numeric(V(g)["Umbrella_2"]))) 

# Note that "Company_1" belongs to two umbrella organisations, as I assume your companies can: 
plot(g) 
+0

고맙습니다. 매우 유용했습니다. 명령은 현재 데이터에서 작동했지만 Excel 스프레드 시트를 먼저 컴파일해야한다는 데 동의합니다. –