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?
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')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.