[I would be surprised if there wasn't a function that did this in R already](https://github.com/westbrooktm/GOeval/blob/3f20b1cb7c1dfff539564fc0f7aecda98bbee76e/R/webgestalt_network.R#L76), though I haven't run this yet to see exactly what it is doing.