Reputation: 185
I'm doing SNA with the igraph R package and need to save some network properties of the nodes along with each node's id to a file for further analysis. That is, a document with the first column representing a node id and the other columns its properties. I'm ok with centrality measures but other igraph functions like transitivity for example, return only a vector with the computed network properties as in
transitivity(graph,type=c("local"))
[1] 0.4285714 0.3976608 0.5454545 0.7142857 0.3928571 0.4640523
[7] 0.5620915 0.6095238 0.3571429 0.4743590 0.3416667 0.6023392
[13] 0.6000000 0.5228758 0.4771242 0.4835165 0.3246753 0.5000000
[19] 0.3636364 0.5777778 0.3571429 0.4487179 0.5238095 0.4857143
What I would like to do is to be able to add transitivity to the following data frame of centrality measures:
metrics <- data.frame(
deg=degree(graph)
bet=betweenness(graph)
clo=closeness(graph)
eig=evcent(graph)$vector
)
which returns:
deg bet clos eig
001 7 8.6046215 0.009523810 0.1697311
002 19 48.2885279 0.012500000 0.7012156
003 12 10.5285962 0.011111111 0.4280625
004 15 8.6161170 0.011363636 0.7729130
I appreciate any help. Thanks!
Upvotes: 1
Views: 1111
Reputation: 347
You can add V(graph)$name to your data frame to get the ids associated with the measures.
metrics <- data.frame(
id = V(graph)$name
deg=degree(graph),
bet=betweenness(graph),
clo=closeness(graph),
eig=evcent(graph)$vector,
tra=transitivity(graph,type=c("local"))
)
Upvotes: 0
Reputation: 10543
Just add the function to your data.frame
:
metrics <- data.frame(
deg=degree(graph),
bet=betweenness(graph),
clo=closeness(graph),
eig=evcent(graph)$vector,
tra=transitivity(graph,type=c("local"))
)
Upvotes: 1