所以我用all_shortest_paths得到一個輸出,它看起來像這樣:翻動igraph.vs到數據幀
PathsE
$res[[1]]
+ 4/990 vertices, named:
[1] Sortilin GGA1 Ubiquitin PIMT
$res[[2]]
+ 4/990 vertices, named:
[1] Sortilin TrkA PLK1 PIMT
$res[[3]]
+ 4/990 vertices, named:
[1] Sortilin APP JAB1 PIMT
我想轉成數據幀,這樣我可以操縱它。 作爲參考,我想數據框,看起來像這樣:
Prot1 Prot2 Prot3 Prot4
Pathway1 Sortilin GGA1 PLK1 PIMT
Pathway2 Sortilin TrkA PLK1 PIMT
Pathway3 Sortilin APP JAB1 PIMT
*我知道如何更改軸名稱
我已經試過
PathsDF<-as.data.frame(PathsE)
,但我得到這個錯誤:
Error in as.data.frame.default(x[[i]], optional = TRUE) : cannot coerce class ""igraph.vs"" to a data.frame
我也試過這個:
PathDF <- as.data.frame(get.edgelist(PathsE))
但是當我審視使用
class(PathsEF)
它說,這是一個列表中的數據strture我得到這個錯誤
Error in get.edgelist(PathsE) : Not a graph object
。但是當我使用
str(PathsE)
看起來是這樣的:
..$ :Class 'igraph.vs' atomic [1:4] 338 204 40 913
.. .. ..- attr(*, "env")=<weakref>
.. .. ..- attr(*, "graph")= chr "717e99fb-b7db-4e35-8fd3-1d8d741e6612"
etc
它看起來像一個矩陣給我。
從這些信息,你有任何想法如何將其轉換爲數據框。我很抱歉,如果我錯過了任何明顯的東西 - 我對R來說很新!
你想幹什麼你的數據幀的樣子:
您也可以使用這個腳本保存在一個.csv格式? – paqmo
請參閱我的編輯! –