[英]R igraph degree() 'Error in match.arg'
I have a directed graph and would like to export a table of vertices with metrics such as "in degree", "out degree", and "total degree", all in one. 我有一个有向图,并且想导出一个带有“进度”,“出度”和“总度”等指标的顶点表。
g <- graph( c("John", "Jim", "Jim", "Jill", "Jill", "John"))
Now that we have a sample directed graph, I would like to get the in, out, and total degree listed for each vertices. 现在我们有了一个有向图样本,我想获取每个顶点的入,出和总度数。
degree(g, mode = c("in", "out", "total"))
This error is returned: 返回此错误:
Error in match.arg(arg = arg, choices = choices, several.ok = several.ok) : 'arg' must be of length 1
match.arg(arg = arg,choices = choices,many.ok = many.ok)中的错误:'arg'必须为长度1
What am I doing wrong? 我究竟做错了什么? I could do each one individually but I don't how to concatenate them all together.
我可以每个人单独做,但我不怎么将它们连接在一起。
The degree
function in igraph
does not accept multiple arguments like that. igraph
中的degree
函数不接受这样的多个参数。 Use sapply
to iterate over the different calls the mode
argument: 使用
sapply
遍历不同的调用mode
参数:
sapply(list("in","out","total"), function(x) degree(g, mode = x))
It returns the values in consecutive columns: 它返回连续列中的值:
> 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
After making each individual in, out, and total list, 在列出每个人的进,出和总计清单之后,
idl <- degree(g, mode="in")
odl <- degree(g, mode="out")
tdl <- degree(g, mode="total")
convert them to a data frame 将它们转换为数据框
idl <- data.frame(idl)
odl <- data.frame(odl)
tdl <- data.frame(tdl)
then combine using cbind
然后结合使用
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.