Chr*_*ois 10 networking r social-networking
我有一个数据框,详细说明N个节点之间的边权重.是否有用于处理此类数据的包?
例如,我想将以下信息绘制为网络:
p1 p2 counts
1 a b 100
2 a c 200
3 a d 100
4 b c 80
5 b d 90
6 b e 100
7 c d 100
8 c e 40
9 d e 60
Run Code Online (Sandbox Code Playgroud)
Chr*_*ois 14
一种选择是网络包,它是用于统计社交网络分析的R包的statnet系列的一部分.它以稀疏的方式处理网络数据,这对于较大的数据集很有用.
下面,我做以下事项:
A = read.table(file="so.txt",header=T)
A
p1 p2 counts
1 a b 100
2 a c 200
3 a d 100
4 b c 80
5 b d 90
6 b e 100
7 c d 100
8 c e 40
9 d e 60
library(network)
net = network(A[,1:2])
# Get summary information about your network
net
Network attributes:
vertices = 5
directed = TRUE
hyper = FALSE
loops = FALSE
multiple = FALSE
bipartite = FALSE
total edges= 9
missing edges= 0
non-missing edges= 9
Vertex attribute names:
vertex.names
adjacency matrix:
a b c d e
a 0 1 1 1 0
b 0 0 1 1 1
c 0 0 0 1 1
d 0 0 0 0 1
e 0 0 0 0 0
set.edge.attribute(net,"weight",A[,3])
gplot(net)
## Another cool feature
s = as.sociomatrix(net,attrname="weight")
plot.sociomatrix(s)