I have a bimodal network of people who write letters soliciting money from various entities made from an edgelist and nodelist (MRE R code below). How do I add columns to my nodelist based on calculations from the edgelist?
library(igraph)
links <- data.frame(solicitor=c("Eve","Eve","Brian","Brian","Brian","Adam","Chuck","Eve","Adam","McManus"),
solicited=c("Boutik","Undertaker","Boutik","School","Courthouse","Boutik","Undertaker","Shop","Shop","Undertaker"),
responded=(as.logical(c(0,1,0,1,1,0,1,1,1,1))),
amount=(c(0,10,0,13,18,0,5,5,5,190)))
nodes <- data.frame(names=unique(c(links$solicitor,links$solicited)),
place=c(rep("town",3),rep("rural",3),rep("city",4)))
g <- graph.data.frame(d=links,
vertices=nodes,
directed=F)
V(g)$type <- bipartite_mapping(g)$type
V(g)$solicitations <- degree(g,mode="all")
plot(g)
In the nodelist, I have name
and place
as attributes already. I want to add solicitations
(for total number letters, sent or received), responses
(for total number responses, given or received), and amount
(for aggregate amounts, given or received).
I think other centrality scores can be added in the same way as the degree
/solicitation
assignment, but for responses
and amount
, I have no idea how to accomplish this. Counting them is easy enough for this small graph, but the actual network is over 600 nodes and 1,200 edges… The goal is to take these calculated attributes and add them to corresponding nodes in the existing nodelist dataframe so that I can write the nodelist back out to csv. (Some regression analyses with these values might be in the offing.) Matching the output back to the correct nodes for all 600++ without flubbing it is crazy scary.
I asked in regular stackexchange, but this community might be a more appropriate venue.