Skip to content

Instantly share code, notes, and snippets.

@geoHeil
Last active January 18, 2017 07:20
Show Gist options
  • Save geoHeil/1bc6141acd25710b9e88899d9cbf6a54 to your computer and use it in GitHub Desktop.
Save geoHeil/1bc6141acd25710b9e88899d9cbf6a54 to your computer and use it in GitHub Desktop.
Igraph calculate custom metrics
library(igraph)
id = c("a", "b", "c", "d", "e", "f", "g")
name = c("Alice", "Bob", "Charlie", "David", "Esther", "Fanny", "Gaby")
directConnectionToTrump = c(TRUE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE)
verticeData <- data.frame(id, name, directConnectionToTrump)
verticeData
src <- c("a", "b", "c", "f", "e", "e", "d", "a")
dst <- c("b", "c", "b", "c", "f", "d", "a", "e")
relationship <-c("A", "B", "B", "B", "B", "A", "A", "A")
edgeData <- data.frame(src, dst, relationship)
edgeData
g <- graph_from_data_frame(edgeData, directed = TRUE, vertices = verticeData)
plot(g, vertex.color=V(g)$directConnectionToTrump)
# TODO compute metrics
@geoHeil
Copy link
Author

geoHeil commented Jan 18, 2017

I am curious how to compute some metrics for each node.

For each node compute percentage of direct connections to trump for

  • direct node (directed)
  • direct node (undirected)
  • the friendship network from the node (directed)
  • the friendship network from the node (undirected)

in total and per relationship type.

Getting started with igraph I am not sure how to move forward to writing own graph processing functions (i.e. not only applying degree, pagerank, ...). Looking forward to some suggestions to solve this task with only one pass over the graph.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment