简体   繁体   English

使用R和igraph的节点度分布

[英]node degree distribution using R and igraph

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. 我有一个名为socialNetwork.csv文件,其中两列表示userA和socialNetwork.csv之间的边缘。

Here is how I load the data into igraph : 这是我将数据加载到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? 将仅degree(d)的度值列导出到csv文件的最佳方法是什么?

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: 如果您已经将图形加载到某个对象g ,那么要创建度分布的直方图,请尝试:

hist(degree(g))

If you want to export this information to a .csv file, try: 如果要将这些信息导出到.csv文件,请尝试:

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')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM