0

I would like to create a histogram of the node degree distribution of a social network. I have file called socialNetwork.csv with two columns representing edges between userA and userB.

Here is how I load the data into igraph:

library(igraph)
g = read.graph("c:\\Network.csv", format="ncol")

What is the best way to export only the degree value column of degree(d) to a csv file?

josliber
  • 43,891
  • 12
  • 98
  • 133
gruber
  • 28,739
  • 35
  • 124
  • 216

1 Answers1

2

You sort of ask a few different questions in your original post, so perhaps clarifying which of them you would like answered and what you have tried would be helpful. That said, there are a few steps listed below that I believe cover most of what you mention.

If you have already loaded the graph into some object g, then to create a histogram of the degree distribution try:

hist(degree(g))

If you want to export this information to a .csv file, try:

df_deg <- as.data.frame(table(degree(g)))
colnames(df_deg) <- c('degree','count')
write.csv(df_deg, file = 'degree_dist.csv')

Or if you only want the "value" column which I interpret to mean the counts of vertices by degree, then try in place of the last line above:

write.csv(df_deg[,2], file = 'degree_dist.csv')
Gary Weissman
  • 3,557
  • 1
  • 18
  • 23