簡體   English   中英

Rigraph degree()'match.arg中的錯誤'

[英]R igraph degree() 'Error in match.arg'

我有一個有向圖,並且想導出一個帶有“進度”,“出度”和“總度”等指標的頂點表。

g <- graph( c("John", "Jim", "Jim", "Jill", "Jill", "John"))

現在我們有了一個有向圖樣本,我想獲取每個頂點的入,出和總度數。

degree(g, mode = c("in", "out", "total"))

返回此錯誤:

match.arg(arg = arg,choices = choices,many.ok = many.ok)中的錯誤:'arg'必須為長度1

我究竟做錯了什么? 我可以每個人單獨做,但我不怎么將它們連接在一起。

igraph中的degree函數不接受這樣的多個參數。 使用sapply遍歷不同的調用mode參數:

sapply(list("in","out","total"), function(x) degree(g, mode = x))

它返回連續列中的值:

> sapply(list("in","out","total"), function(x) degree(g, mode = x))
     [,1] [,2] [,3]
John    1    1    2 
Jim     1    1    2
Jill    1    1    2

在列出每個人的進,出和總計清單之后,

idl <- degree(g, mode="in")
odl <- degree(g, mode="out")
tdl <- degree(g, mode="total")

將它們轉換為數據框

idl <- data.frame(idl)
odl <- data.frame(odl)
tdl <- data.frame(tdl)

然后結合使用cbind

> cbind(idl,odl,tdl)
     idl odl tdl
John   1   1   2
Jim    1   1   2
Jill   1   1   2

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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