I am having difficulty on making graph data in igraph package.

I want to conduct centrality analysis, and prior to do that I found that I have to make a graph data first. So I was struggling to make graph with 'graph.data.frame' function with 'igraph' package. This is my code.

links = fread("C:/Users/82109/Documents/centrality_baselayer.csv")           
links = links %>% select("LINK_ID", "UP_FROM_NO", "UP_TO_NODE") # the first picture

nodes = fread("C:/Users/82109/Documents/linkdata.csv")
nodes = nodes %>% select("UP_FROM_NO")
nodes = unique(nodes) # the second picture 

with the code above, I gained following data :


and with the dataframes above and a code below, I tried to make graph.

graph.data.frame(d = links, vertices = nodes, directed = T)

But this error bothers me...
Error in graph.data.frame(d = links, vertices = nodes, directed = T) : Some vertex names in edge list are not listed in vertex data frame

This makes me very embarrassed now...I would be very appreciate if you help me!


I cannot see your data, which makes a specific answer possible. Please proved a REPREX for helping us and getting more specific help.

The error message is however quite self explaining: your edge-list contains links between vertices that are not present in the node-list. As you read them from different csv's, I expect a mismatch here?

Have you tried creating the nodelist directly from the link-file?

nodes = data.frame(node = unique(links$UP_FROM_NO, links$UP_TO_NODE))

#or use select-full_join-distinct for dplyr

nodes =  full_join(select(links, UP_FROM_NO), select(links, UP_TO_NODE), by = c("UP_FROM_NO" = 'UP_TO_NODE") %>%

This will assure the nodelist contains all the links table appear unambiguously in the node-list


1 Like

I created node list directly from link file, as your question just now. After conducting similar process with the method you told me, I finally made it. Thank you. But I am facing another problem right now...Have you did this stuff before?

Incidentally I do and did. However, if you now run into other problems, I suggest you tick this question for answered and post a new one. This will help you to get faster responses from the community.

Please use the reprexpackage, see link above.

Happy to see this step worked for you.


1 Like

Umm...ok. Thank you so much:)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.