Last active
January 18, 2017 07:20
-
-
Save geoHeil/1bc6141acd25710b9e88899d9cbf6a54 to your computer and use it in GitHub Desktop.
Igraph calculate custom metrics
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am curious how to compute some metrics for each node.
For each node compute percentage of direct connections to trump for
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.