简体   繁体   English

Rigraph degree()'match.arg中的错误'

[英]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.

相关问题 对多个 arguments 使用 match.arg 时出错 - Error in using match.arg for multiple arguments 警告:match.arg中的错误:&#39;arg&#39;必须为NULL或字符向量 - Warning: Error in match.arg: 'arg' must be NULL or a character vector match.arg(mvnTest)中的错误:“ arg”的长度必须为1 - Error in match.arg(mvnTest) : 'arg' must be of length 1 match.arg(regions) 中的错误:“arg”必须为 NULL 或字符向量 - Error in match.arg(regions) : 'arg' must be NULL or a character vector 匹配使用match.arg()的默认值向量,有或没有错误[R] - Matching vector of default values using match.arg() with or without error [R] Python 中的 match.arg 等效项? - match.arg equivalent in Python? match.arg 行为不一致 - match.arg behaviour not coherent 运行应用程序时出现闪亮错误:match.arg(position) 中的错误:&#39;arg&#39; 必须为 NULL 或字符向量 - Shiny Error when running App: Error in match.arg(position) : 'arg' must be NULL or a character vector emmeans错误:match.arg(type)中的错误:&#39;arg&#39;应该是“link”,“response”,“terms”之一 - emmeans error: Error in match.arg(type) : 'arg' should be one of “link”, “response”, “terms” match.arg(opt_crit)中的错误:“ arg”必须为NULL或字符向量 - Error in match.arg(opt_crit) : 'arg' must be NULL or a character vector
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM