Saturday, 15 June 2013

graph - neighbors function in igraph package in R -


First of all I want to say that I already read the answer to this question: "R" igraph "package neighbor function "And I tried to solve my problem, but I could not, I tried to ask my question as a follow up comment but due to the low level of prestige I could not do, so I open this new question . Now my question is: This is the problem with my neighbors, as explained about it: But when I try to solve, which I have given, I have received the tap as a result. I've attached that part of my code here and I would be really grateful for any help and answers. My Table:

  edgelist < - read.table (text = "1 2 2 3 3 4 4 5 3 6 6 7") Library (igraph) graph & lt; - graph.data frame (adgelist) str (graph) ## Egff DN - 7 6 - ## + Att: Name (V / C) ## + Edges (Vertex Name): ## [1] 1- & gt; 2 2- & gt; 3-3-> 4 4- & gt; 5 -3- & gt; 6-6-gt; 7  

Now if I want the neighbors of node 3 it should be

  2, 4, 6  

But the result I got is:

  2, 4, 5  

I saw that the order of my nodes has changed. As I explained, before I try to find the solution found in stack overflow but as a result, I became nullified:

  graph $ name [neighbors (graph, 3)] NULL  

I do not know what I can do, I appreciate any help.

Before you begin, you have to confuse the label / name and index / number of a given head Should be careful. When you use both numbers for labels and policies, things get confused soon. To avoid all confusions, I have used letters here

  edgelist & lt; - read.table (text = "ABBCCDDECFFG") library (igraph) article & lt; - graph.data.frame (edgelist) string (graph) #IGFF DN - 7 6 - # + att: Name (V / C) # + Edges (top name): # [1] A-> BB- & gt; Cc-> D-> E-> F-> G  

To see who we were working with, we plot it:

  graph)  

imgur

Index obtained Neighbors do something like this: (Remember that mode is the argument) Neighbors (graph, 3, mode = "total") # Index of neighbors # # [1] 2 4 5 Neighbors (Graph, "C", Mode = "Total") # Index of Neighbors by Label ## [1] 2 4 5

What is Gaber? It is suggested that you need to do the following. (I think he remembered V and wrote graph $ name when it meant V (article) $ name In his post)

/ code>

The related "neighbors" have been labeled Which agrees with the image.

Edit Oh I messed up V () is used instead of E () . It seems to work as intended, sorry.


No comments:

Post a Comment