[英]Error that the adjacency matrix is not symmetric
My dataset is as follows, I want to create a network but the error is that my adjacency matrix is not symmetric, I am new to R, I don't know how to convert my data to symmetric adjacency matrix, can any one help me please?我的数据集如下,我想创建一个网络,但错误是我的邻接矩阵不是对称的,我是 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"
The code that I tried我试过的代码
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
)
If you are applying igraph
package, you should use graph_from_data_frame
to create the graph object net
, which is followed by get.adjacency
to obtain the adjacency matrix, eg,如果您正在应用
igraph
package,则应使用graph_from_data_frame
创建图 object 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.