如何解决邻接矩阵不对称的错误
我的数据集如下,我想创建一个网络但错误是我的邻接矩阵不对称,我是R新手,我不知道如何将我的数据转换为对称邻接矩阵,可以吗?请一位帮助我?
df2:
17 "RobertKennedyJr" "RobertKennedyJr "
18 "Real_Sheezzii" "Real_Sheezzii "
19 "Kellie_Martin" "Kellie_Martin "
20 "ThatsOurWaldo" "ThatsOurWaldo "
21 "SCN_Nkosi" "SCN_Nkosi "
22 "azsweetheart013" "azsweetheart013 "
23 "KYourrights" "KYourrights KathyConWom"
24 "GowTolson" " KathyConWom"
25 "Peterpu52451065" " KathyConWom"
26 "Jifchoppa" " KathyConWom"
27 "ClaraLpz3" " KathyConWom"
28 "Anna5705" " KathyConWom"
29 "Brizzle254" " KathyConWom"
30 "JackSpa02102454" " KathyConWom"
我尝试过的代码
library("igraph")
library("network")
library("statnet")
relationsp <- as.matrix(df2)
relationsp
net <- as.network(x = mat,# the network object
directed = TRUE,# specify whether the network is directed
loops = FALSE,# do we allow self ties (should not allow them)
matrix.type = "adjacency" # the type of input
)
解决方法
如果你应用igraph
包,你应该使用graph_from_data_frame
来创建图对象net
,然后使用get.adjacency
来获取邻接矩阵,例如,
> net <- graph_from_data_frame(dat)
> get.adjacency(net,sparse = FALSE)
RobertKennedyJr Real_Sheezzii Kellie_Martin GowTolson ClaraLpz3
RobertKennedyJr 1 0 0 0 0
Real_Sheezzii 0 1 0 0 0
Kellie_Martin 0 0 1 0 0
GowTolson 0 0 0 0 0
ClaraLpz3 0 0 0 0 0
KathyConWom 0 0 0 0 0
KathyConWom
RobertKennedyJr 0
Real_Sheezzii 0
Kellie_Martin 0
GowTolson 1
ClaraLpz3 1
KathyConWom 0
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。