How to fix invalid vertex id error in tidygraph?

1.8k views Asked by At

Data

network_data <- list(nodes = structure(list(id = c(0, 1, 2, 3, 4, 5, 6, 7, 8, 
9, 10, 11, 12, 13, 14), label = c("2892056", "2894543", "2894544", 
"2894545", "2894546", "2894547", "2894548", "2894549", "2894550", 
"2894551", "2894552", "2894553", "2894554", "2894555", "2894556"
)), row.names = c(NA, -15L), class = "data.frame"), links = structure(list(
    from = c(3, 5, 7, 13, 13, 7, 3, 5, 0, 0, 5, 2, 7, 6, 13, 
    11, 0, 3, 2, 7, 13, 3, 0, 0, 5, 3, 13, 4, 0, 14, 13, 7, 2, 
    3, 5, 0, 12), to = c(0, 0, 0, 0, 2, 2, 2, 2, 2, 3, 3, 3, 
    3, 3, 3, 4, 5, 5, 5, 5, 5, 6, 6, 7, 7, 7, 7, 11, 12, 12, 
    12, 13, 13, 13, 13, 13, 14), weight = c(1, 2, 2, 1, 2, 1, 
    1, 1, 2, 1, 1, 1, 1, 2, 1, 1, 2, 1, 2, 1, 2, 2, 2, 1, 1, 
    2, 1, 2, 1, 1, 2, 2, 2, 1, 2, 1, 1)), row.names = c(NA, -37L
), class = "data.frame"))

I have this list of nodes and links for building a network. Rather than plotting the network, I want to get the network characteristics such as isolates, reciprocity, etc.

Here's the rest of the code that I'm using to obtain these characteristics:

network_data$nodes <- network_data$nodes %>% select(id, label)
  
  network_data$links <- network_data$links %>% rename(from = source, to = target)
  
  print(network_data$nodes)
  print(network_data$links)
  
  SNA <- tidygraph::tbl_graph(
    nodes = network_data$nodes, 
    edges = network_data$links, 
    directed = T
  )
  

The last line is where it errors out.

Error in (function (edges, n = max(edges), directed = TRUE)  : 
  At structure_generators.c:86 : Invalid (negative) vertex id, Invalid vertex id

I googled the issue and seems like it's pretty prevalent, but none of the methods suggested worked for me. What's different in my data that it's still generating the error, and how can I resolve this error?

0

There are 0 answers