簡體   English   中英

鄰接矩陣不對稱的錯誤

[英]Error that the adjacency matrix is not symmetric

我的數據集如下,我想創建一個網絡,但錯誤是我的鄰接矩陣不是對稱的,我是 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 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM